/// <summary> /// 播放一次,结束时隐藏 /// </summary> /// <param name="animator"></param> /// <param name="clipName"></param> /// <returns></returns> private Animator PlayOnceAndDisable(Animator animator, string clipName) { /// 取消使用缩放 //animator.transform.localScale = actionRenderer.transform.localScale; /// 方向以人物动作精灵渲染器为准 //animator.GetComponent<SpriteRenderer>().flipX = actionRenderer.flipX; /// 如果使用flipX属性直接改变精灵方向会导致碰撞盒与精灵图不一致, /// 尝试直接使用transform的Rotation绕Z轴旋转180度解决 if (actionRenderer.transform.localRotation != Quaternion.identity) { animator.transform.localEulerAngles = new Vector3(180, 0, 180); } else { animator.transform.localRotation = Quaternion.identity; } #if SHOWCLIP Debug.Log("<color=#FF1493>" + clipName + "</color>"); #endif animator.Play(clipName); animator.AnimationEndCallback(this, () => { /// 播放招式后进入共有空闲状态Empty animator.Play("Empty"); }); return(animator); }
public override void OnEnter() { #if UNITY_EDITOR if (controller == null) { Debug.LogError($"{Owner.name} 位于" + State.Name + "状态的RuntimeAnimatorController引用没有被赋值"); } #endif if (animator.runtimeAnimatorController != controller) { animator.runtimeAnimatorController = controller; //if (animator.GetComponent<AnimatorFinishEventTrigger>() == null) // animator.gameObject.AddComponent<AnimatorFinishEventTrigger>(); //animator.GetComponent<AnimatorFinishEventTrigger>().OnAnimatorControllerChanged(); } /// 处理当前相同动画的情况 if (interruptSameAnimation && animator.CurrentStateEqual(animationClip.Value)) { animator.Play(animationClip.Value, 0, 0f); } else { animator.Play(animationClip.Value); } if (!FsmEvent.IsNullOrEmpty(CompletedEvent)) { waitForAnimationToEndCoroutine = animator.AnimationEndCallback(playmakerFSM, () => Fsm.Event(CompletedEvent)); } //animator.OnCurrentAnimationCompleted(() => Fsm.Event(CompletedEvent)); if (forceFace2Player) { var target = Owner.GetComponent <NodeCanvas.Framework.Blackboard>().GetValue <Transform>("Target"); // if (target == null) // target = m_Player.transform; m_Monster.FaceDirection = Util.GetPlayerDirectionRelative(target.position, transform.position); } }