-
Notifications
You must be signed in to change notification settings - Fork 0
/
ColliderTestInputManager.cs
57 lines (47 loc) · 1.75 KB
/
ColliderTestInputManager.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
using Collider.Components;
using Unity.Entities;
using UnityEngine;
namespace Collider {
public class ColliderTestInputManager : MonoBehaviour {
[SerializeField] private Camera mainCamera;
private World _world;
private Entity _spawnRequestBuffer;
private void OnEnable() {
mainCamera = mainCamera == null ? Camera.main : mainCamera;
_world = World.DefaultGameObjectInjectionWorld;
if (_world.IsCreated) {
if (!_world.EntityManager.Exists(_spawnRequestBuffer)) {
_spawnRequestBuffer = _world.EntityManager.CreateSingletonBuffer<SpawnRequestComponentBuffer>();
}
}
}
private void OnDisable() {
if (_world.IsCreated) {
if (_world.EntityManager.Exists(_spawnRequestBuffer)) {
_world.EntityManager.DestroyEntity(_spawnRequestBuffer);
}
}
}
private void Update() {
int clickedButton = -1;
if (Input.GetMouseButtonDown(0)) {
clickedButton = 0;
}
if (Input.GetMouseButtonDown(1)) {
clickedButton = 1;
}
if (Input.GetMouseButtonDown(2)) {
clickedButton = 2;
}
if (clickedButton != -1) {
var ray = mainCamera.ScreenPointToRay(Input.mousePosition);
_world.EntityManager.GetBuffer<SpawnRequestComponentBuffer>(_spawnRequestBuffer)
.Add(new SpawnRequestComponentBuffer() {
MouseButton = clickedButton,
Ray = ray,
Distance = 15f
});
}
}
}
}