| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107 |
- using UnityEngine;
- using UnityEditor;
- using System.Collections.Generic;
- namespace Cinemachine.Editor
- {
- [CustomEditor(typeof(CinemachineTransposer))]
- internal sealed class CinemachineTransposerEditor : BaseEditor<CinemachineTransposer>
- {
- /// <summary>Get the property names to exclude in the inspector.</summary>
- /// <param name="excluded">Add the names to this list</param>
- protected override void GetExcludedPropertiesInInspector(List<string> excluded)
- {
- base.GetExcludedPropertiesInInspector(excluded);
- switch (Target.m_BindingMode)
- {
- default:
- case CinemachineTransposer.BindingMode.LockToTarget:
- if (Target.m_AngularDampingMode == CinemachineTransposer.AngularDampingMode.Euler)
- excluded.Add(FieldPath(x => x.m_AngularDamping));
- else
- {
- excluded.Add(FieldPath(x => x.m_PitchDamping));
- excluded.Add(FieldPath(x => x.m_YawDamping));
- excluded.Add(FieldPath(x => x.m_RollDamping));
- }
- break;
- case CinemachineTransposer.BindingMode.LockToTargetNoRoll:
- excluded.Add(FieldPath(x => x.m_RollDamping));
- excluded.Add(FieldPath(x => x.m_AngularDamping));
- excluded.Add(FieldPath(x => x.m_AngularDampingMode));
- break;
- case CinemachineTransposer.BindingMode.LockToTargetWithWorldUp:
- excluded.Add(FieldPath(x => x.m_PitchDamping));
- excluded.Add(FieldPath(x => x.m_RollDamping));
- excluded.Add(FieldPath(x => x.m_AngularDamping));
- excluded.Add(FieldPath(x => x.m_AngularDampingMode));
- break;
- case CinemachineTransposer.BindingMode.LockToTargetOnAssign:
- case CinemachineTransposer.BindingMode.WorldSpace:
- excluded.Add(FieldPath(x => x.m_PitchDamping));
- excluded.Add(FieldPath(x => x.m_YawDamping));
- excluded.Add(FieldPath(x => x.m_RollDamping));
- excluded.Add(FieldPath(x => x.m_AngularDamping));
- excluded.Add(FieldPath(x => x.m_AngularDampingMode));
- break;
- case CinemachineTransposer.BindingMode.SimpleFollowWithWorldUp:
- excluded.Add(FieldPath(x => x.m_XDamping));
- excluded.Add(FieldPath(x => x.m_PitchDamping));
- excluded.Add(FieldPath(x => x.m_YawDamping));
- excluded.Add(FieldPath(x => x.m_RollDamping));
- excluded.Add(FieldPath(x => x.m_AngularDamping));
- excluded.Add(FieldPath(x => x.m_AngularDampingMode));
- break;
- }
- if (Target.HideOffsetInInspector)
- excluded.Add(FieldPath(x => x.m_FollowOffset));
- }
- public override void OnInspectorGUI()
- {
- BeginInspector();
- if (Target.FollowTarget == null)
- EditorGUILayout.HelpBox(
- "Transposer requires a Follow Target. Change Body to Do Nothing if you don't want a Follow target.",
- MessageType.Warning);
- DrawRemainingPropertiesInInspector();
- }
- /// Process a position drag from the user.
- /// Called "magically" by the vcam editor, so don't change the signature.
- public void OnVcamPositionDragged(Vector3 delta)
- {
- if (Target.FollowTarget != null)
- {
- Undo.RegisterCompleteObjectUndo(Target, "Camera drag");
- Quaternion targetOrientation = Target.GetReferenceOrientation(Target.VcamState.ReferenceUp);
- Vector3 localOffset = Quaternion.Inverse(targetOrientation) * delta;
- Target.m_FollowOffset += localOffset;
- Target.m_FollowOffset = Target.EffectiveOffset;
- }
- }
- [DrawGizmo(GizmoType.Active | GizmoType.Selected, typeof(CinemachineTransposer))]
- static void DrawTransposerGizmos(CinemachineTransposer target, GizmoType selectionType)
- {
- if (target.IsValid & !target.HideOffsetInInspector)
- {
- Color originalGizmoColour = Gizmos.color;
- Gizmos.color = CinemachineCore.Instance.IsLive(target.VirtualCamera)
- ? CinemachineSettings.CinemachineCoreSettings.ActiveGizmoColour
- : CinemachineSettings.CinemachineCoreSettings.InactiveGizmoColour;
- Vector3 up = Vector3.up;
- CinemachineBrain brain = CinemachineCore.Instance.FindPotentialTargetBrain(target.VirtualCamera);
- if (brain != null)
- up = brain.DefaultWorldUp;
- Vector3 targetPos = target.FollowTargetPosition;
- Vector3 desiredPos = target.GetTargetCameraPosition(up);
- Gizmos.DrawLine(targetPos, desiredPos);
- //Gizmos.DrawWireSphere(desiredPos, HandleUtility.GetHandleSize(desiredPos) / 20);
- Gizmos.color = originalGizmoColour;
- }
- }
- }
- }
|