void DoAction(AnimatorAction _actionType, ActionParamtersType _ActionParamtersType, int _intValue = 1, float _floatValue = 0.0f)//播放或停止动作 { this.enity.OnPlayAnimation(_actionType, _intValue, _floatValue); //if (animator != null && animator.parameterCount > (int)_actionType) //{ // string _animatorParameterName = animator.GetParameter((int)_actionType).name; // switch (_ActionParamtersType) // { // case ActionParamtersType.Float: // if (animator.GetFloat(_animatorParameterName) != _floatValue) // animator.SetFloat(_animatorParameterName, _floatValue); // break; // case ActionParamtersType.Int: // if (animator.GetInteger(_animatorParameterName) != _intValue) // animator.SetInteger(_animatorParameterName, _intValue); // break; // case ActionParamtersType.Bool: // if (animator.GetBool(_animatorParameterName) != _intValue > 0) // animator.SetBool(_animatorParameterName, _intValue >0); // break; // case ActionParamtersType.Trigger: // animator.SetTrigger(_animatorParameterName); // break; // default: // break; // } //} }
public void OnPlayAnimation(AnimatorParameters _actionType, ActionParamtersType _ActionParamtersType, int _intValue = 1, float _floatValue = 0.0f)//播放或停止动作 { for (int i = 0; i < animatorList.Count; i++) { Animator animator = animatorList[i]; if (animator != null) { if (animator.parameterCount > (int)_actionType) { if (_ActionParamtersType != ActionParamtersType.Trigger) { animatorParameters = _actionType; } string _animatorParameterName = animator.GetParameter((int)_actionType).name; switch (_ActionParamtersType) { case ActionParamtersType.Float: if (animator.GetFloat(_animatorParameterName) != _floatValue) { animator.SetFloat(_animatorParameterName, _floatValue); } break; case ActionParamtersType.Int: if (animator.GetInteger(_animatorParameterName) != _intValue) { animator.SetInteger(_animatorParameterName, _intValue); } break; case ActionParamtersType.Bool: if (animator.GetBool(_animatorParameterName) != _intValue > 0) { animator.SetBool(_animatorParameterName, (bool)(_intValue > 0)); } break; case ActionParamtersType.Trigger: animator.SetTrigger(_animatorParameterName); break; default: break; } } else { animator.Play("Idle"); } } } }