Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 7558d81

Browse files
renamed all field variables to camel case for consistency with existing names
1 parent 626b03a commit 7558d81

File tree

1 file changed

+16
-15
lines changed

1 file changed

+16
-15
lines changed

‎Assets/Patterns/3. Observer/Different events/DifferentEventAlternatives.cs

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using System.Collections.Generic;
44
using UnityEngine;
55
using UnityEngine.Events;
6+
using UnityEngine.Serialization;
67

78
namespace Observer.DifferentEvents
89
{
@@ -15,19 +16,19 @@ public class DifferentEventAlternatives : MonoBehaviour
1516

1617
//C# built-in EventHandler
1718
//Requires "using System;"
18-
public event EventHandler MyCoolEvent;
19+
public event EventHandler myCoolEvent;
1920
//With parameters
20-
public event EventHandler<MyName> MyCoolEventWithParameters;
21+
public event EventHandler<MyName> myCoolEventWithParameters;
2122

2223

2324
//C# built-in Action
2425
//If we have more parameters we can use Action. Compared with EventHandler, the parameters dont have to inherit from EventArgs
25-
public event Action<MyName, MyAge> MyCoolEventAction;
26+
public event Action<MyName, MyAge> myCoolEventAction;
2627

2728

2829
//Unity built-in UnityEvent
2930
//Requires that we are "using UnityEngine.Events;"
30-
public UnityEvent CoolUnityEvent = new UnityEvent();
31+
[FormerlySerializedAs("CoolUnityEvent")]public UnityEvent coolUnityEvent = new UnityEvent();
3132
//If you have parameters you have to create a new event class that inherits from UnityEvent<parameter1, parameter2, ...>
3233
public MyCustomUnityEvent coolCustomUnityEvent = new MyCustomUnityEvent();
3334
//There's also something called UnityAction
@@ -55,23 +56,23 @@ public class DifferentEventAlternatives : MonoBehaviour
5556
public delegate void MyEventHandlerEmpty();
5657

5758
//The event belonging to the custom delegate
58-
public event MyEventHandlerEmpty MyCoolCustomEvent;
59+
public event MyEventHandlerEmpty myCoolCustomEvent;
5960

6061

6162

6263
void Start()
6364
{
64-
MyCoolEvent += DisplayStuff;
65+
myCoolEvent += DisplayStuff;
6566

66-
MyCoolEventWithParameters += DisplayStuffCustomArgs;
67+
myCoolEventWithParameters += DisplayStuffCustomArgs;
6768

68-
MyCoolEventAction += DisplayStuffCustomParameters;
69+
myCoolEventAction += DisplayStuffCustomParameters;
6970

70-
CoolUnityEvent.AddListener(DisplayStuffEmpty);
71+
coolUnityEvent.AddListener(DisplayStuffEmpty);
7172

7273
coolCustomUnityEvent.AddListener(DisplayStuffCustomParameters);
7374

74-
MyCoolCustomEvent += DisplayStuffEmpty;
75+
myCoolCustomEvent += DisplayStuffEmpty;
7576

7677
myEventHandler += DisplayStuff;
7778
}
@@ -83,20 +84,20 @@ void Update()
8384
if (Input.GetKeyDown(KeyCode.Space))
8485
{
8586
//Built-in
86-
MyCoolEvent?.Invoke(this, null);
87+
myCoolEvent?.Invoke(this, null);
8788

88-
MyCoolEventWithParameters?.Invoke(this, new MyName("InsertFunnyName"));
89+
myCoolEventWithParameters?.Invoke(this, new MyName("InsertFunnyName"));
8990

90-
MyCoolEventAction?.Invoke(new MyName("InsertFunnyName"), new MyAge(5));
91+
myCoolEventAction?.Invoke(new MyName("InsertFunnyName"), new MyAge(5));
9192

92-
CoolUnityEvent?.Invoke();
93+
coolUnityEvent?.Invoke();
9394

9495
coolCustomUnityEvent?.Invoke(new MyName("InsertFunnyName"), new MyAge(5));
9596

9697
//Custom
9798
myEventHandler?.Invoke(this, null);
9899

99-
MyCoolCustomEvent?.Invoke();
100+
myCoolCustomEvent?.Invoke();
100101
}
101102
}
102103

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /