2023-10-24 23:37:59 +08:00
|
|
|
using System;
|
|
|
|
using System.Collections;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using UnityEngine;
|
|
|
|
using UnityEngine.InputSystem;
|
|
|
|
|
|
|
|
namespace BITKit.Entities.Movement
|
|
|
|
{
|
2023-11-30 00:23:23 +08:00
|
|
|
[CustomType(typeof(IEntityMovement))]
|
2023-10-30 01:25:53 +08:00
|
|
|
public class RigidbodyBasedMovement : StateBasedBehavior<IEntityMovementState>,IEntityMovement
|
2023-10-24 23:37:59 +08:00
|
|
|
{
|
|
|
|
[SerializeField] private new Rigidbody rigidbody;
|
|
|
|
[SerializeField] private Animator animator;
|
2023-11-30 00:23:23 +08:00
|
|
|
[SerializeField] private bool allowRootMotion;
|
|
|
|
|
|
|
|
|
2023-10-24 23:37:59 +08:00
|
|
|
public Vector3 Position { get; set; }
|
|
|
|
public Quaternion Rotation { get; set; }
|
|
|
|
public Vector3 Forward { get; }
|
2023-11-30 00:23:23 +08:00
|
|
|
public Vector3 ViewForward { get; }
|
2023-10-24 23:37:59 +08:00
|
|
|
public Vector3 ViewCenter { get; }
|
2023-11-30 00:23:23 +08:00
|
|
|
public Vector3 FocusPoint { get; }
|
2023-10-24 23:37:59 +08:00
|
|
|
public Quaternion ViewRotation { get; }
|
|
|
|
public Vector3 LocomotionBasedVelocity { get; }
|
|
|
|
public Vector3 Velocity { get;private set; }
|
|
|
|
public Vector3 GroundVelocity { get; }
|
|
|
|
public Vector3 AngularVelocity { get; }
|
|
|
|
public bool IsGrounded { get; }
|
2023-10-25 17:26:42 +08:00
|
|
|
|
|
|
|
[Inject(true)]
|
|
|
|
private IHealth health;
|
|
|
|
|
|
|
|
|
2023-10-24 23:37:59 +08:00
|
|
|
public void SyncMovement(Vector3 velocity, Vector3 position, Quaternion rotation, bool isGrounded)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
public void Movement(Vector3 relativeVector)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
public void Movement(InputAction.CallbackContext context)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
public void ExecuteCommand<T>(T command = default)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
public event Action<object> OnCommand;
|
2023-10-25 17:26:42 +08:00
|
|
|
public override void OnAwake()
|
|
|
|
{
|
|
|
|
base.OnAwake();
|
|
|
|
if (health is not null)
|
|
|
|
{
|
|
|
|
health.OnSetAlive += OnSetAlive;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void OnSetAlive(bool obj)
|
|
|
|
{
|
|
|
|
rigidbody.isKinematic = !obj;
|
|
|
|
}
|
|
|
|
|
2023-10-24 23:37:59 +08:00
|
|
|
public override void OnFixedUpdate(float deltaTime)
|
|
|
|
{
|
|
|
|
rigidbody.MovePosition(rigidbody.position + Velocity * deltaTime
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void OnAnimatorMove()
|
|
|
|
{
|
2023-11-30 00:23:23 +08:00
|
|
|
if (allowRootMotion)
|
|
|
|
Velocity = animator.velocity;
|
2023-10-24 23:37:59 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|