forked from Unity-Technologies/EntityComponentSystemSamples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlayerInputSystem.cs
More file actions
53 lines (47 loc) · 1.9 KB
/
Copy pathPlayerInputSystem.cs
File metadata and controls
53 lines (47 loc) · 1.9 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
51
52
53
using Unity.Entities;
using Unity.NetCode;
using UnityEngine;
using UnityEngine.InputSystem;
namespace KickBall
{
[UpdateInGroup(typeof(GhostInputSystemGroup))]
public partial struct PlayerInputSystem : ISystem
{
public void OnCreate(ref SystemState state)
{
var moveAction = InputSystem.actions.FindAction("Move");
moveAction.Enable();
}
public void OnUpdate(ref SystemState state)
{
var moveAction = InputSystem.actions.FindAction("Move");
var moveValue = moveAction.ReadValue<Vector2>();
// WithAll<GhostOwnerIsLocal> so that we only modify the input buffer of the local client, not other clients
// (it's possible and sometimes useful for clients to receive copies of each other's input buffers, but even in
// those cases we wouldn't want to modify the copies of other players' input buffers)
foreach (var input in SystemAPI.Query<RefRW<PlayerInput>>()
.WithAll<GhostOwnerIsLocal>())
{
input.ValueRW = default;
// var moveAction = InputSystem.actions.FindAction("Move");
// var moveValue = moveAction.ReadValue<Vector2>();
//
// Debug.Log(moveValue);
input.ValueRW.Horizontal = moveValue.x;
input.ValueRW.Vertical = moveValue.y;
var keyboard = Keyboard.current;
if (keyboard != null)
{
if (keyboard.spaceKey.wasPressedThisFrame)
{
input.ValueRW.KickBall.Set();
}
if (keyboard.enterKey.wasPressedThisFrame)
{
input.ValueRW.SpawnBall.Set();
}
}
}
}
}
}