85 lines
1.8 KiB
C#
85 lines
1.8 KiB
C#
|
using System.Collections;
|
||
|
using System.Collections.Generic;
|
||
|
using BITKit.Entities;
|
||
|
using UnityEngine;
|
||
|
using UnityEngine.AI;
|
||
|
using UnityEngine.InputSystem;
|
||
|
|
||
|
namespace BITKit
|
||
|
{
|
||
|
public class NavAgentMovement : EntityComponent,IEntityMovement,IHealthCallback
|
||
|
{
|
||
|
#region 属性
|
||
|
|
||
|
[SerializeField] private NavMeshAgent agent;
|
||
|
[SerializeField] private new Rigidbody rigidbody;
|
||
|
#endregion
|
||
|
#region 接口实现
|
||
|
public Vector3 Velocity { get; private set; }
|
||
|
public Vector3 GroundVelocity { get; private set; }
|
||
|
public bool IsGrounded { get; private set; }
|
||
|
private bool isDead;
|
||
|
private Vector3 recordPosition;
|
||
|
private Quaternion recordRotation;
|
||
|
#endregion
|
||
|
public override void OnUpdate(float deltaTime)
|
||
|
{
|
||
|
Velocity = agent.velocity;
|
||
|
var _groundVelocity = Velocity;
|
||
|
_groundVelocity.y = 0;
|
||
|
GroundVelocity = _groundVelocity;
|
||
|
IsGrounded = agent.isOnOffMeshLink is false;
|
||
|
|
||
|
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 System.NotImplementedException();
|
||
|
}
|
||
|
|
||
|
public void OnSetAlive(bool alive)
|
||
|
{
|
||
|
switch (alive)
|
||
|
{
|
||
|
case false:
|
||
|
isDead = true;
|
||
|
break;
|
||
|
case true when isDead:
|
||
|
{
|
||
|
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)
|
||
|
{
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|