diff options
Diffstat (limited to 'Runtime/Graphs/UnityEngine.Graphs/LogicNodeLibrary/Animation')
-rw-r--r-- | Runtime/Graphs/UnityEngine.Graphs/LogicNodeLibrary/Animation/AnimationNodes.cs | 76 | ||||
-rw-r--r-- | Runtime/Graphs/UnityEngine.Graphs/LogicNodeLibrary/Animation/SimpleAnimationPlayer.cs | 78 |
2 files changed, 154 insertions, 0 deletions
diff --git a/Runtime/Graphs/UnityEngine.Graphs/LogicNodeLibrary/Animation/AnimationNodes.cs b/Runtime/Graphs/UnityEngine.Graphs/LogicNodeLibrary/Animation/AnimationNodes.cs new file mode 100644 index 0000000..28d0efd --- /dev/null +++ b/Runtime/Graphs/UnityEngine.Graphs/LogicNodeLibrary/Animation/AnimationNodes.cs @@ -0,0 +1,76 @@ +using UnityEngine; + +namespace UnityEngine.Graphs.LogicGraph +{ + public partial class AnimationNodes + { + [Logic(typeof(Animation))] + [return: Title("Animation State")] + public static AnimationState GetAnimationState (Animation self, [Setting] string animationStateName) + { + return self[animationStateName]; + } + + [Logic(typeof(Animation))] + [return: Title("Animation State")] + public static AnimationState PlayAnimation (Animation self, [Setting] string animationName, [Setting] bool crossfade, [Setting] float fadeLength, [Setting] PlayMode playMode) + { + AnimationState animationState = self[animationName == "" ? self.clip.name : animationName]; + + if (crossfade) + self.CrossFade (animationState.name, fadeLength, playMode); + else + self.Play (animationState.name, playMode); + + return animationState; + } + + [Logic(typeof(Animation))] + [return: Title("Animation State")] + public static AnimationState PlayQueuedAnimation (Animation self, [Setting] string animationName, [Setting] bool crossfade, [Setting] float fadeLength, [Setting] QueueMode queueMode, [Setting] PlayMode playMode) + { + if (animationName == "") + animationName = self.clip.name; + + var animationState = crossfade ? + self.CrossFadeQueued (animationName, fadeLength, queueMode, playMode) : + self.PlayQueued (animationName, queueMode, playMode); + + return animationState; + } + + [Logic(typeof(Animation))] + public static void StopAnimation (Animation self, [Setting] string animationName) + { + if (animationName == "") + self.Stop(); + else + self.Stop(animationName); + } + + [Logic (typeof (Animation))] + public static void SampleAnimation (Animation self) + { + self.Sample (); + } + + [Logic(typeof(Animation))] + public static void StopAnimationState (Animation self, AnimationState animationState) + { + self.Stop(animationState.name); + } + + [Logic(typeof(Animation))] + public static void BlendAnimationState (Animation self, AnimationState animationState, float targetWeight, [Setting] float fadeLength) + { + self.Blend (animationState.name, targetWeight, fadeLength); + } + + [Logic(typeof(Animation))] + public static void SyncAnimationLayer (Animation self, int layer) + { + self.SyncLayer (layer); + } + } +} + diff --git a/Runtime/Graphs/UnityEngine.Graphs/LogicNodeLibrary/Animation/SimpleAnimationPlayer.cs b/Runtime/Graphs/UnityEngine.Graphs/LogicNodeLibrary/Animation/SimpleAnimationPlayer.cs new file mode 100644 index 0000000..9b1ee07 --- /dev/null +++ b/Runtime/Graphs/UnityEngine.Graphs/LogicNodeLibrary/Animation/SimpleAnimationPlayer.cs @@ -0,0 +1,78 @@ +using UnityEngine; + +namespace UnityEngine.Graphs.LogicGraph +{ + public partial class AnimationNodes + { + [Logic(typeof(Animation))] + public sealed class SimpleAnimationPlayer + { + // Logic Target + public Animation self; + + // Settings + private AnimationState m_AnimationState; + [Setting] + public string animationName + { + set + { + m_AnimationState = self[value != "" ? value : self.clip.name]; + } + } + private bool m_Crossfade; + [Setting] + public bool crossfade { set { m_Crossfade = value; } } + private float m_FadeLength; + [Setting] + public float fadeLength { set { m_FadeLength = value; } } + + private bool m_IsPaused; + private float m_ResumeSpeed; + + public SimpleAnimationPlayer () { } + + public SimpleAnimationPlayer (Animation self, string animationName, bool crossfade, float fadeLength) + { + this.self = self; + this.animationName = animationName; + m_Crossfade = crossfade; + m_FadeLength = fadeLength; + } + + public void Play () + { + if (m_Crossfade) + self.CrossFade (m_AnimationState.name, m_FadeLength); + else + self.Play (m_AnimationState.name); + } + + public void Stop () + { + StopAnimationState (m_AnimationState); + } + + [Title("Pause/Resume")] + public void PauseResume () + { + float tmpSpeed = m_AnimationState.speed; + m_AnimationState.speed = m_IsPaused ? m_ResumeSpeed : 0.0f; + + m_ResumeSpeed = tmpSpeed; + m_IsPaused = !m_IsPaused; + } + + public void Rewind () + { + m_AnimationState.time = 0.0f; + } + + private static void StopAnimationState (AnimationState animationState) + { + animationState.enabled = false; + animationState.time = 0.0f; + } + } + } +} |