BITFALL/Assets/Artists/Scripts/Entity/Movement/EntityRootMotionController.cs

32 lines
1.2 KiB
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using BITKit;
using BITKit.Entities;
using UnityEngine.InputSystem;
namespace BITFALL.Entites
{
public class EntityRootMotionController : EntityInputComponent
{
[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);
}
public override void OnMovement(InputAction.CallbackContext context)
{
var moveDelta = context.ReadValue<Vector2>();
entity.Set<float>(_vertical, moveDelta.y);
entity.Set<float>(_horizontal, moveDelta.x);
entity.Set<float>(_sqrMagnitude,moveDelta.sqrMagnitude);
}
}
}