123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145 |
- #if UNITY_EDITOR
- using System;
- using UnityEditor;
- using UnityEngine;
- namespace Animancer.Editor
- {
-
-
-
- public abstract class BaseAnimancerComponentEditor : UnityEditor.Editor
- {
-
- [NonSerialized]
- private IAnimancerComponent[] _Targets;
-
- public IAnimancerComponent[] Targets => _Targets;
-
- private readonly AnimancerPlayableDrawer
- PlayableDrawer = new AnimancerPlayableDrawer();
-
-
- protected virtual void OnEnable()
- {
- var targets = this.targets;
- _Targets = new IAnimancerComponent[targets.Length];
- GatherTargets();
- }
-
-
-
-
- private void GatherTargets()
- {
- for (int i = 0; i < _Targets.Length; i++)
- _Targets[i] = (IAnimancerComponent)targets[i];
- }
-
-
- public override void OnInspectorGUI()
- {
- _LastRepaintTime = EditorApplication.timeSinceStartup;
-
-
- GatherTargets();
- serializedObject.Update();
- var area = GUILayoutUtility.GetRect(0, 0);
- DoOtherFieldsGUI();
- PlayableDrawer.DoGUI(_Targets);
- area.yMax = GUILayoutUtility.GetLastRect().yMax;
- AnimancerLayerDrawer.HandleDragAndDropAnimations(area, _Targets[0], 0);
- serializedObject.ApplyModifiedProperties();
- }
-
- [NonSerialized]
- private double _LastRepaintTime = double.NegativeInfinity;
-
-
-
-
- public override bool RequiresConstantRepaint()
- {
- if (_Targets.Length != 1)
- return false;
- var target = _Targets[0];
- if (!target.IsPlayableInitialized)
- {
- if (!EditorApplication.isPlaying ||
- target.Animator == null ||
- target.Animator.runtimeAnimatorController == null)
- return false;
- }
- if (AnimancerPlayableDrawer.RepaintConstantly)
- return true;
- return EditorApplication.timeSinceStartup > _LastRepaintTime + AnimancerSettings.InspectorRepaintInterval;
- }
-
-
- protected void DoOtherFieldsGUI()
- {
- var property = serializedObject.GetIterator();
- if (!property.NextVisible(true))
- return;
- do
- {
- var path = property.propertyPath;
- if (path == "m_Script")
- continue;
- using (ObjectPool.Disposable.AcquireContent(out var label, property))
- {
-
- if (DoOverridePropertyGUI(path, property, label))
- continue;
-
- EditorGUILayout.PropertyField(property, label, true);
- }
- }
- while (property.NextVisible(false));
- }
-
-
-
-
-
-
-
- protected virtual bool DoOverridePropertyGUI(string path, SerializedProperty property, GUIContent label) => false;
-
- }
- }
- #endif
|