123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176 |
- using System;
- using UnityEngine;
- using UnityEngine.Animations;
- using UnityEngine.Playables;
- using Object = UnityEngine.Object;
- namespace Animancer
- {
-
-
-
-
-
-
- public class ClipState : AnimancerState
- {
-
-
- public interface ITransition : ITransition<ClipState> { }
-
- #region Fields and Properties
-
-
- private AnimationClip _Clip;
-
- public override AnimationClip Clip
- {
- get => _Clip;
- set
- {
- Validate.AssertNotLegacy(value);
- ChangeMainObject(ref _Clip, value);
- }
- }
-
- public override Object MainObject
- {
- get => _Clip;
- set => Clip = (AnimationClip)value;
- }
-
-
- public override float Length => _Clip.length;
-
-
- public override bool IsLooping => _Clip.isLooping;
-
-
- public override Vector3 AverageVelocity => _Clip.averageSpeed;
-
- #region Inverse Kinematics
-
-
- public override bool ApplyAnimatorIK
- {
- get
- {
- Validate.AssertPlayable(this);
- return ((AnimationClipPlayable)_Playable).GetApplyPlayableIK();
- }
- set
- {
- Validate.AssertPlayable(this);
- ((AnimationClipPlayable)_Playable).SetApplyPlayableIK(value);
- }
- }
-
-
- public override bool ApplyFootIK
- {
- get
- {
- Validate.AssertPlayable(this);
- return ((AnimationClipPlayable)_Playable).GetApplyFootIK();
- }
- set
- {
- Validate.AssertPlayable(this);
- ((AnimationClipPlayable)_Playable).SetApplyFootIK(value);
- }
- }
-
- #endregion
-
- #endregion
-
- #region Methods
-
-
-
- public ClipState(AnimationClip clip)
- {
- Validate.AssertNotLegacy(clip);
- _Clip = clip;
- }
-
-
- protected override void CreatePlayable(out Playable playable)
- {
- var clipPlayable = AnimationClipPlayable.Create(Root._Graph, _Clip);
- playable = clipPlayable;
- }
-
-
- public override void Destroy()
- {
- _Clip = null;
- base.Destroy();
- }
-
- #endregion
-
- #region Inspector
- #if UNITY_EDITOR
-
-
- protected internal override Editor.IAnimancerNodeDrawer CreateDrawer() => new Drawer(this);
-
-
- public class Drawer : Editor.AnimancerStateDrawer<ClipState>
- {
-
-
- public Drawer(ClipState state) : base(state) { }
-
-
- protected override void AddContextMenuFunctions(UnityEditor.GenericMenu menu)
- {
- menu.AddDisabledItem(new GUIContent(
- $"{DetailsPrefix}Animation Type: {Editor.AnimationBindings.GetAnimationType(Target._Clip)}"));
- base.AddContextMenuFunctions(menu);
- Editor.AnimancerEditorUtilities.AddContextMenuIK(menu, Target);
- }
-
- }
-
- #endif
- #endregion
-
- }
- }
|