public float GetAnimtionClipLength(IAnim anim, string name) { Animator animator = anim.GetAnimator(); return(AnimManager.Instance.GetAnimtionClip(animator, 0, name).length); }
public void ResetAllTrigger(IAnim anim) { Animator animator = anim.GetAnimator(); AnimManager.Instance.ResetAllTrigger(animator); }
public bool GetStateBool(IAnim anim, string name) { Animator animator = anim.GetAnimator(); return(AnimManager.Instance.GetAnimtorBoolParam(animator, name)); }
public bool IsInTransforming(IAnim anim, string name) { Animator animator = anim.GetAnimator(); return(AnimManager.Instance.IsInTransforming(animator, 0, name)); }
public float GetAnimCurrentRuningTime(IAnim anim) { Animator animator = anim.GetAnimator(); return(AnimManager.Instance.GetCurrentNormalizeTime(animator, 0)); }
/// <summary> /// 是否正在运行指定动画 /// </summary> /// <param name="animName"></param> /// <param name="anim"></param> /// <returns></returns> public bool IsInStateAnim(string animName, IAnim anim) { Animator animator = anim.GetAnimator(); return(AnimManager.Instance.IsInThisAnimState(animator, 0, animName)); }
/// <summary> /// 依据游戏角色物体和回调控制器(mono)实现动态动画绑定 /// note:由于发布后,动画片段在内存重新加载时就会重置,所以不能用角色类型来判断是否绑定过 /// note:直接在动画片段上查找是否有绑定函数,没有再绑定 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="target"></param> public void BindAnimCallBack(IAnim target) { //绑定动画回调函数 //获得动画状态机中的所有动画片段引用 AnimationClip[] clips = target.GetAnimator().runtimeAnimatorController.animationClips; List <AnimCallBackEntity> entities = target.GetCallBacks(); foreach (var e in entities) { for (int i = 0; i < clips.Length; i++) { AnimationClip clip = clips[i]; if (clip.name.Equals(e.AnimName))//当动画片段的名称相同,这是需要绑定的目标 { //这里要加一步判断,判断是否该动画片段中已经绑定了同名方法,有则不再重复绑定 AnimationEvent[] events = clip.events; bool isExits = false; for (int j = 0; j < events.Length; j++) { //查找该片段的所有事件中,是否有同名事件了。 if (events[j].functionName.Equals(e.FunName)) { isExits = true; break; } } if (isExits)//若存在相同的同名事件方法 { break; } AnimationEvent ae = new AnimationEvent(); ae.time = clips[i].length * e.NormalizeTime; //用单位比例时间获得实际时间 ae.functionName = e.FunName; switch (e.Type) { case AnimEventParamType.Int: ae.intParameter = e.IntParam; break; case AnimEventParamType.Float: ae.floatParameter = e.FloatParam; break; case AnimEventParamType.Object: ae.objectReferenceParameter = e.ObjectParam; break; case AnimEventParamType.String: ae.stringParameter = e.StringParam; break; case AnimEventParamType.Null: break; } //给动画片段添加事件,只在运行时有效果 clips[i].AddEvent(ae); break; } } } }