-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
Copy pathInputSystem.cs
35 lines (31 loc) · 964 Bytes
/
InputSystem.cs
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
using Unity.Burst;
using Unity.Entities;
using UnityEngine;
namespace HelloCube.StateChange
{
public partial struct InputSystem : ISystem
{
[BurstCompile]
public void OnCreate(ref SystemState state)
{
state.RequireForUpdate<Hit>();
state.RequireForUpdate<Config>();
state.RequireForUpdate<ExecuteStateChange>();
}
public void OnUpdate(ref SystemState state)
{
var hit = SystemAPI.GetSingletonRW<Hit>();
hit.ValueRW.HitChanged = false;
if (Camera.main == null || !Input.GetMouseButton(0))
{
return;
}
var ray = Camera.main.ScreenPointToRay(Input.mousePosition);
if (new Plane(Vector3.up, 0f).Raycast(ray, out var dist))
{
hit.ValueRW.HitChanged = true;
hit.ValueRW.Value = ray.GetPoint(dist);
}
}
}
}