public void SetBackwards(Vector3 offest) { if (gameObject.GetComponent <RoleBehaviorTree>() != null) { if (_currAnimatorStateInfo.IsTag("idle") || _currAnimatorStateInfo.IsTag("walk") || _currAnimatorStateInfo.IsTag("run")) { if (direction == Direction.Left) { if (offest.x > 0) { SkeletonAnimator.SetBackwards(true); } else { SkeletonAnimator.SetBackwards(false); } } else { if (offest.x < 0) { SkeletonAnimator.SetBackwards(true); } else { SkeletonAnimator.SetBackwards(false); } } } else { SkeletonAnimator.SetBackwards(false); } } }
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); } } }
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; // } } }