2023-06-08 14:09:50 +08:00
|
|
|
using System.Collections;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using UnityEngine;
|
|
|
|
using BITKit;
|
|
|
|
using BITKit.Entities;
|
|
|
|
using UnityEngine.InputSystem;
|
|
|
|
namespace BITFALL.Entites
|
|
|
|
{
|
2023-08-12 01:43:24 +08:00
|
|
|
public class EntityRootMotionController : EntityComponent
|
2023-06-08 14:09:50 +08:00
|
|
|
{
|
|
|
|
[SerializeReference, SubclassSelector] References _vertical;
|
|
|
|
[SerializeReference, SubclassSelector] References _horizontal;
|
|
|
|
[SerializeReference, SubclassSelector] References _sqrMagnitude;
|
|
|
|
public override void OnStart()
|
|
|
|
{
|
|
|
|
base.OnStart();
|
|
|
|
entity.AddListener<InputAction.CallbackContext>(nameof(OnMovement), OnMovement);
|
|
|
|
}
|
|
|
|
public override void OnDestroyComponent()
|
|
|
|
{
|
|
|
|
base.OnDestroyComponent();
|
|
|
|
entity.RemoveListener<InputAction.CallbackContext>(nameof(OnMovement), OnMovement);
|
|
|
|
}
|
2023-08-12 01:43:24 +08:00
|
|
|
public void OnMovement(InputAction.CallbackContext context)
|
2023-06-08 14:09:50 +08:00
|
|
|
{
|
|
|
|
var moveDelta = context.ReadValue<Vector2>();
|
|
|
|
entity.Set<float>(_vertical, moveDelta.y);
|
|
|
|
entity.Set<float>(_horizontal, moveDelta.x);
|
|
|
|
entity.Set<float>(_sqrMagnitude,moveDelta.sqrMagnitude);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|