-
Notifications
You must be signed in to change notification settings - Fork 38
/
EventHandler.cs
107 lines (89 loc) · 2.85 KB
/
EventHandler.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
using UnityEngine;
namespace FMODUnity
{
public abstract class EventHandler : MonoBehaviour
{
public string CollisionTag = "";
protected virtual void Start()
{
HandleGameEvent(EmitterGameEvent.ObjectStart);
}
protected virtual void OnDestroy()
{
HandleGameEvent(EmitterGameEvent.ObjectDestroy);
}
private void OnEnable()
{
HandleGameEvent(EmitterGameEvent.ObjectEnable);
}
private void OnDisable()
{
HandleGameEvent(EmitterGameEvent.ObjectDisable);
}
#if UNITY_PHYSICS_EXIST
private void OnTriggerEnter(Collider other)
{
if (string.IsNullOrEmpty(CollisionTag) || other.CompareTag(CollisionTag) || (other.attachedRigidbody && other.attachedRigidbody.CompareTag(CollisionTag)))
{
HandleGameEvent(EmitterGameEvent.TriggerEnter);
}
}
private void OnTriggerExit(Collider other)
{
if (string.IsNullOrEmpty(CollisionTag) || other.CompareTag(CollisionTag) || (other.attachedRigidbody && other.attachedRigidbody.CompareTag(CollisionTag)))
{
HandleGameEvent(EmitterGameEvent.TriggerExit);
}
}
#endif
#if UNITY_PHYSICS2D_EXIST
private void OnTriggerEnter2D(Collider2D other)
{
if (string.IsNullOrEmpty(CollisionTag) || other.CompareTag(CollisionTag))
{
HandleGameEvent(EmitterGameEvent.TriggerEnter2D);
}
}
private void OnTriggerExit2D(Collider2D other)
{
if (string.IsNullOrEmpty(CollisionTag) || other.CompareTag(CollisionTag))
{
HandleGameEvent(EmitterGameEvent.TriggerExit2D);
}
}
#endif
private void OnCollisionEnter()
{
HandleGameEvent(EmitterGameEvent.CollisionEnter);
}
private void OnCollisionExit()
{
HandleGameEvent(EmitterGameEvent.CollisionExit);
}
private void OnCollisionEnter2D()
{
HandleGameEvent(EmitterGameEvent.CollisionEnter2D);
}
private void OnCollisionExit2D()
{
HandleGameEvent(EmitterGameEvent.CollisionExit2D);
}
private void OnMouseEnter()
{
HandleGameEvent(EmitterGameEvent.MouseEnter);
}
private void OnMouseExit()
{
HandleGameEvent(EmitterGameEvent.MouseExit);
}
private void OnMouseDown()
{
HandleGameEvent(EmitterGameEvent.MouseDown);
}
private void OnMouseUp()
{
HandleGameEvent(EmitterGameEvent.MouseUp);
}
protected abstract void HandleGameEvent(EmitterGameEvent gameEvent);
}
}