ItemContainerInterfaceEditor.cs 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. using UnityEngine;
  2. using UnityEditor;
  3. using HQFPSWeapons.UserInterface;
  4. namespace HQFPSWeapons
  5. {
  6. [CanEditMultipleObjects]
  7. [CustomEditor(typeof(ItemContainerInterface))]
  8. public class ItemContainerInterfaceEditor : UnityEditor.Editor
  9. {
  10. private SerializedProperty m_SlotTemplate;
  11. private SerializedProperty m_SlotsParent;
  12. public override void OnInspectorGUI()
  13. {
  14. serializedObject.Update();
  15. base.OnInspectorGUI();
  16. if(!Application.isPlaying)
  17. {
  18. EditorGUILayout.Space();
  19. if(!serializedObject.isEditingMultipleObjects && GUILayout.Button("Spawn Default Slots"))
  20. (serializedObject.targetObject as ItemContainerInterface).GenerateSlots();
  21. }
  22. if(!m_SlotTemplate.objectReferenceValue || !m_SlotsParent.objectReferenceValue)
  23. EditorGUILayout.HelpBox("Make sure a slot template and parent are assigned!", MessageType.Error);
  24. serializedObject.ApplyModifiedProperties();
  25. }
  26. private void OnEnable()
  27. {
  28. m_SlotTemplate = serializedObject.FindProperty("m_SlotTemplate");
  29. m_SlotsParent = serializedObject.FindProperty("m_SlotsParent");
  30. }
  31. }
  32. }