Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Animancer // Copyright 2019 Kybernetik //
- #pragma warning disable CS0649 // Field is never assigned to, and will always have its default value.
- using System;
- using UnityEngine;
- namespace Animancer.Examples
- {
- /// <summary>
- /// Demonstrates how to use Root Motion for some animations but not others.
- /// </summary>
- [AddComponentMenu("Animancer/Examples/Root Motion")]
- [HelpURL(AnimancerPlayable.APIDocumentationURL + ".Examples/RootMotion")]
- public sealed class RootMotion : MonoBehaviour
- {
- /************************************************************************************************************************/
- /// <summary>
- /// A <see cref="ClipState.Serializable"/> with an <see cref="ApplyRootMotion"/> to determine whether root
- /// motion should be enabled when it plays.
- /// </summary>
- [Serializable]
- public class MotionClip : ClipState.Serializable
- {
- /************************************************************************************************************************/
- [Tooltip("Determines if root motion should be enabled when this animation plays")]
- [SerializeField]
- private bool _ApplyRootMotion;
- /// <summary>
- /// Determines if root motion should be enabled when this animation plays.
- /// </summary>
- public bool ApplyRootMotion
- {
- get { return _ApplyRootMotion; }
- set { _ApplyRootMotion = value; }
- }
- /************************************************************************************************************************/
- }
- /************************************************************************************************************************/
- [SerializeField]
- private AnimancerComponent _Animancer;
- [SerializeField]
- private MotionClip[] _Animations;
- /************************************************************************************************************************/
- private void OnEnable()
- {
- Play(0);
- }
- /************************************************************************************************************************/
- public void Play(int index)
- {
- var animation = _Animations[index];
- _Animancer.Transition(animation);
- _Animancer.Animator.applyRootMotion = animation.ApplyRootMotion;
- }
- /************************************************************************************************************************/
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement