105 lines
3.4 KiB
C#
105 lines
3.4 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.InputSystem;
|
|
|
|
namespace BITKit.Entities
|
|
{
|
|
[System.Serializable]
|
|
public struct ExpectState<T>
|
|
{
|
|
public T shouldBe;
|
|
public T being;
|
|
public T force;
|
|
public static implicit operator T(ExpectState<T> value)
|
|
{
|
|
return value.being;
|
|
}
|
|
public void Reset()
|
|
{
|
|
shouldBe = being = force = default;
|
|
}
|
|
public void Release()
|
|
{
|
|
being = shouldBe;
|
|
}
|
|
public void Release(T value)
|
|
{
|
|
force = default;
|
|
being = shouldBe = value;
|
|
}
|
|
}
|
|
public interface IEntityMovement
|
|
{
|
|
Vector3 Velocity { get; }
|
|
Vector3 GroundVelocity { get; }
|
|
bool IsGrounded { get; }
|
|
void SyncMovement(Vector3 velocity, Vector3 position,Quaternion rotation,bool isGrounded);
|
|
void Movement(Vector3 relativeVector);
|
|
void Movement(InputAction.CallbackContext context);
|
|
}
|
|
[System.Serializable]
|
|
public class MonoMovementProxy:IEntityMovement
|
|
{
|
|
[SerializeField] private MonoBehaviour monoBehaviour;
|
|
private IEntityMovement _entityMovementImplementation=>monoBehaviour as IEntityMovement;
|
|
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 class EntityMovement : EntityComponent, IEntityMovement
|
|
{
|
|
protected Vector2 relativeVector;
|
|
private Vector3 _velocity;
|
|
private bool _isGrounded;
|
|
public Vector3 Velocity { get;protected set; }
|
|
public Vector3 GroundVelocity { get;protected set; }
|
|
public bool IsGrounded { get;protected set; }
|
|
|
|
public void SyncMovement(Vector3 velocity, Vector3 position, Quaternion rotation, bool isGrounded)
|
|
{
|
|
}
|
|
public void Movement(Vector3 _relativeVector)
|
|
{
|
|
relativeVector = _relativeVector;
|
|
}
|
|
|
|
public void Movement(InputAction.CallbackContext context)
|
|
{
|
|
relativeVector = context.ReadValue<Vector2>();
|
|
}
|
|
}
|
|
|
|
public interface IMovementCallback { }
|
|
public record MovementCallback : IMovementCallback
|
|
{
|
|
public bool started;
|
|
public bool updated;
|
|
public bool canceled;
|
|
}
|
|
public record OnRunCallback : MovementCallback { }
|
|
public record OnClimbCallback : MovementCallback { }
|
|
|
|
public interface IMovementCancelAction { }
|
|
public record MovementCancelAction : IMovementCancelAction { }
|
|
public record CancelMovement : MovementCancelAction { }
|
|
public record CancelMovementAction : MovementCancelAction { }
|
|
public record CancelRunOrSprint : MovementCancelAction { }
|
|
} |