Advertisement
Guest User

Animancer - Root Motion

a guest
Jun 1st, 2019
222
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.70 KB | None | 0 0
  1. // Animancer // Copyright 2019 Kybernetik //
  2.  
  3. #pragma warning disable CS0649 // Field is never assigned to, and will always have its default value.
  4.  
  5. using System;
  6. using UnityEngine;
  7.  
  8. namespace Animancer.Examples
  9. {
  10.     /// <summary>
  11.     /// Demonstrates how to use Root Motion for some animations but not others.
  12.     /// </summary>
  13.     [AddComponentMenu("Animancer/Examples/Root Motion")]
  14.     [HelpURL(AnimancerPlayable.APIDocumentationURL + ".Examples/RootMotion")]
  15.     public sealed class RootMotion : MonoBehaviour
  16.     {
  17.         /************************************************************************************************************************/
  18.  
  19.         /// <summary>
  20.         /// A <see cref="ClipState.Serializable"/> with an <see cref="ApplyRootMotion"/> to determine whether root
  21.         /// motion should be enabled when it plays.
  22.         /// </summary>
  23.         [Serializable]
  24.         public class MotionClip : ClipState.Serializable
  25.         {
  26.             /************************************************************************************************************************/
  27.  
  28.             [Tooltip("Determines if root motion should be enabled when this animation plays")]
  29.             [SerializeField]
  30.             private bool _ApplyRootMotion;
  31.  
  32.             /// <summary>
  33.             /// Determines if root motion should be enabled when this animation plays.
  34.             /// </summary>
  35.             public bool ApplyRootMotion
  36.             {
  37.                 get { return _ApplyRootMotion; }
  38.                 set { _ApplyRootMotion = value; }
  39.             }
  40.  
  41.             /************************************************************************************************************************/
  42.         }
  43.  
  44.         /************************************************************************************************************************/
  45.  
  46.         [SerializeField]
  47.         private AnimancerComponent _Animancer;
  48.  
  49.         [SerializeField]
  50.         private MotionClip[] _Animations;
  51.  
  52.         /************************************************************************************************************************/
  53.  
  54.         private void OnEnable()
  55.         {
  56.             Play(0);
  57.         }
  58.  
  59.         /************************************************************************************************************************/
  60.  
  61.         public void Play(int index)
  62.         {
  63.             var animation = _Animations[index];
  64.             _Animancer.Transition(animation);
  65.             _Animancer.Animator.applyRootMotion = animation.ApplyRootMotion;
  66.         }
  67.  
  68.         /************************************************************************************************************************/
  69.     }
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement