KeyManagerInspector.cs 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. using UnityEditor;
  2. using UnityEngine;
  3. namespace DunGen.Editor
  4. {
  5. [CustomEditor(typeof(KeyManager))]
  6. public sealed class KeyManagerInspector : UnityEditor.Editor
  7. {
  8. public override void OnInspectorGUI()
  9. {
  10. KeyManager keyManager = target as KeyManager;
  11. if (keyManager == null)
  12. return;
  13. DrawKeyListGUI(keyManager);
  14. if (GUI.changed)
  15. EditorUtility.SetDirty(keyManager);
  16. }
  17. private void DrawKeyListGUI(KeyManager manager)
  18. {
  19. int toDeleteIndex = -1;
  20. for (int i = 0; i < manager.Keys.Count; i++)
  21. {
  22. var key = manager.Keys[i];
  23. EditorGUILayout.BeginVertical("box");
  24. EditorGUILayout.BeginHorizontal();
  25. string name = EditorGUILayout.TextField("Name", key.Name);
  26. if (!string.IsNullOrEmpty(name))
  27. manager.RenameKey(i, name);
  28. if (GUILayout.Button("x", EditorStyles.miniButton, InspectorConstants.SmallButtonWidth))
  29. toDeleteIndex = i;
  30. EditorGUILayout.EndHorizontal();
  31. key.Prefab = (GameObject)EditorGUILayout.ObjectField(key.Prefab, typeof(GameObject), false);
  32. key.Colour = EditorGUILayout.ColorField(key.Colour);
  33. EditorUtil.DrawIntRange("Keys per Lock", key.KeysPerLock);
  34. if (key.KeysPerLock.Min < 1)
  35. key.KeysPerLock.Min = 1;
  36. EditorGUILayout.EndVertical();
  37. }
  38. EditorGUILayout.Space();
  39. if (toDeleteIndex != -1)
  40. manager.DeleteKey(toDeleteIndex);
  41. if (GUILayout.Button("Add New Key"))
  42. manager.CreateKey();
  43. }
  44. }
  45. }