@@ -26,35 +26,35 @@ public void Subscribe()
26
26
{
27
27
// Examples of how to subscribe to global and local events. We are
28
28
// subscribing to the event MyExampleEvent which will invoke
29
- // the function OnStandardEvent when the global or local event
29
+ // the function ListenerFunction when the global or local event
30
30
// is sent. Note that nothing prevents a function from subscribing
31
31
// multiple times.
32
32
33
33
// Global subscription
34
- EventManager . Subscribe < MyExampleEvent > ( OnStandardEvent ) ;
34
+ EventManager . Subscribe < MyExampleEvent > ( ListenerFunction ) ;
35
35
36
36
// Local subscription
37
- gameObject . Subscribe < MyExampleEvent > ( OnStandardEvent ) ;
37
+ gameObject . Subscribe < MyExampleEvent > ( ListenerFunction ) ;
38
38
}
39
39
40
40
public void Unsubscribe ( )
41
41
{
42
42
// Examples of how to unsubscribe to global and local events.
43
- // Specifically it will unsubscribe the function OnStandardEvent
43
+ // Specifically it will unsubscribe the function ListenerFunction
44
44
// from the event MyExampleEvent. Unsubscribing is safe to do
45
45
// even if the function isn't subscribed.
46
46
47
47
// Unsubscribe from global event.
48
- EventManager . Unsubscribe < MyExampleEvent > ( OnStandardEvent ) ;
48
+ EventManager . Unsubscribe < MyExampleEvent > ( ListenerFunction ) ;
49
49
50
50
// Unsubscribe from local event.
51
- gameObject . Unsubscribe < MyExampleEvent > ( OnStandardEvent ) ;
51
+ gameObject . Unsubscribe < MyExampleEvent > ( ListenerFunction ) ;
52
52
}
53
53
54
54
public void SendEvents ( )
55
55
{
56
56
// Examples of how to send the global and local events. If
57
- // subscribed it will invoke the function OnStandardEvent .
57
+ // subscribed it will invoke the function ListenerFunction .
58
58
59
59
// Send the global event.
60
60
EventManager . SendEvent ( new MyExampleEvent ( 54 , null , true ) ) ;
@@ -67,10 +67,10 @@ public void SendEvents()
67
67
gameObject . SendEventDeep ( new MyExampleEvent ( 8 , gameObject , false ) ) ;
68
68
}
69
69
70
- private void OnStandardEvent ( MyExampleEvent ev )
70
+ private void ListenerFunction ( MyExampleEvent ev )
71
71
{
72
72
Debug . LogFormat (
73
- "Standard Event Triggered : Integer: {0} GameObject: {1} Was Global Event?: {2}" ,
73
+ "ListenerFunction Invoked : Integer: {0} GameObject: {1} Was Global Event?: {2}" ,
74
74
ev . anIntProperty ,
75
75
ev . anObjectProperty == null ? "null" : ev . anObjectProperty . name ,
76
76
ev . wasGlobal ) ;
@@ -120,7 +120,7 @@ public void TerminableFunctions()
120
120
121
121
// Subscription
122
122
EventManager . SubscribeTerminable < MyExampleEvent > (
123
- OnStandardEventTerminable ) ;
123
+ ListenerFunctionTerminable ) ;
124
124
125
125
// Sending the event
126
126
if ( EventManager . SendEvent ( new MyExampleEvent ( 2 , null , true ) ) )
@@ -136,13 +136,13 @@ public void TerminableFunctions()
136
136
137
137
// Unsubscription
138
138
EventManager . UnsubscribeTerminable < MyExampleEvent > (
139
- OnStandardEventTerminable ) ;
139
+ ListenerFunctionTerminable ) ;
140
140
}
141
141
142
- private bool OnStandardEventTerminable ( MyExampleEvent ev )
142
+ private bool ListenerFunctionTerminable ( MyExampleEvent ev )
143
143
{
144
144
Debug . LogFormat (
145
- "Standard Event Triggered : Integer: {0} GameObject: {1} Was Global Event?: {2}" ,
145
+ "Listener Function Terminable Invoked : Integer: {0} GameObject: {1} Was Global Event?: {2}" ,
146
146
ev . anIntProperty ,
147
147
ev . anObjectProperty == null ? "null" : ev . anObjectProperty . name ,
148
148
ev . wasGlobal ) ;
@@ -182,6 +182,13 @@ public void HasSubscribers()
182
182
hasSubscribers = gameObject . HasSubscribers < MyExampleEvent > ( ) ;
183
183
}
184
184
185
+ public void UnsubscribeTarget ( )
186
+ {
187
+ // Unsubscribes all functions associated with the object passed in.
188
+ EventManager . UnsubscribeTarget ( this ) ;
189
+ gameObject . UnsubscribeTarget ( this ) ;
190
+ }
191
+
185
192
public void Initialization ( )
186
193
{
187
194
// Local event systems are initialized lazily so this isn't necessary
@@ -253,10 +260,10 @@ public void UseSubscriptionHandles()
253
260
254
261
// Global Events
255
262
SubscriptionHandle < MyExampleEvent > globalHandle =
256
- EventManager . GetSubscriptionHandle < MyExampleEvent > ( OnStandardEvent ) ;
263
+ EventManager . GetSubscriptionHandle < MyExampleEvent > ( ListenerFunction ) ;
257
264
258
265
SubscriptionHandle < MyExampleEvent > globalTerminableHandle =
259
- EventManager . GetSubscriptionHandleTerminable < MyExampleEvent > ( OnStandardEventTerminable ) ;
266
+ EventManager . GetSubscriptionHandleTerminable < MyExampleEvent > ( ListenerFunctionTerminable ) ;
260
267
261
268
globalHandle . Subscribe ( ) ;
262
269
globalTerminableHandle . Subscribe ( ) ;
@@ -268,10 +275,10 @@ public void UseSubscriptionHandles()
268
275
269
276
// Local Events
270
277
SubscriptionHandle < MyExampleEvent > localHandle =
271
- gameObject . GetSubscriptionHandle < MyExampleEvent > ( OnStandardEvent ) ;
278
+ gameObject . GetSubscriptionHandle < MyExampleEvent > ( ListenerFunction ) ;
272
279
273
280
SubscriptionHandle < MyExampleEvent > localTerminableHandle =
274
- gameObject . GetSubscriptionHandleTerminable < MyExampleEvent > ( OnStandardEventTerminable ) ;
281
+ gameObject . GetSubscriptionHandleTerminable < MyExampleEvent > ( ListenerFunctionTerminable ) ;
275
282
276
283
localHandle . Subscribe ( ) ;
277
284
localTerminableHandle . Subscribe ( ) ;
0 commit comments