-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathComplexEventListenerBehaviour.cs
70 lines (53 loc) · 1.84 KB
/
ComplexEventListenerBehaviour.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
/***********************************************
Copyright © 2018 AltSalt Media, LLC.
All rights reserved.
https://www.altsalt.com / [email protected]
**********************************************/
using UnityEngine;
using Sirenix.OdinInspector;
using UnityEditor;
using UnityEngine.Serialization;
namespace AltSalt.Maestro
{
[ExecuteInEditMode]
public class ComplexEventListenerBehaviour : MonoBehaviour, ISkipRegistration
{
[SerializeField]
private ComplexEventReference _complexEventReference = new ComplexEventReference();
private ComplexEventReference complexEvent => _complexEventReference;
#if UNITY_EDITOR
[PropertySpace]
[Multiline]
public string DeveloperDescription = "";
#endif
[FormerlySerializedAs("_response")]
[FormerlySerializedAs("Response")]
[ValidateInput(nameof(IsPopulated))]
[SerializeField]
private ComplexPayloadGenericAction _action;
private ComplexPayloadGenericAction action => _action;
[FormerlySerializedAs("_doNotRecord"),SerializeField]
[InfoBox("Specifies whether this dependency should be recorded when the RegisterDependencies tool is used.")]
private bool _skipRegistration;
public bool skipRegistration => _skipRegistration;
private void OnEnable()
{
#if UNITY_EDITOR
_complexEventReference.PopulateVariable(this, nameof(_complexEventReference));
#endif
(complexEvent.GetVariable() as ComplexEvent).RegisterListener(this);
}
private void OnDisable()
{
(complexEvent.GetVariable() as ComplexEvent).UnregisterListener(this);
}
public void OnEventRaised(ComplexPayload complexPayload)
{
action.Invoke(complexPayload);
}
private static bool IsPopulated(ComplexPayloadGenericAction attribute)
{
return Utils.IsPopulated(attribute);
}
}
}