1
This commit is contained in:
@@ -1,132 +0,0 @@
|
||||
using System;
|
||||
using BITKit.Entities;
|
||||
using UnityEngine;
|
||||
using UnityEngine.AI;
|
||||
using UnityEngine.InputSystem;
|
||||
|
||||
namespace BITKit
|
||||
{
|
||||
public class NavAgentMovement: StateBasedBehavior<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; }
|
||||
public Vector3 Velocity { get; private set; }
|
||||
public Vector3 GroundVelocity { get; private set; }
|
||||
public Vector3 AngularVelocity { get; private set; }
|
||||
public bool IsGrounded { get; private set; }
|
||||
private bool isDead;
|
||||
private Vector3 recordPosition;
|
||||
private Quaternion recordRotation;
|
||||
private IEntityMovement _entityMovementImplementation;
|
||||
#endregion
|
||||
public override void OnUpdate(float deltaTime)
|
||||
{
|
||||
Velocity = agent.velocity;
|
||||
var _groundVelocity = Velocity;
|
||||
_groundVelocity.y = 0;
|
||||
GroundVelocity = _groundVelocity;
|
||||
IsGrounded = agent.isOnOffMeshLink is false;
|
||||
|
||||
UnityEntity.Set<bool>("IsMoving",Velocity.sqrMagnitude>=0.16f);
|
||||
UnityEntity.Set<float>("SqrMagnitude",Velocity.sqrMagnitude);
|
||||
|
||||
if (!isDead) return;
|
||||
|
||||
recordPosition = rigidbody.position;
|
||||
recordRotation = rigidbody.rotation * transform.rotation;
|
||||
}
|
||||
public void SyncMovement(Vector3 velocity, Vector3 position, Quaternion rotation, bool isGrounded)
|
||||
{
|
||||
|
||||
}
|
||||
public void Movement(Vector3 relativeVector)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public void Movement(InputAction.CallbackContext context)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public void ExecuteCommand<T>(T command)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public event Action<object> OnCommand;
|
||||
|
||||
public void OnSetAlive(bool alive)
|
||||
{
|
||||
switch (alive)
|
||||
{
|
||||
case false:
|
||||
isDead = true;
|
||||
break;
|
||||
case true when isDead:
|
||||
{
|
||||
var _transform = transform;
|
||||
_transform.position = new Vector3()
|
||||
{
|
||||
x=recordPosition.x,
|
||||
y=0,
|
||||
z=recordPosition.x,
|
||||
};
|
||||
rigidbody.position = recordPosition;
|
||||
|
||||
_transform.rotation *= recordRotation;
|
||||
|
||||
rigidbody.rotation = recordRotation;
|
||||
|
||||
isDead = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void OnSetHP(int hp)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c9f4b115cecfadd40b191dc35f29ef08
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Reference in New Issue
Block a user