using System.Collections; using System.Collections.Generic; using UnityEngine; namespace Rigging.Data { public class StandingDataHandler : RiggingDataBase { public float sinceGrounded; // 离地时间 public float sinceLanded; public bool isGrounded; public float distanceToGround = 1f; private bool hasRecievedTouchedGround; private MovementDataHandler movementData; protected override void OnStart() { movementData = player.status.movementData; } // 每帧都重置和刷新状态,而不是持续的维护bool值(容易出异常) protected override void OnFixedUpdate() { sinceGrounded += Time.fixedDeltaTime;// sinceLanded += Time.fixedDeltaTime;// if ((double)sinceGrounded > 0.1) { isGrounded = false;// } } protected override void OnLateUpdate() { hasRecievedTouchedGround = false;// } // 每帧都会检测和刷新状态,而不是维护bool值 public void TouchGround(float distance, Vector3 normal) { //if (sinceGrounded > 0.5f && (bool)wobbleShake) //{ // wobbleShake.AddShake(-Vector3.up * 5f * Mathf.Pow(sinceGrounded, 1.5f), 0.8f); //} if (sinceGrounded > 0.5f) { Land(sinceGrounded); } sinceGrounded = 0f; isGrounded = true; if (distance > distanceToGround || !hasRecievedTouchedGround) { distanceToGround = distance; } hasRecievedTouchedGround = true; //moveMentData.SetSlope(normal); } private void Land(float landForce) { sinceLanded = 0f; } } }