CinemachineStoryboardEditor.cs 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. #if !UNITY_2019_1_OR_NEWER
  2. #define CINEMACHINE_UGUI
  3. #endif
  4. #if CINEMACHINE_UGUI
  5. using UnityEngine;
  6. using UnityEditor;
  7. namespace Cinemachine.Editor
  8. {
  9. [InitializeOnLoad]
  10. internal class CinemachineStoryboardMute
  11. {
  12. const string StoryboardGlobalMuteMenuName = "Cinemachine/Storyboard Global Mute";
  13. [MenuItem(StoryboardGlobalMuteMenuName, false)]
  14. public static void StoryboardGlobalMute()
  15. {
  16. bool enable = !CinemachineStoryboardMute.Enabled;
  17. CinemachineStoryboardMute.Enabled = enable;
  18. }
  19. static CinemachineStoryboardMute()
  20. {
  21. CinemachineStoryboard.s_StoryboardGlobalMute = Enabled;
  22. /// Delaying until first editor tick so that the menu
  23. /// will be populated before setting check state, and
  24. /// re-apply correct action
  25. EditorApplication.delayCall += () => { UnityEditor.Menu.SetChecked(StoryboardGlobalMuteMenuName, Enabled); };
  26. }
  27. public static string kEnabledKey = "StoryboardMute_Enabled";
  28. public static bool Enabled
  29. {
  30. get { return EditorPrefs.GetBool(kEnabledKey, false); }
  31. set
  32. {
  33. if (value != Enabled)
  34. {
  35. EditorPrefs.SetBool(kEnabledKey, value);
  36. CinemachineStoryboard.s_StoryboardGlobalMute = value;
  37. UnityEditor.Menu.SetChecked(StoryboardGlobalMuteMenuName, value);
  38. InspectorUtility.RepaintGameView();
  39. }
  40. }
  41. }
  42. }
  43. [CustomEditor(typeof(CinemachineStoryboard))]
  44. [CanEditMultipleObjects]
  45. internal sealed class CinemachineStoryboardEditor : BaseEditor<CinemachineStoryboard>
  46. {
  47. public void OnDisable()
  48. {
  49. WaveformWindow.SetDefaultUpdateInterval();
  50. }
  51. const float FastWaveformUpdateInterval = 0.1f;
  52. float mLastSplitScreenEventTime = 0;
  53. public override void OnInspectorGUI()
  54. {
  55. float now = Time.realtimeSinceStartup;
  56. if (now - mLastSplitScreenEventTime > FastWaveformUpdateInterval * 5)
  57. WaveformWindow.SetDefaultUpdateInterval();
  58. BeginInspector();
  59. CinemachineStoryboardMute.Enabled
  60. = EditorGUILayout.Toggle(
  61. new GUIContent(
  62. "Storyboard Global Mute",
  63. "If checked, all storyboards are globally muted."),
  64. CinemachineStoryboardMute.Enabled);
  65. Rect rect = EditorGUILayout.GetControlRect(true);
  66. EditorGUI.BeginChangeCheck();
  67. {
  68. float width = rect.width;
  69. rect.width = EditorGUIUtility.labelWidth + rect.height;
  70. EditorGUI.PropertyField(rect, FindProperty(x => x.m_ShowImage));
  71. rect.x += rect.width; rect.width = width - rect.width;
  72. EditorGUI.PropertyField(rect, FindProperty(x => x.m_Image), GUIContent.none);
  73. EditorGUILayout.PropertyField(FindProperty(x => x.m_Aspect));
  74. EditorGUILayout.PropertyField(FindProperty(x => x.m_Alpha));
  75. EditorGUILayout.PropertyField(FindProperty(x => x.m_Center));
  76. EditorGUILayout.PropertyField(FindProperty(x => x.m_Rotation));
  77. rect = EditorGUILayout.GetControlRect(true);
  78. EditorGUI.LabelField(rect, "Scale");
  79. rect.x += EditorGUIUtility.labelWidth; rect.width -= EditorGUIUtility.labelWidth;
  80. rect.width /= 3;
  81. serializedObject.SetIsDifferentCacheDirty(); // prop.hasMultipleDifferentValues always results in false if the SO isn't refreshed here
  82. var prop = FindProperty(x => x.m_SyncScale);
  83. var syncHasDifferentValues = prop.hasMultipleDifferentValues;
  84. GUIContent syncLabel = new GUIContent("Sync", prop.tooltip);
  85. EditorGUI.showMixedValue = syncHasDifferentValues;
  86. prop.boolValue = EditorGUI.ToggleLeft(rect, syncLabel, prop.boolValue);
  87. EditorGUI.showMixedValue = false;
  88. rect.x += rect.width;
  89. if (prop.boolValue || targets.Length > 1 && syncHasDifferentValues)
  90. {
  91. prop = FindProperty(x => x.m_Scale);
  92. float[] values = new float[1] { prop.vector2Value.x };
  93. EditorGUI.showMixedValue = prop.hasMultipleDifferentValues;
  94. EditorGUI.MultiFloatField(rect, new GUIContent[1] { new GUIContent("X") }, values);
  95. EditorGUI.showMixedValue = false;
  96. prop.vector2Value = new Vector2(values[0], values[0]);
  97. }
  98. else
  99. {
  100. rect.width *= 2;
  101. prop = FindProperty(x => x.m_Scale);
  102. EditorGUI.showMixedValue = prop.hasMultipleDifferentValues;
  103. EditorGUI.PropertyField(rect, prop, GUIContent.none);
  104. EditorGUI.showMixedValue = false;
  105. }
  106. EditorGUILayout.PropertyField(FindProperty(x => x.m_MuteCamera));
  107. }
  108. if (EditorGUI.EndChangeCheck())
  109. serializedObject.ApplyModifiedProperties();
  110. EditorGUILayout.Space();
  111. EditorGUI.BeginChangeCheck();
  112. EditorGUILayout.PropertyField(FindProperty(x => x.m_SplitView));
  113. if (EditorGUI.EndChangeCheck())
  114. {
  115. mLastSplitScreenEventTime = now;
  116. WaveformWindow.UpdateInterval = FastWaveformUpdateInterval;
  117. serializedObject.ApplyModifiedProperties();
  118. }
  119. rect = EditorGUILayout.GetControlRect(true);
  120. GUI.Label(new Rect(rect.x, rect.y, EditorGUIUtility.labelWidth, rect.height),
  121. "Waveform Monitor");
  122. rect.width -= EditorGUIUtility.labelWidth; rect.width /= 2;
  123. rect.x += EditorGUIUtility.labelWidth;
  124. if (GUI.Button(rect, "Open"))
  125. WaveformWindow.OpenWindow();
  126. }
  127. }
  128. }
  129. #endif