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
This repository was archived by the owner on Aug 10, 2021. It is now read-only.

Commit e599bb9

Browse files
Add usage documentation and links
1 parent 32691f5 commit e599bb9

File tree

2 files changed

+87
-4
lines changed

2 files changed

+87
-4
lines changed

‎Assets/Documentation/README.md‎

Lines changed: 85 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,85 @@
1-
Documentation
1+
# Documentation
2+
3+
## Game Events
4+
The library provides two types of game events:
5+
- `GameEvent` without arguments.
6+
- `ArgumentGameEvent` which accept arguments.
7+
8+
### 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.
10+
11+
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):
12+
- `GameEvent` - _Right Click -> Create -> Game Events -> Game Event_
13+
- `ArgumentGameEvent` - _Right Click -> Create -> Game Events -> "Argument Name" Game Event_
14+
15+
Event assets can be referenced and raised in scripts directly or used in `UnityEvent` fields:
16+
```cs
17+
public class SceneManager : MonoBehaviour
18+
{
19+
// Reference GameEvent directly.
20+
[SerializedField]
21+
private GameEvent startSceneGameEvent = default;
22+
23+
// Or inside UnityEvent.
24+
[SerializedField]
25+
private UnityEvent onStartScene = default;
26+
27+
private void Start()
28+
{
29+
if (startSceneGameEvent != null)
30+
{
31+
startSceneGameEvent.RaiseGameEvent();
32+
}
33+
34+
onStartScene.Invoke();
35+
}
36+
}
37+
```
38+
39+
### Custom game events
40+
If you need to define a game event which accepts custom arguments, extend `GameEvents.Generic.ArgumentGameEvent` class:
41+
```cs
42+
[CreateAssetMenu(fileName = "CustomGameEvent", menuName = "Game Events/Custom Game Event")]
43+
public class CustomGameEvent : ArgumentGameEvent<Custom>
44+
{
45+
}
46+
```
47+
48+
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. To do so, define an editor script, extend `GameEvents.Generic.ArgumentGameEventEditor` and override `DrawArgumentField(Custom)` . Make sure to place this script under the `Editor` folder:
49+
```cs
50+
[CustomEditor(typeof(CustomGameEvent))]
51+
public class CustomGameEventEditor : ArgumentGameEventEditor<CustomGameEvent, Custom>
52+
{
53+
protected override Custom DrawArgumentField(Custom value)
54+
{
55+
// Draw Custom value input fields here.
56+
}
57+
}
58+
```
59+
60+
### Game event listeners
61+
Game events can be listened to by listener components. To use listeners, you need to create an appropriate listener component:
62+
- `GameEvent` - _Add Component -> Game Events -> Game Event Listener_
63+
- `ArgumentGameEvent` - _Add Component -> Game Events -> "Argument Name" Game Event Listener_
64+
65+
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.
66+
67+
### Custom game event listeners
68+
Custom game event listeners which accept different arguments can also be created. First of all, create a `UnityEvent` which would accept your `Custom` type:
69+
```cs
70+
[Serializable]
71+
public class CustomEvent : UnityEvent<Custom>
72+
{
73+
}
74+
```
75+
76+
Then, create a custom game event listener which. This can be done by extending `GameEvents.Generic.ArgumentGameEventListener` class.
77+
```cs
78+
[AddComponentMenu("Game Events/Custom Game Event Listener")]
79+
public class CustomGameEventListener : ArgumentGameEventListener<CustomGameEvent, CustomEvent, Custom>
80+
{
81+
}
82+
```
83+
84+
### Examples
85+
Import the `GameEvents` samples which show how to use game events in various situations.

‎README.md‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
# Unity Scriptable Objects
2-
Provides Game Events and their respective listeners. Includes Mutable Scriptable Objects for injecting and using shared data.
2+
This package provides utilities for implementing game architecture which is oriented around `ScriptableObject` assets and Game Events. For more info see [Unite2017](https://github.com/roboryantron/Unite2017).
33

44
## Installation
5-
<https://docs.unity3d.com/Packages/com.unity.package-manager-ui@2.0/manual/index.html>
6-
5+
This package can be installed by using the [Unity Package Manager](https://docs.unity3d.com/Packages/com.unity.package-manager-ui@2.0/manual/index.html). To install this package, add the following to `manifest.json`:
76
```json
87
{
98
"dependencies": {

0 commit comments

Comments
(0)

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