1
This commit is contained in:
@@ -62,6 +62,9 @@ namespace BITKit.Entities
|
||||
/// </summary>
|
||||
public interface IEntityMovement:IStateMachine<IEntityMovementState>
|
||||
{
|
||||
Vector3 Position { get; set; }
|
||||
Quaternion Rotation { get; set; }
|
||||
Vector3 Forward { get; }
|
||||
/// <summary>
|
||||
/// 视角中心,通常是摄像机的位置
|
||||
/// </summary>
|
||||
|
@@ -6,14 +6,47 @@ using UnityEngine.InputSystem;
|
||||
|
||||
namespace BITKit
|
||||
{
|
||||
public class NavAgentMovement: StateBasedComponent<IEntityMovementState>,IEntityMovement,IHealthCallback
|
||||
public class NavAgentMovement: StateBasedComponent<IEntityMovementState>,IEntityMovement
|
||||
{
|
||||
#region 属性
|
||||
[SerializeField] private NavMeshAgent agent;
|
||||
[SerializeField] private new Rigidbody rigidbody;
|
||||
|
||||
[Inject] private IHealth _health;
|
||||
|
||||
[Inject(true)] private IEntityOverride _override;
|
||||
#endregion
|
||||
|
||||
public override void OnStart()
|
||||
{
|
||||
if (_override is not null)
|
||||
{
|
||||
_override.OnOverride += (x) =>
|
||||
{
|
||||
agent.isStopped = x;
|
||||
};
|
||||
}
|
||||
|
||||
_health.OnSetAlive += OnSetAlive;
|
||||
_health.OnSetHealthPoint += OnSetHP;
|
||||
|
||||
}
|
||||
|
||||
#region 接口实现
|
||||
|
||||
public Vector3 Position
|
||||
{
|
||||
get=>transform.position;
|
||||
set=>transform.position=value;
|
||||
}
|
||||
|
||||
public Quaternion Rotation
|
||||
{
|
||||
get=>transform.rotation;
|
||||
set=>transform.rotation=value;
|
||||
}
|
||||
|
||||
public Vector3 Forward => transform.forward;
|
||||
public Vector3 ViewCenter { get; set; }
|
||||
public Quaternion ViewRotation { get; set; }
|
||||
public Vector3 LocomotionBasedVelocity { get; private set; }
|
||||
@@ -34,6 +67,9 @@ namespace BITKit
|
||||
GroundVelocity = _groundVelocity;
|
||||
IsGrounded = agent.isOnOffMeshLink is false;
|
||||
|
||||
entity.Set<bool>("IsMoving",Velocity.sqrMagnitude>=0.16f);
|
||||
entity.Set<float>("SqrMagnitude",Velocity.sqrMagnitude);
|
||||
|
||||
if (!isDead) return;
|
||||
|
||||
recordPosition = rigidbody.position;
|
||||
|
@@ -0,0 +1,52 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.InputSystem;
|
||||
|
||||
namespace BITKit.Entities.Movement
|
||||
{
|
||||
public class RigidbodyBasedMovement : StateBasedComponent<IEntityMovementState>,IEntityMovement
|
||||
{
|
||||
[SerializeField] private new Rigidbody rigidbody;
|
||||
[SerializeField] private Animator animator;
|
||||
public Vector3 Position { get; set; }
|
||||
public Quaternion Rotation { get; set; }
|
||||
public Vector3 Forward { get; }
|
||||
public Vector3 ViewCenter { get; }
|
||||
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; }
|
||||
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;
|
||||
public override void OnFixedUpdate(float deltaTime)
|
||||
{
|
||||
rigidbody.MovePosition(rigidbody.position + Velocity * deltaTime
|
||||
);
|
||||
}
|
||||
|
||||
private void OnAnimatorMove()
|
||||
{
|
||||
Velocity = animator.velocity;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9db04e8e30068ef40b2afa725bdc239d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Reference in New Issue
Block a user