// (c) Copyright HutongGames, LLC 2010-2016. All rights reserved. using UnityEngine; namespace HutongGames.PlayMaker.Actions { [ActionCategory(ActionCategory.Animator)] [Tooltip("Gets the value of an int parameter")] public class GetAnimatorInt : FsmStateActionAnimatorBase { [RequiredField] [CheckForComponent(typeof(Animator))] [Tooltip("The target. An Animator component is required")] public FsmOwnerDefault gameObject; [RequiredField] [UIHint(UIHint.AnimatorInt)] [Tooltip("The animator parameter")] public FsmString parameter; [ActionSection("Results")] [RequiredField] [UIHint(UIHint.Variable)] [Tooltip("The int value of the animator parameter")] public FsmInt result; private Animator _animator; private int _paramID; public override void Reset() { base.Reset(); gameObject = null; parameter = null; result = null; } // Code that runs on entering the state. public override void OnEnter() { // get the animator component var go = Fsm.GetOwnerDefaultTarget(gameObject); if (go==null) { Finish(); return; } _animator = go.GetComponent(); if (_animator==null) { Finish(); return; } // get hash from the param for efficiency: _paramID = Animator.StringToHash(parameter.Value); GetParameter(); if (!everyFrame) { Finish(); } } public override void OnActionUpdate() { GetParameter(); } void GetParameter() { if (_animator!=null) { result.Value = _animator.GetInteger(_paramID); } } #if UNITY_EDITOR public override string AutoName() { return ActionHelpers.AutoNameGetProperty(this, parameter, result); } #endif } }