You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Aug 10, 2021. It is now read-only.
Copy file name to clipboardExpand all lines: Documentation/README.md
+54-8Lines changed: 54 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,12 +1,14 @@
1
1
# Documentation
2
2
3
3
## Game Events
4
-
The library provides two types of game events:
4
+
Game events allow to decouple prefabs from direct dependencies such as scene or nested prefab game objects. The biggest benefit of events is that they can be referenced in isolated prefabs, this allows to later avoid having to set them up in the scene.
5
+
6
+
The package provides two types of game events:
5
7
-`GameEvent` without arguments.
6
-
-`ArgumentGameEvent` which accepts arguments.
8
+
-`ArgumentGameEvent` which accepts arguments (includes default implementations for commonly used types).
7
9
8
10
### Game event assets
9
-
The core of events is game event `ScriptableObject` assets. They store game event listeners and notify them when an event is raised. To use game events, create an appropriate game event type asset (where _"Argument Name"_ is type of the argument that you are going to be passing to your events):
11
+
The core of events is game event `ScriptableObject` assets. They store game event listeners and notify them when an event is raised. To use game events, create an appropriate game event type asset (where _"Argument Name"_ is the type of the argument that will be to passed to events):
10
12
-`GameEvent` - _Right Click -> Create -> Game Events -> Game Event_
11
13
-`ArgumentGameEvent` - _Right Click -> Create -> Game Events -> "Argument Name" Game Event_
12
14
@@ -35,15 +37,15 @@ public class SceneManager : MonoBehaviour
35
37
```
36
38
37
39
### Custom game events
38
-
If you need to define a game event which accepts custom arguments, extend `GameEvents.Generic.ArgumentGameEvent` class:
40
+
To define a game event which accepts custom arguments, extend `GameEvents.Generic.ArgumentGameEvent`:
39
41
```cs
40
42
[CreateAssetMenu(fileName="CustomGameEvent", menuName="Game Events/Custom Game Event")]
In order to enable raising of custom game events from the inspector, create a `CustomEditor` script where the argument fields are going to be drawn. Extend `GameEvents.Generic.ArgumentGameEventEditor` and override `DrawArgumentField(Custom)`. Make sure to place this script under the `Editor` folder:
48
+
In order to enable raising of custom game events from the inspector, create a `CustomEditor` script and specify how the argument fields are going to be drawn. Extend `GameEvents.Generic.ArgumentGameEventEditor` and override `DrawArgumentField(Custom)`. Make sure to place this script under the `Editor` folder:
@@ -56,14 +58,14 @@ public class CustomGameEventEditor : ArgumentGameEventEditor<CustomGameEvent, Cu
56
58
```
57
59
58
60
### Game event listeners
59
-
Game events can be listened to by listener components. To use pre-made listeners, add an appropriate listener component:
61
+
Game events can be listened to by listener components. To use listeners, add an appropriate listener component via:
60
62
-`GameEvent` - _Add Component -> Game Events -> Game Event Listener_
61
63
-`ArgumentGameEvent` - _Add Component -> Game Events -> "Argument Name" Game Event Listener_
62
64
63
-
Once the component is added, slot in the appropriate `GameEvent`you want the listener to listen to and add your response methods to `onGameEvent` callback via the inspector.
65
+
Once the component is added, slot in the appropriate `GameEvent`asset to the listener and add insert response methods to `onGameEvent` callback via the inspector.
64
66
65
67
### Custom game event listeners
66
-
Custom game event listeners which accept different arguments can also be created. Create a `UnityEvent` which would accept your`Custom` type:
68
+
Custom game event listeners which accept different arguments can also be created. Create a `UnityEvent` which would accept the`Custom` type:
67
69
```cs
68
70
[Serializable]
69
71
publicclassCustomEvent : UnityEvent<Custom>
@@ -81,3 +83,47 @@ public class CustomGameEventListener : ArgumentGameEventListener<CustomGameEvent
81
83
82
84
### Examples
83
85
Import the `GameEvents` samples which show how to use game events in various situations.
86
+
87
+
## Mutable Objects
88
+
Mutable objects allow using `ScriptableObject` assets to store and share data. They are handy when a lot of behaviours need access to specific data. In such cases, mutable objects can be injected in dependant behaviours instead of forming hard dependencies between them or using singletons.
89
+
90
+
### Mutable object assets
91
+
The package provides mutable objects for most commonly used types such as `MutableInt`, `MutableFloat`, etc. Mutable object assets can be created by (where _"Value Name"_ is the type name of the contained value):
The core of events is game event `ScriptableObject` assets. They store game event listeners and notify them when an event is raised. To use game events, create an appropriate game event type asset (where _"Argument Name"_ is the type of the argument that will be to passed to events):
95
+
-`GameEvent` - _Right Click -> Create -> Game Events -> Game Event_
96
+
-`ArgumentGameEvent` - _Right Click -> Create -> Game Events -> "Argument Name" Game Event_
97
+
98
+
### Custom mutable objects
99
+
Using mutable objects for each individual field can be troublesome in cases where a lot of values need to be observed. In such a situation it is better to create a single mutable object to house those values by extending `MutableObject` and overriding `ResetValues()`:
// Set property values when mutable object is enabled or if the values change in the inspector.
120
+
publicoverridevoidResetValues()
121
+
{
122
+
Health=health;
123
+
Armor=armor;
124
+
Xp=xp;
125
+
}
126
+
}
127
+
```
128
+
129
+
After that is set up, make sure to call `MutableObjectExtensions.ResetMutatedObjects()` somewhere in one of the `Awake` methods, each time before a scene loads. Make sure the script which calls this extension executes before other scripts by setting up [Script Execution Order](https://docs.unity3d.com/Manual/class-MonoManager.html).
0 commit comments