GlobalClockEditor.cs 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. using UnityEditor;
  2. using UnityEngine;
  3. namespace Chronos
  4. {
  5. [CustomEditor(typeof(GlobalClock)), CanEditMultipleObjects]
  6. public class GlobalClockEditor : ClockEditor
  7. {
  8. protected SerializedProperty key;
  9. public override void OnEnable()
  10. {
  11. base.OnEnable();
  12. key = serializedObject.FindProperty("_key");
  13. }
  14. public override void OnInspectorGUI()
  15. {
  16. serializedObject.Update();
  17. if (!serializedObject.isEditingMultipleObjects)
  18. {
  19. Timekeeper timekeeper = ((Clock)serializedObject.targetObject).GetComponent<Timekeeper>();
  20. if (timekeeper == null || !timekeeper.enabled)
  21. {
  22. EditorGUILayout.HelpBox("Global clocks only function when attached to the timekeeper.", MessageType.Error);
  23. }
  24. }
  25. EditorGUILayout.PropertyField(key, new GUIContent("Key"));
  26. base.OnInspectorGUI();
  27. if (!key.hasMultipleDifferentValues &&
  28. string.IsNullOrEmpty(key.stringValue))
  29. {
  30. EditorGUILayout.HelpBox("The key cannot be empty.", MessageType.Error);
  31. }
  32. serializedObject.ApplyModifiedProperties();
  33. }
  34. }
  35. }