CinemachineGroupComposerEditor.cs 4.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq.Expressions;
  4. using UnityEditor;
  5. using UnityEngine;
  6. using Cinemachine.Utility;
  7. namespace Cinemachine.Editor
  8. {
  9. [CustomEditor(typeof(CinemachineGroupComposer))]
  10. internal class CinemachineGroupComposerEditor : CinemachineComposerEditor
  11. {
  12. // Specialization
  13. private CinemachineGroupComposer MyTarget { get { return target as CinemachineGroupComposer; } }
  14. protected string FieldPath<TValue>(Expression<Func<CinemachineGroupComposer, TValue>> expr)
  15. {
  16. return ReflectionHelpers.GetFieldPath(expr);
  17. }
  18. /// <summary>Get the property names to exclude in the inspector.</summary>
  19. /// <param name="excluded">Add the names to this list</param>
  20. protected override void GetExcludedPropertiesInInspector(List<string> excluded)
  21. {
  22. base.GetExcludedPropertiesInInspector(excluded);
  23. CinemachineBrain brain = CinemachineCore.Instance.FindPotentialTargetBrain(MyTarget.VirtualCamera);
  24. bool ortho = brain != null ? brain.OutputCamera.orthographic : false;
  25. if (ortho)
  26. {
  27. excluded.Add(FieldPath(x => x.m_AdjustmentMode));
  28. excluded.Add(FieldPath(x => x.m_MinimumFOV));
  29. excluded.Add(FieldPath(x => x.m_MaximumFOV));
  30. excluded.Add(FieldPath(x => x.m_MaxDollyIn));
  31. excluded.Add(FieldPath(x => x.m_MaxDollyOut));
  32. excluded.Add(FieldPath(x => x.m_MinimumDistance));
  33. excluded.Add(FieldPath(x => x.m_MaximumDistance));
  34. }
  35. else
  36. {
  37. excluded.Add(FieldPath(x => x.m_MinimumOrthoSize));
  38. excluded.Add(FieldPath(x => x.m_MaximumOrthoSize));
  39. switch (MyTarget.m_AdjustmentMode)
  40. {
  41. case CinemachineGroupComposer.AdjustmentMode.DollyOnly:
  42. excluded.Add(FieldPath(x => x.m_MinimumFOV));
  43. excluded.Add(FieldPath(x => x.m_MaximumFOV));
  44. break;
  45. case CinemachineGroupComposer.AdjustmentMode.ZoomOnly:
  46. excluded.Add(FieldPath(x => x.m_MaxDollyIn));
  47. excluded.Add(FieldPath(x => x.m_MaxDollyOut));
  48. excluded.Add(FieldPath(x => x.m_MinimumDistance));
  49. excluded.Add(FieldPath(x => x.m_MaximumDistance));
  50. break;
  51. default:
  52. break;
  53. }
  54. }
  55. }
  56. public override void OnInspectorGUI()
  57. {
  58. if (MyTarget.IsValid && MyTarget.AbstractLookAtTargetGroup == null)
  59. EditorGUILayout.HelpBox(
  60. "The Framing settings will be ignored because the LookAt target is not a kind of ICinemachineTargetGroup",
  61. MessageType.Info);
  62. base.OnInspectorGUI();
  63. }
  64. [DrawGizmo(GizmoType.Active | GizmoType.InSelectionHierarchy, typeof(CinemachineGroupComposer))]
  65. private static void DrawGroupComposerGizmos(CinemachineGroupComposer target, GizmoType selectionType)
  66. {
  67. // Show the group bounding box, as viewed from the camera position
  68. if (target.AbstractLookAtTargetGroup != null)
  69. {
  70. Matrix4x4 m = Gizmos.matrix;
  71. Bounds b = target.LastBounds;
  72. Gizmos.matrix = target.LastBoundsMatrix;
  73. Gizmos.color = Color.yellow;
  74. if (target.VcamState.Lens.Orthographic)
  75. Gizmos.DrawWireCube(b.center, b.size);
  76. else
  77. {
  78. float z = b.center.z;
  79. Vector3 e = b.extents;
  80. Gizmos.DrawFrustum(
  81. Vector3.zero,
  82. Mathf.Atan2(e.y, z) * Mathf.Rad2Deg * 2,
  83. z + e.z, z - e.z, e.x / e.y);
  84. }
  85. Gizmos.matrix = m;
  86. }
  87. }
  88. }
  89. }