forked from Unity-Technologies/EntityComponentSystemSamples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCubeInputAuthoring.cs
More file actions
50 lines (46 loc) · 1.57 KB
/
Copy pathCubeInputAuthoring.cs
File metadata and controls
50 lines (46 loc) · 1.57 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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
using Unity.Burst;
using Unity.Entities;
using Unity.NetCode;
using Unity.NetCode.Samples.Common;
using UnityEngine;
public struct CubeInput : IInputComponentData
{
public int Horizontal;
public int Vertical;
}
[DisallowMultipleComponent]
public class CubeInputAuthoring : MonoBehaviour
{
class CubeInputBaking : Unity.Entities.Baker<CubeInputAuthoring>
{
public override void Bake(CubeInputAuthoring authoring)
{
var entity = GetEntity(TransformUsageFlags.Dynamic);
AddComponent<CubeInput>(entity);
}
}
}
[UpdateInGroup(typeof(GhostInputSystemGroup))]
public partial struct SampleCubeInput : ISystem
{
public void OnCreate(ref SystemState state)
{
state.RequireForUpdate<NetworkStreamInGame>();
state.RequireForUpdate<NetCubeSpawner>();
}
public void OnUpdate(ref SystemState state)
{
foreach (var playerInput in SystemAPI.Query<RefRW<CubeInput>>().WithAll<GhostOwnerIsLocal>())
{
playerInput.ValueRW = default;
if (Input.GetKey("left") || TouchInput.GetKey(TouchInput.KeyCode.Left))
playerInput.ValueRW.Horizontal -= 1;
if (Input.GetKey("right") || TouchInput.GetKey(TouchInput.KeyCode.Right))
playerInput.ValueRW.Horizontal += 1;
if (Input.GetKey("down") || TouchInput.GetKey(TouchInput.KeyCode.Down))
playerInput.ValueRW.Vertical -= 1;
if (Input.GetKey("up") || TouchInput.GetKey(TouchInput.KeyCode.Up))
playerInput.ValueRW.Vertical += 1;
}
}
}