Last active
February 12, 2021 15:25
-
-
Save InukVT/2d59036cb58634c79b70ebdf58695c41 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #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 | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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(); | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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