-
Notifications
You must be signed in to change notification settings - Fork 0
/
SimpleSignalListener.cs
95 lines (78 loc) · 2.59 KB
/
SimpleSignalListener.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
using UnityEngine;
using System.Linq;
namespace AltSalt.Maestro
{
[ExecuteInEditMode]
public class SimpleSignalListener : ISimpleSignalListener
{
public delegate void TargetSignalExecutedHandler();
private event TargetSignalExecutedHandler _targetEventExecuted = () => { };
public event TargetSignalExecutedHandler targetEventExecuted
{
add
{
if (_targetEventExecuted == null
|| _targetEventExecuted.GetInvocationList().Contains(value) == false) {
_targetEventExecuted += value;
}
}
remove => _targetEventExecuted -= value;
}
private SimpleSignal _targetSignal;
private SimpleSignal targetSignal
{
get => _targetSignal;
set => _targetSignal = value;
}
private GameObject _parentGameObject;
private GameObject parentGameObject
{
get => _parentGameObject;
set => _parentGameObject = value;
}
private UnityEngine.Object _parentObject;
public UnityEngine.Object parentObject
{
get
{
if(parentGameObject != null) {
return parentGameObject;
}
return parentObject;
}
private set => _parentObject = value;
}
private string _sceneName;
public string sceneName
{
get => _sceneName;
private set => _sceneName = value;
}
public SimpleSignalListener(SimpleSignal signalToRegister, GameObject parentObject)
{
this.targetSignal = signalToRegister;
this.parentGameObject = parentObject;
this.sceneName = parentObject.scene.name;
this.targetSignal.RegisterListener(this);
}
public SimpleSignalListener(SimpleSignal signalToRegister, UnityEngine.Object parentObject, string sceneName)
{
this.targetSignal = signalToRegister;
this.parentObject = parentObject;
this.sceneName = sceneName;
this.targetSignal.RegisterListener(this);
}
public void OnEventRaised()
{
_targetEventExecuted.Invoke();
}
public void DestroyListener()
{
targetSignal.UnregisterListener(this);
}
public void LogName(string callingInfo)
{
Debug.Log(callingInfo + parentObject, parentObject);
}
}
}