CinemachineStoryboardEditor.cs 6.3 KB

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