Skip to content

Commit 41fba53

Browse files
Stephen KimberlinStephen Kimberlin
authored andcommitted
tweaks to examples
1 parent 4ab5870 commit 41fba53

File tree

1 file changed

+24
-17
lines changed

1 file changed

+24
-17
lines changed

Assets/UnityEvents/Example/Examples.cs

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -26,35 +26,35 @@ public void Subscribe()
2626
{
2727
// Examples of how to subscribe to global and local events. We are
2828
// 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
3030
// is sent. Note that nothing prevents a function from subscribing
3131
// multiple times.
3232

3333
// Global subscription
34-
EventManager.Subscribe<MyExampleEvent>(OnStandardEvent);
34+
EventManager.Subscribe<MyExampleEvent>(ListenerFunction);
3535

3636
// Local subscription
37-
gameObject.Subscribe<MyExampleEvent>(OnStandardEvent);
37+
gameObject.Subscribe<MyExampleEvent>(ListenerFunction);
3838
}
3939

4040
public void Unsubscribe()
4141
{
4242
// 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
4444
// from the event MyExampleEvent. Unsubscribing is safe to do
4545
// even if the function isn't subscribed.
4646

4747
// Unsubscribe from global event.
48-
EventManager.Unsubscribe<MyExampleEvent>(OnStandardEvent);
48+
EventManager.Unsubscribe<MyExampleEvent>(ListenerFunction);
4949

5050
// Unsubscribe from local event.
51-
gameObject.Unsubscribe<MyExampleEvent>(OnStandardEvent);
51+
gameObject.Unsubscribe<MyExampleEvent>(ListenerFunction);
5252
}
5353

5454
public void SendEvents()
5555
{
5656
// 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.
5858

5959
// Send the global event.
6060
EventManager.SendEvent(new MyExampleEvent(54, null, true));
@@ -67,10 +67,10 @@ public void SendEvents()
6767
gameObject.SendEventDeep(new MyExampleEvent(8, gameObject, false));
6868
}
6969

70-
private void OnStandardEvent(MyExampleEvent ev)
70+
private void ListenerFunction(MyExampleEvent ev)
7171
{
7272
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}",
7474
ev.anIntProperty,
7575
ev.anObjectProperty == null ? "null" : ev.anObjectProperty.name,
7676
ev.wasGlobal);
@@ -120,7 +120,7 @@ public void TerminableFunctions()
120120

121121
// Subscription
122122
EventManager.SubscribeTerminable<MyExampleEvent>(
123-
OnStandardEventTerminable);
123+
ListenerFunctionTerminable);
124124

125125
// Sending the event
126126
if (EventManager.SendEvent(new MyExampleEvent(2, null, true)))
@@ -136,13 +136,13 @@ public void TerminableFunctions()
136136

137137
// Unsubscription
138138
EventManager.UnsubscribeTerminable<MyExampleEvent>(
139-
OnStandardEventTerminable);
139+
ListenerFunctionTerminable);
140140
}
141141

142-
private bool OnStandardEventTerminable(MyExampleEvent ev)
142+
private bool ListenerFunctionTerminable(MyExampleEvent ev)
143143
{
144144
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}",
146146
ev.anIntProperty,
147147
ev.anObjectProperty == null ? "null" : ev.anObjectProperty.name,
148148
ev.wasGlobal);
@@ -182,6 +182,13 @@ public void HasSubscribers()
182182
hasSubscribers = gameObject.HasSubscribers<MyExampleEvent>();
183183
}
184184

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+
185192
public void Initialization()
186193
{
187194
// Local event systems are initialized lazily so this isn't necessary
@@ -253,10 +260,10 @@ public void UseSubscriptionHandles()
253260

254261
// Global Events
255262
SubscriptionHandle<MyExampleEvent> globalHandle =
256-
EventManager.GetSubscriptionHandle<MyExampleEvent>(OnStandardEvent);
263+
EventManager.GetSubscriptionHandle<MyExampleEvent>(ListenerFunction);
257264

258265
SubscriptionHandle<MyExampleEvent> globalTerminableHandle =
259-
EventManager.GetSubscriptionHandleTerminable<MyExampleEvent>(OnStandardEventTerminable);
266+
EventManager.GetSubscriptionHandleTerminable<MyExampleEvent>(ListenerFunctionTerminable);
260267

261268
globalHandle.Subscribe();
262269
globalTerminableHandle.Subscribe();
@@ -268,10 +275,10 @@ public void UseSubscriptionHandles()
268275

269276
// Local Events
270277
SubscriptionHandle<MyExampleEvent> localHandle =
271-
gameObject.GetSubscriptionHandle<MyExampleEvent>(OnStandardEvent);
278+
gameObject.GetSubscriptionHandle<MyExampleEvent>(ListenerFunction);
272279

273280
SubscriptionHandle<MyExampleEvent> localTerminableHandle =
274-
gameObject.GetSubscriptionHandleTerminable<MyExampleEvent>(OnStandardEventTerminable);
281+
gameObject.GetSubscriptionHandleTerminable<MyExampleEvent>(ListenerFunctionTerminable);
275282

276283
localHandle.Subscribe();
277284
localTerminableHandle.Subscribe();

0 commit comments

Comments
 (0)