arthurdiniz0_outer-math/OuterMath Unity Project/Assets/PlayMaker/Actions/Animator/GetAnimatorPivot.cs
// (c) Copyright HutongGames, LLC 2010-2016. All rights reserved.

using UnityEngine;

namespace HutongGames.PlayMaker.Actions
{
	[ActionCategory(ActionCategory.Animator)]
	[Tooltip("Returns the pivot weight and/or position. The pivot is the most stable point between the avatar's left and right foot.\n For a weight value of 0, the left foot is the most stable point For a value of 1, the right foot is the most stable point")]
	public class GetAnimatorPivot : FsmStateActionAnimatorBase
	{
		[RequiredField]
		[CheckForComponent(typeof(Animator))]
        [Tooltip("The GameObject with an Animator Component.")]
		public FsmOwnerDefault gameObject;
		
		[ActionSection("Results")]
		
		[UIHint(UIHint.Variable)]
		[Tooltip("The pivot is the most stable point between the avatar's left and right foot.\n For a value of 0, the left foot is the most stable point For a value of 1, the right foot is the most stable point")]
		public FsmFloat pivotWeight;
		
		[UIHint(UIHint.Variable)]
		[Tooltip("The pivot is the most stable point between the avatar's left and right foot.\n For a value of 0, the left foot is the most stable point For a value of 1, the right foot is the most stable point")]
		public FsmVector3 pivotPosition;

        private Animator animator
        {
            get { return cachedComponent; }
        }

        public override void Reset()
		{
			base.Reset();

			gameObject = null;
			pivotWeight = null;
			pivotPosition = null;
		}
		
		public override void OnEnter()
		{
			DoCheckPivot();
			
			if (!everyFrame)
			{
				Finish();
			}
		}

		public override void OnActionUpdate() 
		{
			DoCheckPivot();
		}


        private void DoCheckPivot()
		{
            if (!UpdateCache(Fsm.GetOwnerDefaultTarget(gameObject)))
            {
                Finish();
                return;
            }

            if (!pivotWeight.IsNone)
			{
				pivotWeight.Value = animator.pivotWeight;
			}
			if (!pivotPosition.IsNone)
			{
				pivotPosition.Value = animator.pivotPosition;
			}

		}
	}
}