-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathEventVolume.cs
More file actions
53 lines (43 loc) · 1.61 KB
/
EventVolume.cs
File metadata and controls
53 lines (43 loc) · 1.61 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 System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;
#if UNITY_EDITOR
using UnityEditor;
#endif
namespace SubsurfaceStudios {
public sealed class EventVolume : MonoBehaviour {
public LayerMask m_PlayerLayerMask;
public UnityEvent m_OnPlayerEnter;
public UnityEvent m_OnPlayerExit;
public LayerMask m_ObjectLayerMask;
public UnityEvent m_OnObjectEnter;
public UnityEvent m_OnObjectExit;
void OnTriggerEnter(Collider other) {
if (((1 << other.gameObject.layer) & m_PlayerLayerMask.value) > 0) {
m_OnPlayerEnter.Invoke();
} else if (((1 << other.gameObject.layer) & m_ObjectLayerMask.value) > 0) {
m_OnObjectEnter.Invoke();
}
}
void OnTriggerExit(Collider other) {
if (((1 << other.gameObject.layer) & m_PlayerLayerMask.value) > 0) {
m_OnPlayerExit.Invoke();
} else if (((1 << other.gameObject.layer) & m_ObjectLayerMask.value) > 0) {
m_OnObjectExit.Invoke();
}
}
#if UNITY_EDITOR
[MenuItem("GameObject/3D Object/Event Volume", false, 10)]
static void CreateEventVolume(MenuCommand command) {
GameObject go = new("Event Volume");
GameObjectUtility.SetParentAndAlign(go, command.context as GameObject);
Undo.RegisterCreatedObjectUndo(go, $"Create {go.name}");
Selection.activeObject = go;
Collider c = go.AddComponent<BoxCollider>();
c.isTrigger = true;
go.AddComponent<EventVolume>();
}
#endif
}
}