forked from BilalY/Rasagar
106 lines
4.4 KiB
C#
106 lines
4.4 KiB
C#
using UnityEngine;
|
|
using UnityEditor;
|
|
using System.Collections.Generic;
|
|
|
|
namespace Cinemachine.Editor
|
|
{
|
|
[CustomEditor(typeof(CinemachineTransposer))]
|
|
[CanEditMultipleObjects]
|
|
internal 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();
|
|
bool needWarning = false;
|
|
for (int i = 0; !needWarning && i < targets.Length; ++i)
|
|
needWarning = (targets[i] as CinemachineTransposer).FollowTarget == null;
|
|
if (needWarning)
|
|
EditorGUILayout.HelpBox(
|
|
"Transposer requires a Follow Target. Change Body to Do Nothing if you don't want a Follow target.",
|
|
MessageType.Warning);
|
|
DrawRemainingPropertiesInInspector();
|
|
}
|
|
#if UNITY_2021_2_OR_NEWER
|
|
void OnSceneGUI()
|
|
{
|
|
DrawSceneTools();
|
|
}
|
|
|
|
protected virtual void OnEnable()
|
|
{
|
|
CinemachineSceneToolUtility.RegisterTool(typeof(FollowOffsetTool));
|
|
}
|
|
|
|
protected virtual void OnDisable()
|
|
{
|
|
CinemachineSceneToolUtility.UnregisterTool(typeof(FollowOffsetTool));
|
|
}
|
|
|
|
void DrawSceneTools()
|
|
{
|
|
var transposer = Target;
|
|
if (transposer == null || !transposer.IsValid)
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (CinemachineSceneToolUtility.IsToolActive(typeof(FollowOffsetTool)))
|
|
{
|
|
CinemachineSceneToolHelpers.TransposerFollowOffsetTool(transposer);
|
|
}
|
|
}
|
|
#endif
|
|
}
|
|
}
|