Esempio n. 1
0
 public void OnStateEvent(string stateName, AnimatorStateEventType eventType, Animator animator, AnimatorStateInfo stateInfo,
                          int layerIndex, float time)
 {
     if (OnStateEvents != null)
     {
         OnStateEvents(stateName, eventType, animator, stateInfo, layerIndex, time);
     }
 }
Esempio n. 2
0
        public void OnSelfStateEvent(string stateName, AnimatorStateEventType eventType, Animator animator,
                                     AnimatorStateInfo stateInfo,
                                     int layerIndex, float time)
        {
//            if (_qteState == QteState.QteRunning)
//            {
//                if (stateName == "Qte_ToHuman_Success")
//                {
//                    if (eventType == AnimatorStateEventType.OnStateExit)
//                    {
//                        Success();
//                    }
//                }
//            }
        }
Esempio n. 3
0
 public void OnTargetStateEvent(string stateName, AnimatorStateEventType eventType, Animator animator,
                                AnimatorStateInfo stateInfo,
                                int layerIndex, float time)
 {
     if (_qteState == QteState.QteRunning)
     {
         if (eventType == AnimatorStateEventType.OnStateEnter)
         {
             if (stateName == "Qte_DogToHuman_Struggle")
             {
                 StruggleTimes++;
                 if (StruggleTimes >= 1)
                 {
                     _qteState = QteState.QteFailure;
                     targetController.RoleAnimator.SetTrigger("qte_struggleSuccess");
                 }
             }
         }
     }
 }
Esempio n. 4
0
        public override void UpdateMovement(string stateName, AnimatorStateEventType eventType, Animator animator,
                                            AnimatorStateInfo stateInfo,
                                            int layerIndex, float time)
        {
            AnimatorStateInfo currStateInfo = stateInfo;

            AnimatorStateInfo nextStateInfo = animator.GetNextAnimatorStateInfo(layerIndex);
            bool hasNext = nextStateInfo.fullPathHash != 0;

            if (hasNext)
            {
                currStateInfo = nextStateInfo;
            }
            else if (skeletonAnimator.IsInterruptionActive(layerIndex))
            {
                currStateInfo = skeletonAnimator.GetInterruptingStateInfo(layerIndex);
            }

            if (eventType == AnimatorStateEventType.OnStateUpdate)
            {
                if (lastUpdateMovementTime < 0)
                {
                    lastUpdateMovementTime = Time.time;
                }

                var deltaTime = Time.time - lastUpdateMovementTime;
                lastUpdateMovementTime = Time.time;

                if (
                    currStateInfo.IsTag("hurt") ||
                    currStateInfo.IsTag("hurtHold"))
                {
                    CalcSpeed(deltaTime, Vector2.zero);
                    speed = CalcGravity(speed, deltaTime);
                    Move(Speed * deltaTime);
                }
                else if (currStateInfo.IsTag("idle"))
                {
                    speed = CalcGravity(speed, deltaTime);

                    TurnBackWithAnim();

                    if (joystick.magnitude < 0.5f)
                    {
                        speed.x = 0;
                        speed.z = 0;
                    }

                    Move(Speed * deltaTime);
                }
                else if (
                    currStateInfo.IsTag("move") ||
                    currStateInfo.IsTag("run") ||
                    currStateInfo.IsTag("walk")
                    // || currAnimatorStateInfo.IsTag("accelerateRoll")
                    )
                {
                    // 倒播移动
                    if (IsAltPressed && joystick.x * GetDirectionInt() < 0)
                    {
                        SkeletonAnimator.SetBackwards(true);
                    }
                    else
                    {
                        SkeletonAnimator.SetBackwards(false);
                    }

                    speed = CalcGravity(speed, deltaTime);

                    TurnBackWithAnim();

                    CalcSpeed(deltaTime);
                    Move(Speed * deltaTime);
                }
                else if (
                    currStateInfo.IsTag("rush")
                    )
                {
                    speed = CalcGravity(speed, deltaTime);

                    TurnBackWithAnim();

                    CalcSpeed(deltaTime, new Vector2(joystick.x, joystick.y / 2), RushSpeed);
                    Move(Speed * deltaTime);
                }
                else if (
                    currStateInfo.IsTag("rush_end")
                    )
                {
                    speed = CalcGravity(speed, deltaTime);

                    TurnBackWithAnim();

                    CalcSpeed(deltaTime, Vector2.zero);
                    Move(Speed * deltaTime);
                }
                else if (currStateInfo.IsTag("attack"))
                {
                    speed = CalcGravity(speed, deltaTime);

                    CalcSpeed(deltaTime, Vector2.zero);
                    Move(Speed * deltaTime);
                }
                else if (currStateInfo.IsTag("jumping"))
                {
                    speed = CalcGravity(speed, deltaTime);

//                    TurnBack();

                    CalcSpeed(deltaTime);


                    if (joystick.magnitude <= 0.1f)
                    {
                        speed.x = 0;
                        speed.z = 0;
                    }

                    if (speed.x * GetDirectionInt() < 0)
                    {
                        Move(new Vector3(Speed.x / 2f, Speed.y, Speed.z) * deltaTime);
                    }
                    else
                    {
                        Move(Speed * deltaTime);
                    }
                }
                else if (currStateInfo.IsTag("jumpingAttack"))
                {
                    speed = CalcGravity(speed, deltaTime);

                    CalcSpeed(deltaTime, Vector2.zero);
                    Vector3 finalSpeed = Vector3.zero;
                    finalSpeed.x = Speed.x;
                    finalSpeed.y = Speed.y * currVariableSpeed;
                    finalSpeed.z = Speed.z;
                    Move(new Vector3(finalSpeed.x / 5f, finalSpeed.y, finalSpeed.z / 5f) * deltaTime);
                }
                else if (currStateInfo.IsTag("landing"))
                {
                    speed = CalcGravity(speed, deltaTime);

                    CalcSpeed(deltaTime, Vector2.zero);
                    Move(Speed * deltaTime);
                }
                else if (currStateInfo.IsTag("nomove"))
                {
                    speed = CalcGravity(speed, deltaTime);
                }
                else if (currStateInfo.IsTag("dun-idle") || currStateInfo.IsTag("dun-move"))
                {
                    speed = CalcGravity(speed, deltaTime);

                    CalcSpeed(deltaTime);
                    Move(Speed / 3f * deltaTime);
                }
                else if (currStateInfo.IsTag("nocontrol"))
                {
                    speed = CalcGravity(speed, deltaTime);

                    CalcSpeed(deltaTime, Vector2.zero);
                    Move(Speed * deltaTime);
                }
                else if (currStateInfo.IsTag("climb"))
                {
                    speed = CalcGravity(speed, deltaTime);

                    speed.y = 0;
                }
                else if (currStateInfo.IsTag("ClimbLadder"))
                {
                    speed = CalcGravity(speed, deltaTime);

                    speed.y = 0;
                    if (joystick.y != 0f)
                    {
                        OverClimbLadder();
                    }
                }
                else if (currStateInfo.IsTag("jumpattack"))
                {
                    speed = CalcGravity(speed, deltaTime);
                    CalcSpeed(deltaTime, Vector2.zero);
                    Move(new Vector3(Speed.x / 10f, Speed.y, Speed.x / 10f) * deltaTime);
                }
                else
                {
                    speed = CalcGravity(speed, deltaTime);
                    CalcSpeed(deltaTime, Vector2.zero);
                    Move(Speed * deltaTime);
                }
            }
            else if (eventType == AnimatorStateEventType.OnStateExit)
            {
                if (
                    currStateInfo.IsTag("walk") ||
                    currStateInfo.IsTag("run") ||
                    currStateInfo.IsTag("move")
                    // || currAnimatorStateInfo.IsTag("accelerateRoll")
                    )
                {
                    skeletonAnimator.SetBackwards(false);
                }
            }
        }
Esempio n. 5
0
 public virtual void UpdateMovement(string stateName, AnimatorStateEventType eventType, Animator animator,
                                    AnimatorStateInfo stateInfo,
                                    int layerIndex, float time)
 {
 }
Esempio n. 6
0
        public void OnStateEvent(string stateName, AnimatorStateEventType eventType, Animator animator, AnimatorStateInfo stateInfo,
                                 int layerIndex, float time)
        {
            Debug.Log("StateName = " + stateName + ", eventType = " + eventType);
            if (stateName == "Normal")
            {
                if (eventType == AnimatorStateEventType.OnStateEnter)
                {
                    colliderParent.SetActive(true);
                    triggerParent.SetActive(true);

                    MainSkeletonAnimator.SetFillVertexType(FillVertexType.Ground);
                }
            }
            else if (stateName == "BreakingHold" && time >= breakingDelay)
            {
                switch (eventType)
                {
                case AnimatorStateEventType.OnStateUpdate:
                    if (stateInfo.normalizedTime >= 1)
                    {
                        State = 2;
                    }
                    break;
                }
            }
            else if (stateName == "Breaking")
            {
                if (eventType == AnimatorStateEventType.OnStateEnter)
                {
                    colliderParent.SetActive(false);
                    triggerParent.SetActive(false);

                    MainSkeletonAnimator.SetFillVertexType(FillVertexType.Center);
                }
                else if (eventType == AnimatorStateEventType.OnStateUpdate)
                {
                    if (stateInfo.normalizedTime >= 1)
                    {
                        State = 3;
                    }
                }
            }
            else if (stateName == "Breaked")
            {
                if (eventType == AnimatorStateEventType.OnStateUpdate)
                {
                    if (stateInfo.normalizedTime >= 1 && time >= recoverDelay)
                    {
                        State = 4;
                    }
                }
            }
            else if (stateName == "Recovering")
            {
                if (eventType == AnimatorStateEventType.OnStateUpdate)
                {
                    if (stateInfo.normalizedTime >= 1)
                    {
                        State = 0;
                    }
                }
            }
        }
Esempio n. 7
0
        public virtual void UpdateMovement(string stateName, AnimatorStateEventType eventType, Animator animator,
                                           AnimatorStateInfo stateInfo,
                                           int layerIndex, float time)
        {
            currStateName = stateName;

            AnimatorStateInfo currStateInfo = stateInfo;

            AnimatorStateInfo nextStateInfo = animator.GetNextAnimatorStateInfo(layerIndex);
            bool hasNext = nextStateInfo.fullPathHash != 0;

            if (hasNext)
            {
                currStateInfo = nextStateInfo;
            }
            else if (skeletonAnimator.IsInterruptionActive(layerIndex))
            {
                currStateInfo = skeletonAnimator.GetInterruptingStateInfo(layerIndex);
            }

            if (eventType == AnimatorStateEventType.OnStateUpdate)
            {
                if (lastUpdateMovementTime < 0)
                {
                    lastUpdateMovementTime = Time.time;
                }

                var deltaTime = Time.time - lastUpdateMovementTime;
                lastUpdateMovementTime = Time.time;
//                var deltaTime = Time.deltaTime / 2f;

//                deltaTime *= _animator.speed * currStateInfo.speed;

                // 通过移动动画额定速度, 调整动画播放速度
//                float moveAnimSpeedScale = skeletonAnimator.GetMoveAnimSpeedScale(stateName, speed.magnitude);
//                _animator.speed = moveAnimSpeedScale;


                if (
                    currStateInfo.IsTag("hurt") ||
                    currStateInfo.IsTag("hurtHold"))
                {
                    joystick = Vector2.zero;

                    CalcSpeed(deltaTime);
                    speed = CalcGravity(speed, deltaTime, true);
                    Move(Speed * deltaTime);
                }
                else if (currStateInfo.IsTag("idle"))
                {
                    speed = CalcGravity(speed, deltaTime);


                    TurnBackWithAnim();

                    if (joystick.magnitude < 0.5f)
                    {
                        speed.x = 0;
                        speed.z = 0;
                    }

                    CalcSpeed(deltaTime);
                    Move(Speed * deltaTime);
                }
                else if (
                    currStateInfo.IsTag("move")
//                    || currStateInfo.IsTag("walk")
//                    || currStateInfo.IsTag("rush")
//                    || currStateInfo.IsTag("run")
                    )
                {
                    // 倒播移动
                    if (IsAltPressed && joystick.x * GetDirectionInt() < 0)
                    {
                        SkeletonAnimator.SetBackwards(true);
                    }
                    else
                    {
                        SkeletonAnimator.SetBackwards(false);
                    }

                    speed = CalcGravity(speed, deltaTime);


                    TurnBackWithAnim();

                    CalcSpeed(deltaTime);
                    Move(Speed * deltaTime);
                }
                else if (
                    currStateInfo.IsTag("run") ||
                    currStateInfo.IsTag("walk") ||
                    currStateInfo.IsTag("move"))
                {
                    TurnBack();

                    speed = CalcGravity(speed, deltaTime);
                    CalcSpeed(deltaTime);
//                    Move(Speed * deltaTime);
                }
                else if (
                    currStateInfo.IsTag("rush_end")
                    )
                {
                    speed = CalcGravity(speed, deltaTime);


                    joystick = Vector2.zero;
                    //GroundFrictionAcceleration = 30f;
                    CalcSpeed(deltaTime);
                    //GroundFrictionAcceleration = 60f;
                    //Speed = new Vector3(Speed.x, Speed.y, Speed.z / 2f);
                    Move(Speed * deltaTime);
                }
                else if (
                    currStateInfo.IsTag("roll") ||
                    currStateInfo.IsTag("dodge"))
                {
                    TurnBack();

                    speed = CalcGravity(speed, deltaTime);
                    CalcSpeed(deltaTime, Vector2.zero);
                    Move(Speed * deltaTime);
                }
                else if (currStateInfo.IsTag("attack"))
                {
                    speed = CalcGravity(speed, deltaTime);

                    joystick = Vector2.zero;

                    CalcSpeed(deltaTime);
                    Move(Speed * deltaTime);
                }
                else if (currStateInfo.IsTag("jumping"))
                {
                    speed = CalcGravity(speed, deltaTime);

                    TurnBack();

                    CalcSpeed(deltaTime);


                    if (joystick.magnitude <= 0.1f)
                    {
                        speed.x = 0;
                        speed.z = 0;
                    }

                    Move(Speed * deltaTime);
                }
                else if (currStateInfo.IsTag("jumpingAttack"))
                {
                    speed = CalcGravity(speed, deltaTime);

                    joystick = Vector2.zero;

                    CalcSpeed(deltaTime);
                    Vector3 finalSpeed = Vector3.zero;
                    finalSpeed.x = Speed.x;
                    finalSpeed.y = Speed.y * currVariableSpeed;
                    finalSpeed.z = Speed.z;
                    Move(new Vector3(finalSpeed.x / 5f, finalSpeed.y, finalSpeed.z / 5f) * deltaTime);
                }
                else if (currStateInfo.IsTag("landing"))
                {
                    speed = CalcGravity(speed, deltaTime);

                    joystick = Vector2.zero;

                    CalcSpeed(deltaTime);
                    Move(Speed * deltaTime);
                }
                else if (currStateInfo.IsTag("nomove"))
                {
                    speed = CalcGravity(speed, deltaTime);

                    joystick = Vector2.zero;
                    Speed    = Vector3.zero;
                }
                else if (currStateInfo.IsTag("dun-idle") || currStateInfo.IsTag("dun-move"))
                {
                    speed = CalcGravity(speed, deltaTime);

                    CalcSpeed(deltaTime);
                    Move(Speed / 3f * deltaTime);
                }
                else if (currStateInfo.IsTag("nocontrol"))
                {
                    speed = CalcGravity(speed, deltaTime);

                    joystick = Vector2.zero;

                    CalcSpeed(deltaTime);
                    Move(Speed * deltaTime);
                }
                else if (currStateInfo.IsTag("climb"))
                {
                    speed = CalcGravity(speed, deltaTime);

                    //joystick = Vector2.zero;
                    speed.y = 0;
                    //calcSpeed(deltaTime);
                    //Move(Speed * deltaTime);
                }
                else if (currStateInfo.IsTag("ClimbLadder"))
                {
                    speed = CalcGravity(speed, deltaTime);

                    speed.y = 0;
                    if (joystick.y != 0f)
                    {
                        OverClimbLadder();
                    }
                }
                else
                {
                    speed = CalcGravity(speed, deltaTime);
                    CalcSpeed(deltaTime, Vector2.zero);
                    Move(Speed * deltaTime);
                }
//
//                if (currStateInfo.IsTag("walk") == false
//                    && currStateInfo.IsTag("run") == false)
//                {
//                    SetBackwards(Vector3.zero);
//                }
            }
            else if (eventType == AnimatorStateEventType.OnStateExit)
            {
                if (
                    currStateInfo.IsTag("walk") ||
                    currStateInfo.IsTag("run") ||
                    currStateInfo.IsTag("move")
                    // || currAnimatorStateInfo.IsTag("accelerateRoll")
                    )
                {
                    skeletonAnimator.SetBackwards(false);
                }

//                if (stateInfo.IsTag("roll")
//                    || stateInfo.IsTag("dodge"))
//                {
//                    speed.x = 0;
//                    speed.z = 0;
//                }
            }
        }