using ProjectM.Simulation; using Unity.Entities; using Unity.Mathematics; using Unity.NetCode; namespace ProjectM.Client { /// /// Client-only twin-stick input gather. Samples the Input System once per frame (WASD / /// left-stick -> Move, right-stick -> Aim) and writes on the /// locally-owned player ghost (filtered to ). Runs in /// — NOT the prediction loop — so devices are read once per /// frame, never re-read during rollback. Implemented as a non-Burst /// because it reads the managed Input System. /// /// NOTE: the Input System device types are fully qualified rather than imported via /// using UnityEngine.InputSystem; on purpose — that namespace also defines a /// PlayerInput type which would collide with /// and make the Entities source generator bind RefRW<PlayerInput> to the managed /// class (a spurious CS8377 "must be unmanaged"). /// /// [UpdateInGroup(typeof(GhostInputSystemGroup))] [WorldSystemFilter(WorldSystemFilterFlags.ClientSimulation)] public partial struct PlayerInputGatherSystem : ISystem { public void OnCreate(ref SystemState state) { state.RequireForUpdate(); } public void OnUpdate(ref SystemState state) { float2 move = float2.zero; float2 aim = float2.zero; var keyboard = UnityEngine.InputSystem.Keyboard.current; if (keyboard != null) { if (keyboard.wKey.isPressed) move.y += 1f; if (keyboard.sKey.isPressed) move.y -= 1f; if (keyboard.dKey.isPressed) move.x += 1f; if (keyboard.aKey.isPressed) move.x -= 1f; } var gamepad = UnityEngine.InputSystem.Gamepad.current; if (gamepad != null) { float2 leftStick = gamepad.leftStick.ReadValue(); if (math.lengthsq(leftStick) > math.lengthsq(move)) move = leftStick; aim = gamepad.rightStick.ReadValue(); } // Right-stick deadzone: a resting stick yields zero Aim so PlayerAimSystem falls back to // the movement heading (controller-first directional aim). if (math.lengthsq(aim) < 0.04f) aim = float2.zero; foreach (var input in SystemAPI.Query>().WithAll()) { input.ValueRW.Move = move; input.ValueRW.Aim = aim; } } } }