ClockEditor.cs 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. using System.Linq;
  2. using UnityEditor;
  3. using UnityEngine;
  4. namespace Chronos
  5. {
  6. [CustomEditor(typeof(Clock)), CanEditMultipleObjects]
  7. public class ClockEditor : Editor
  8. {
  9. protected SerializedProperty parentKey;
  10. protected SerializedProperty localTimeScale;
  11. protected SerializedProperty paused;
  12. protected SerializedProperty parentBlend;
  13. public virtual void OnEnable()
  14. {
  15. parentKey = serializedObject.FindProperty("_parentKey");
  16. localTimeScale = serializedObject.FindProperty("_localTimeScale");
  17. paused = serializedObject.FindProperty("_paused");
  18. parentBlend = serializedObject.FindProperty("_parentBlend");
  19. }
  20. public override void OnInspectorGUI()
  21. {
  22. EditorGUI.BeginDisabledGroup(Application.isPlaying);
  23. {
  24. EditorGUILayout.PropertyField(parentKey, new GUIContent("Parent"));
  25. }
  26. EditorGUI.EndDisabledGroup();
  27. OnBlendsGUI();
  28. EditorGUILayout.PropertyField(localTimeScale, new GUIContent("Time Scale"));
  29. EditorGUILayout.PropertyField(paused, new GUIContent("Paused"));
  30. if (!serializedObject.isEditingMultipleObjects &&
  31. Application.isPlaying)
  32. {
  33. Clock clock = (Clock)serializedObject.targetObject;
  34. EditorGUILayout.LabelField("Computed Time Scale", clock.timeScale.ToString("0.00"));
  35. }
  36. }
  37. protected virtual void OnBlendsGUI()
  38. {
  39. if (parentKey.hasMultipleDifferentValues || !string.IsNullOrEmpty(parentKey.stringValue))
  40. {
  41. EditorGUILayout.PropertyField(parentBlend, new GUIContent("Parent Blend"));
  42. }
  43. }
  44. }
  45. }