1
This commit is contained in:
@@ -62,6 +62,14 @@ namespace BITKit.Entities
|
||||
/// </summary>
|
||||
public interface IEntityMovement:IStateMachine<IEntityMovementState>
|
||||
{
|
||||
/// <summary>
|
||||
/// 视角中心,通常是摄像机的位置
|
||||
/// </summary>
|
||||
Vector3 ViewCenter { get; }
|
||||
/// <summary>
|
||||
/// 视角旋转,通常是摄像机的旋转
|
||||
/// </summary>
|
||||
Quaternion ViewRotation { get; }
|
||||
/// <summary>
|
||||
/// 基于运动的速度,是相对于标准化移动速度的相对速度
|
||||
/// </summary>
|
||||
@@ -75,6 +83,10 @@ namespace BITKit.Entities
|
||||
/// </summary>
|
||||
Vector3 GroundVelocity { get; }
|
||||
/// <summary>
|
||||
/// 旋转速度
|
||||
/// </summary>
|
||||
Vector3 AngularVelocity { get; }
|
||||
/// <summary>
|
||||
/// 是否在地面上
|
||||
/// </summary>
|
||||
bool IsGrounded { get; }
|
||||
@@ -96,8 +108,16 @@ namespace BITKit.Entities
|
||||
/// </summary>
|
||||
/// <param name="context"></param>
|
||||
void Movement(InputAction.CallbackContext context);
|
||||
|
||||
/// <summary>
|
||||
/// 执行命令
|
||||
/// </summary>
|
||||
/// <param name="command"></param>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
void ExecuteCommand<T>(T command=default);
|
||||
/// <summary>
|
||||
/// 执行命令的回调
|
||||
/// </summary>
|
||||
event Action<object> OnCommand;
|
||||
}
|
||||
public interface IEntityMovementState:IState
|
||||
{
|
||||
@@ -107,80 +127,4 @@ namespace BITKit.Entities
|
||||
void AfterUpdateMovement(float deltaTime);
|
||||
void ExecuteCommand<T>(T command);
|
||||
}
|
||||
public interface IPlayerMovementCommand{}
|
||||
[Serializable]
|
||||
public class MonoMovementProxy:IEntityMovement
|
||||
{
|
||||
[SerializeField] private MonoBehaviour monoBehaviour;
|
||||
private IEntityMovement _entityMovementImplementation=>monoBehaviour as IEntityMovement;
|
||||
|
||||
public Vector3 LocomotionBasedVelocity=>_entityMovementImplementation.LocomotionBasedVelocity;
|
||||
public Vector3 Velocity => _entityMovementImplementation.Velocity;
|
||||
|
||||
public Vector3 GroundVelocity => _entityMovementImplementation.GroundVelocity;
|
||||
|
||||
public bool IsGrounded => _entityMovementImplementation.IsGrounded;
|
||||
|
||||
public void SyncMovement(Vector3 velocity, Vector3 position, Quaternion rotation, bool isGrounded)
|
||||
{
|
||||
_entityMovementImplementation.SyncMovement(velocity, position, rotation, isGrounded);
|
||||
}
|
||||
|
||||
public void Movement(Vector3 relativeVector)
|
||||
{
|
||||
_entityMovementImplementation.Movement(relativeVector);
|
||||
}
|
||||
|
||||
public void Movement(InputAction.CallbackContext context)
|
||||
{
|
||||
_entityMovementImplementation.Movement(context);
|
||||
}
|
||||
|
||||
public void ExecuteCommand<T>(T command)=>_entityMovementImplementation.ExecuteCommand(command);
|
||||
|
||||
public bool Enabled
|
||||
{
|
||||
get => _entityMovementImplementation.Enabled;
|
||||
set => _entityMovementImplementation.Enabled = value;
|
||||
}
|
||||
|
||||
public IEntityMovementState CurrentState
|
||||
{
|
||||
get => _entityMovementImplementation.CurrentState;
|
||||
set => _entityMovementImplementation.CurrentState = value;
|
||||
}
|
||||
|
||||
public event Action<IEntityMovementState, IEntityMovementState> OnStateChanged
|
||||
{
|
||||
add => _entityMovementImplementation.OnStateChanged += value;
|
||||
remove => _entityMovementImplementation.OnStateChanged -= value;
|
||||
}
|
||||
|
||||
public IDictionary<Type, IEntityMovementState> StateDictionary => _entityMovementImplementation.StateDictionary;
|
||||
|
||||
public void Initialize()
|
||||
{
|
||||
_entityMovementImplementation.Initialize();
|
||||
}
|
||||
|
||||
public void UpdateState(float deltaTime)
|
||||
{
|
||||
_entityMovementImplementation.UpdateState(deltaTime);
|
||||
}
|
||||
|
||||
public void DisposeState()
|
||||
{
|
||||
_entityMovementImplementation.DisposeState();
|
||||
}
|
||||
|
||||
public void TransitionState<State>() where State : IEntityMovementState
|
||||
{
|
||||
_entityMovementImplementation.TransitionState<State>();
|
||||
}
|
||||
|
||||
public void TransitionState(IEntityMovementState state)
|
||||
{
|
||||
_entityMovementImplementation.TransitionState(state);
|
||||
}
|
||||
}
|
||||
}
|
@@ -14,9 +14,12 @@ namespace BITKit
|
||||
#endregion
|
||||
#region 接口实现
|
||||
|
||||
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;
|
||||
@@ -55,6 +58,8 @@ namespace BITKit
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public event Action<object> OnCommand;
|
||||
|
||||
public void OnSetAlive(bool alive)
|
||||
{
|
||||
switch (alive)
|
||||
|
@@ -90,9 +90,6 @@ namespace BITKit.Entities
|
||||
{
|
||||
OnSetAliveInternal(IsAlive = _isAlive);
|
||||
}
|
||||
|
||||
//entity.Invoke<int>(_onSetHP, newHP);
|
||||
//entity.Set<int>("HP", newHP);
|
||||
foreach (var x in entity.GetCallbacks<IHealthCallback>())
|
||||
{
|
||||
x.OnSetHP(newHP);
|
||||
@@ -108,20 +105,17 @@ namespace BITKit.Entities
|
||||
|
||||
private void OnSetAliveInternal(bool alive)
|
||||
{
|
||||
IsAlive = alive;
|
||||
foreach (var x in entity.GetCallbacks<IHealthCallback>())
|
||||
{
|
||||
x.OnSetAlive(alive);
|
||||
}
|
||||
|
||||
foreach (var x in additiveCallback)
|
||||
{
|
||||
x.OnSetAlive(alive);
|
||||
}
|
||||
|
||||
//entity.Invoke<bool>(_onSetAlive, alive);
|
||||
//entity.Set<bool>(_isAlive, alive);
|
||||
onSetAlive.Invoke(alive);
|
||||
OnSetAlive?.Invoke(alive);
|
||||
onSetAlive.Invoke(alive);
|
||||
}
|
||||
|
||||
private void AddHP(int hp)
|
||||
|
@@ -68,7 +68,7 @@ namespace BITKit.Entities.Player
|
||||
}
|
||||
public void Interactive(InputAction.CallbackContext context)
|
||||
{
|
||||
if (context.interaction is not TapInteraction || !context.performed) return;
|
||||
if (context.interaction is not PressInteraction || !context.performed) return;
|
||||
var _selected = selected;
|
||||
if (_selected is not MonoBehaviour monoBehaviour) return;
|
||||
if (monoBehaviour.TryGetComponentAny<IAction>(out var action))
|
||||
|
Reference in New Issue
Block a user