123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358 |
- using UnityEngine;
- using System;
- #if UNITY_EDITOR
- using Animancer.Editor;
- using UnityEditor;
- #endif
- namespace Animancer
- {
-
-
- public partial class AnimancerTransitionAssetBase
- {
-
-
- [Serializable]
- public class UnShared : UnShared<AnimancerTransitionAssetBase> { }
-
-
-
-
-
-
-
-
-
-
-
- [Serializable]
- public class UnShared<TAsset> : ITransition, ITransitionWithEvents, IWrapper
- where TAsset : AnimancerTransitionAssetBase
- {
-
- [SerializeField]
- private TAsset _Asset;
-
- public TAsset Asset
- {
- get
- {
- AssertAsset();
- return _Asset;
- }
- set
- {
- _Asset = value;
- BaseState = null;
- ClearCachedEvents();
- }
- }
-
- object IWrapper.WrappedObject => _Asset;
-
- public ITransition BaseTransition => _Asset.GetTransition();
-
-
- public virtual bool IsValid
- {
- get
- {
- AssertAsset();
- return _Asset.IsValid();
- }
- }
-
-
- public bool HasAsset => _Asset != null;
-
-
- [System.Diagnostics.Conditional(Strings.Assertions)]
- private void AssertAsset()
- {
- if (_Asset == null)
- Debug.LogError($"{GetType().Name}.{nameof(Asset)} is not assigned." +
- $" {nameof(HasAsset)} can be used to check without triggering this error.");
- }
-
- private AnimancerState _BaseState;
-
-
-
-
-
-
-
-
-
-
- public AnimancerState BaseState
- {
- get => _BaseState;
- protected set
- {
- _BaseState = value;
- OnSetBaseState();
- }
- }
-
- protected virtual void OnSetBaseState() { }
-
- private AnimancerEvent.Sequence _Events;
-
-
- public virtual AnimancerEvent.Sequence Events
- {
- get
- {
- if (_Events == null)
- _Events = new AnimancerEvent.Sequence(SerializedEvents.GetEventsOptional());
- return _Events;
- }
- }
-
- public virtual ref AnimancerEvent.Sequence.Serializable SerializedEvents
- {
- get
- {
- AssertAsset();
- return ref ((ITransitionWithEvents)_Asset.GetTransition()).SerializedEvents;
- }
- }
-
-
-
-
- public void ClearCachedEvents()
- {
- _Events = null;
- }
-
-
- public virtual void Apply(AnimancerState state)
- {
- BaseState = state;
- _Asset.Apply(state);
- if (_Events == null)
- {
- _Events = SerializedEvents.GetEventsOptional();
- if (_Events == null)
- return;
- _Events = new AnimancerEvent.Sequence(_Events);
- }
- state.Events = _Events;
- }
-
-
- public virtual object Key
- {
- get
- {
- AssertAsset();
- return _Asset.Key;
- }
- }
-
- public virtual float FadeDuration
- {
- get
- {
- AssertAsset();
- return _Asset.FadeDuration;
- }
- }
-
- public virtual FadeMode FadeMode
- {
- get
- {
- AssertAsset();
- return _Asset.FadeMode;
- }
- }
-
- AnimancerState ITransition.CreateState()
- {
- AssertAsset();
- return BaseState = _Asset.CreateState();
- }
-
- }
-
-
- [Serializable]
- public class UnShared<TAsset, TTransition, TState> : UnShared<TAsset>, ITransition<TState>
- where TAsset : AnimancerTransitionAsset<TTransition>
- where TTransition : ITransition<TState>, IHasEvents
- where TState : AnimancerState
- {
-
-
- public TTransition Transition
- {
- get => Asset.Transition;
- set => Asset.Transition = value;
- }
-
-
- protected override void OnSetBaseState()
- {
- base.OnSetBaseState();
- if (_State != BaseState)
- _State = null;
- }
-
- private TState _State;
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- public TState State
- {
- get
- {
- if (_State == null)
- _State = (TState)BaseState;
- return _State;
- }
- protected set
- {
- BaseState = _State = value;
- }
- }
-
-
- public override ref AnimancerEvent.Sequence.Serializable SerializedEvents
- => ref Asset.Transition.SerializedEvents;
-
-
- public virtual TState CreateState()
- => State = (TState)Asset.CreateState();
-
- }
-
- #if UNITY_EDITOR
-
-
-
-
-
-
-
-
-
-
-
-
-
- [CustomPropertyDrawer(typeof(UnShared<>), true)]
- public class UnSharedTransitionDrawer : PropertyDrawer
- {
-
-
- public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
- {
- var height = AnimancerGUI.LineHeight;
- if (property.propertyType == SerializedPropertyType.ManagedReference &&
- property.isExpanded)
- height += AnimancerGUI.LineHeight + AnimancerGUI.StandardSpacing;
- return height;
- }
-
-
- public override void OnGUI(Rect area, SerializedProperty property, GUIContent label)
- {
- if (property.propertyType == SerializedPropertyType.ManagedReference)
- {
- using (new TypeSelectionButton(area, property, true))
- EditorGUI.PropertyField(area, property, label, true);
- }
- else
- {
- var transitionProperty = property.FindPropertyRelative("_Asset");
- EditorGUI.PropertyField(area, transitionProperty, label, false);
- }
- }
-
- }
- #endif
-
- }
- }
|