Skip to content

Instantly share code, notes, and snippets.

@InukVT
Last active February 12, 2021 15:25
Show Gist options
  • Select an option

  • Save InukVT/2d59036cb58634c79b70ebdf58695c41 to your computer and use it in GitHub Desktop.

Select an option

Save InukVT/2d59036cb58634c79b70ebdf58695c41 to your computer and use it in GitHub Desktop.
#nullable enable
#region Usings
using Unity.Burst;
using Unity.Collections;
using Unity.Entities;
using Unity.Jobs;
using Unity.Mathematics;
using Unity.Transforms;
using UnityEngine.InputSystem;
#endregion
public class InputHandler : SystemBase
{
private PlayerInput input = new PlayerInput();
private Movement? movement;
#region Handle Input
protected override void OnCreate()
{
UnityEngine.Debug.Log("Test create");
input.Player.Move.performed += Move;
input.Player.Move.canceled += StopMovement;
}
protected override void OnStartRunning()
=> input.Enable();
protected override void OnUpdate()
{
var deltaTime = Time.DeltaTime;
var moveVector = movement ?? Movement.zero;
Entities
.WithAll<PlayerControllable>()
.ForEach((ref Movement move) => {
move = moveVector;
}).Run();
}
#endregion
#region Controls
private void Move(InputAction.CallbackContext context)
=> movement = context.ReadValue<UnityEngine.Vector2>();
private void StopMovement(InputAction.CallbackContext context)
=> movement = null;
#endregion
}
using Unity.Burst;
using Unity.Collections;
using Unity.Entities;
using Unity.Jobs;
using Unity.Mathematics;
using Unity.Transforms;
public class MovementHandling : SystemBase
{
protected override void OnUpdate()
{
float deltaTime = Time.DeltaTime;
Entities.ForEach((ref Translation translation, in Movement movement) => {
translation.Value += movement * deltaTime;
}).Schedule();
}
}
using Unity.Burst;
using Unity.Collections;
using Unity.Entities;
using Unity.Jobs;
using Unity.Mathematics;
using Unity.Transforms;
public class MovementHandling : SystemBase
{
protected override void OnUpdate()
{
float deltaTime = Time.DeltaTime;
Entities.ForEach((ref Translation translation, in Movement movement) => {
translation.Value += movement * deltaTime;
}).Schedule();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment