forked from Unity-Technologies/EntityComponentSystemSamples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInputSystem.cs
More file actions
36 lines (33 loc) · 1.08 KB
/
Copy pathInputSystem.cs
File metadata and controls
36 lines (33 loc) · 1.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
using Unity.Burst;
using Unity.Entities;
using UnityEngine;
namespace Miscellaneous.FirstPersonController
{
public partial struct InputSystem : ISystem
{
[BurstCompile]
public void OnCreate(ref SystemState state)
{
state.EntityManager.CreateSingleton<InputState>();
state.RequireForUpdate<Execute.FirstPersonController>();
}
[BurstCompile]
public void OnUpdate(ref SystemState state)
{
ref var inputState = ref SystemAPI.GetSingletonRW<InputState>().ValueRW;
inputState.Horizontal = Input.GetAxisRaw("Horizontal");
inputState.Vertical = Input.GetAxisRaw("Vertical");
inputState.MouseX = Input.GetAxisRaw("Mouse X");
inputState.MouseY = Input.GetAxisRaw("Mouse Y");
inputState.Space = Input.GetKeyDown(KeyCode.Space);
}
}
public struct InputState : IComponentData
{
public float Horizontal;
public float Vertical;
public float MouseX;
public float MouseY;
public bool Space;
}
}