using Entitas; using UnityEngine; using Game; public class MoveParam { public float MoveForce; public float MoveSpeedMax; public float AirSpeedMaxRate; public float JumpTimeMax; public float JumpTimeMin; public float JumpForce; public float FallForce; public float AirDrag; public float GroundDrag; public float Gravity; public bool NeedScale; } [Game] public class MoveComponent : IComponent { public Transform Transform; public Transform TransformViewMain; public Rigidbody Rigidbody; public MoveParam MoveParam; public Vector3 Position { get => Transform.position; set => Rigidbody.position = value; } public Vector3 Velocity { get => Rigidbody.velocity; set => Rigidbody.velocity = value; } public float JumpTimeNow; public bool IsRight = true; public bool IsGround = false; public bool IsGroundLogic = false; public bool IsAgainstWall = false; public bool IsCrashToWall = false; public bool IsFlowing = false; public bool IsWalk = false; public bool IsJumpCommand = false; public bool IsJumpPressed = false; public bool IsFreeTurn = true; public bool IsSlide = false; public bool IsSkillAble = true; public float MoveSpeedScale = 0f; //移动速度缩放 public float TempMoveForceScale = 0f; //移动力临时缩放 时间轴结束时重置 public EJumpState JumpState = EJumpState.InAir; public Vector3 GroundPosition = Vector3.zero; public Vector3 CrashWallPosition = Vector3.zero; public Vector3 CrashWallNormal = Vector3.zero; public Vector3 MoveDir = Vector3.zero; public EMovestepType StepType; public Vector3 StepValue; } namespace Game { public abstract partial class Util { public static void EntityTurn(GameEntity entity, bool isRight) { entity.move.IsRight = isRight; } public static void EntityMove(int entity, Vector3 direction) { var e = Util.GetEntity(entity); if (e == null) { return; } EntityTurn(e, direction.x > 0); e.move.IsWalk = true; e.move.MoveDir = direction; } public static void EntityStopMove(int entity) { var e = Util.GetEntity(entity); if (e == null) { return; } e.move.IsWalk = false; e.move.MoveDir = GameConst.NoneDir; } public static void EntitySetTempMoveForceScale(int entity, float scale) { var e = Util.GetEntity(entity); if (e == null) { return; } e.move.TempMoveForceScale = scale; } public static bool EntityInAir(int entity) { var e = Util.GetEntity(entity); if (e == null || !e.hasMove) { return false; } return !e.move.IsGround; } public static bool EntityIsWalk(int entity) { var e = Util.GetEntity(entity); if (e == null || !e.hasMove) { return false; } return e.move.IsWalk; } public static Vector3 EntityVelocity(int entity) { var e = Util.GetEntity(entity); if (e == null || !e.hasMove) { return Vector3.zero; } if (e.move.IsFlowing && e.hasHp) { return e.hp.LastDamageDir; } if (e.hasPause && e.pause.IsPause) { return e.pause.VelocityCache; } return e.move.Velocity; } public static void ClearMove(GameEntity entity) { EntityStopMove(entity.ID()); var move = entity.move; move.Velocity = Vector3.zero; move.IsAgainstWall = false; } } }