Skip to content

Commit 040e4ce

Browse files
Updated documentation
1 parent e85316f commit 040e4ce

File tree

1 file changed

+86
-142
lines changed

1 file changed

+86
-142
lines changed

README.md

Lines changed: 86 additions & 142 deletions
Original file line numberDiff line numberDiff line change
@@ -58,231 +58,175 @@ It's recommended to build your entire project around these life cycle methods.
5858

5959
### Introduction
6060

61-
The [Controller](#controllers) is the heart of your Application, each Application should consist of just one, commonly named the MainController. The [Controller](#controllers) is the first entry point of the Entity Component System and is the place where all of your [Systems](#systems) and [Services](#services) are registered. Your [Controller](#controllers) should be attached to a Game Object in your scene and will be marked to not be destroyed when switching scenes.
61+
The `Controller` is the heart of your Application, each Application should consist of just one, commonly named the MainController. The `Controller` is the first entry point of the Entity Component System and is the place where all of your `System` and `Services` are registered. Your `Controller` should be attached to a `GameObject` in your scene and will automatically be marked to not be destroyed when switching scenes.
6262

6363
```csharp
64-
public class MainController : Controller { }
64+
public class MainController: Controller { }
6565
```
6666

67-
### Virtual On Initialize
67+
### Life Cycle Methods
6868

69-
The [Controller](#controllers) consists of an OnInitialize virtual method. This method can be overwritten and will be invoked during the very start of your Application. During this cycle properties with the Injected and Asset attribute are being assigned, it is important to invoke the Register method during this cycle since this is the only time in your Application you can register [Systems](#systems) and [Services](#services).
69+
#### On Initialize Life Cycle Method
7070

71-
```csharp
72-
public class MainController : Controller {
73-
public override void OnInitialize () {
74-
this.Register (
75-
typeof (MovementSystem),
76-
typeof (AudioService)
77-
);
78-
}
79-
}
80-
```
81-
82-
### Virtual On Initialized
83-
84-
The [Controller](#controllers) consists of an OnInitialized virtual method. This method can be overwritten and will be invoked when all [Systems](#systems) and [Services](#services) did initialize, and all the properties with the Injected and Asset attributes are assigned.
85-
86-
```csharp
87-
public class MainController : Controller {
88-
public override void OnInitialized () { }
89-
}
90-
```
91-
92-
### Virtual On Update
93-
94-
The [Controller](#controllers) consists of an OnUpdate virtual method. This method can be overwritten and will be invoked during the Update cycle. This cycle will run once every frame, the Controller's Update is invoked before the [System's](#systems) and [Service's](#services) update cycles.
95-
96-
```csharp
97-
public class MainController : Controller {
98-
public override void OnUpdate () { }
99-
}
100-
```
101-
102-
### Enabling Systems
103-
104-
To enable or disable [Systems](#systems), the [Controller](#controllers) contains of a method EnableSystem which allows [Systems](#systems) to stop their life cycle methods such as OnUpdate, OnPhysics, OnDrawGui and others. You can provide the [System's](#system) type using a generic. Systems are enabled by default.
71+
The `Controller` consists of a virtual `OnInitialize` method. This lifecycle method can be overwritten and will be invoked at the very start of your Application. During this cycle, properties with the `Injected` and `Asset` attributes are being assigned, and the `OnInitialize` method of each registered `System` and `Service` will be invoked as well.
10572

10673
```csharp
107-
public class MainController : Controller {
108-
public void SomeMethod () {
109-
this.SetSystemEnabled<MovementSystem> (true);
110-
this.SetSystemEnabled<InteractableSystem> (false);
111-
}
74+
public class MainController: Controller {
75+
public override void OnInitialize() { }
11276
}
11377
```
11478

115-
### Checking Whether Systems Are Enabled
79+
#### On Initialized Life Cycle Method
11680

117-
To check whether [Systems](#systems) are enable or disabled, the [Controller](#controllers) contains of a method IsSystemEnabled. Invoking the method will return a boolean informing if the [System](#systems) is enabled or not. You can provide the [System's](#system) type using a generic.
81+
The `Controller` consists of a virtual `OnInitialized` method. This lifecycle method can be overwritten and will be invoked after the `OnInitialize` method has been invoked. During this cycle, the `OnInitialized` method of each registered `System` and `Service` will be invoked as well.
11882

11983
```csharp
120-
public class MainController : Controller {
121-
public void SomeMethod () {
122-
if (this.IsSystemEnabled<MovementSystem> ()) { }
123-
}
84+
public class MainController: Controller {
85+
public override void OnInitialized() { }
12486
}
12587
```
12688

127-
### Injection
89+
#### On Update Life Cycle Method
12890

129-
The [Controller](#controllers) allows the use of the Injected attribute on properties to automatically assign the values of referenced [Systems](#Systems) and [Services](#Services), making all public methods and properties accessible. These properties are assigned during the OnInitialize cycle and are available for use at the OnInitialized cycle.
91+
The `Controller` consists of a virtual `OnUpdate` method. This lifecycle method can be overwritten and will be invoked every frame. During this cycle, the `OnUpdate` method of each registered `System` will be invoked as well.
13092

13193
```csharp
132-
public class MainController : Controller {
133-
[Injected] private MovementSystem movementSystem;
134-
[Injected] private AudioService audioService;
94+
public class MainController: Controller {
95+
public override void OnUpdate() { }
13596
}
13697
```
13798

138-
### Assets
99+
#### On Will Destroy Life Cycle Method
139100

140-
The [Controller](#controllers) allows the use of the Asset attribute on properties to automatically assign the values of referenced Assets. Assets can be assigned on the [Controller](#controllers) instance in your Scene. When assigning using the empty contructor, the property's name will be used for searching the Asset, to find an Asset by it's name, use the string overload. All types of UnityEngine's Object can be used in these fields. These properties are assigned during the OnInitialize cycle and are available for use at the OnInitialized cycle. When an asset is not found, an error is thrown.
101+
The `Controller` consists of a virtual `OnWillDestroy` method. This lifecycle method can be overwritten and will be invoked when the Application is about to quit. During this cycle, the `OnWillDestroy` method of each registered `System` and `Service` will be invoked as well.
141102

142103
```csharp
143-
public class MainController : Controller {
144-
[Asset] private GameObject playerPrefab;
145-
[Asset ("ShopDialog")] private NpcDialog npcDialog;
104+
public class MainController: Controller {
105+
public override void OnWillDestroy() { }
146106
}
147107
```
148108

149-
### Notes
150-
151-
While it is recommended to move as much logic into [Services](#services) and [Systems](#systems), it is possible to let your [Controller](#controllers) house any functionality. If you use the [Controller](#controllers) for this purpose, try to keep it down to only Application wide and core functionality.
152-
153-
## Components
154-
155-
### Introduction
156-
157-
[Components](#components) are responsible for housing the data of your entities, and should consist of nothing more than that. All properties should be public and will be accessible to all [Systems](#systems) and [Controllers](#controllers) since there is no need for privates. [Components](#components) should be added to your Entities (GameObjects) in the Scene, an Entity is not limited to one [Components](#components) and can hold as many as needed.
109+
### Methods
158110

159-
```csharp
160-
public class MovementComponent : EntityComponent<MovementComponent, MovementSystem> { }
161-
```
111+
#### Registering Systems and Services
162112

163-
### Public Properties
113+
Use this method to `Register` the Systems and Services that are required for your Application to function. The `Register` method accepts a list of `Type` arguments, each of these types should be a `System` or `Service` type.
164114

165-
Public properties are the heart of your [Components](#components), and are here to provide data for the [Systems](#systems) to use. Properties can be added to [Components](#components) like in any other class and can consist of any kind of type.
115+
Registering a `System` or `Service` can only be done once during the `Controller`'s `OnInitialize` life cycle method.
166116

167117
```csharp
168-
public class MovementComponent : EntityComponent<MovementComponent, MovementSystem> {
169-
public float speed;
170-
public Vector3 targetPosition;
171-
public int[] ids;
172-
public NpcDialog dialog;
118+
public class MainController: Controller {
119+
public override void OnInitialize() {
120+
Register(
121+
typeof(ExampleSystem),
122+
typeof(ExampleService)
123+
);
124+
}
173125
}
174126
```
175127

176-
## Systems
177-
178-
### Introduction
179-
180-
The [Systems](#systems) are responsible for controlling all of your Entity's [Components](#components) and are the closest you'll get of what you're used to when working with MonoBehaviours. The entire life cycles of your Entities are managed in here.
181-
182-
```csharp
183-
public class MovementSystem : EntitySystem<MovementSystem, MovementComponent> { }
184-
```
185-
186-
### Virtual On Initialize
128+
#### Disabling a System's Update Life Cycles
187129

188-
The [System](#systems) consists of an OnInitialize virtual method. This method can be overwritten and will be invoked during the very start of your Application. During this cycle properties with the Injected and Asset attribute are being assigned. This cycle can be used to create instances or pre-set properties. Keep in mind references to other [System](#systems) and [Services](#services) are yet to be assigned and are not available at this point.
130+
To enable or disable the life cycle of a `System` or `Service`, use the `SetSystemEnabled` methods. This method accepts a `Type` generic, and a `bool` value to enable or disable the life cycle of the `System` or `Service`.
189131

190132
```csharp
191-
public class MovementSystem : EntitySystem<MovementSystem, MovementComponent> {
192-
public override void OnInitialize () { }
133+
public class MainController: Controller {
134+
void SomeMethod() {
135+
SetSystemEnabled<ExampleSystem>(false);
136+
}
193137
}
194138
```
195139

196-
### Virtual On Initialized
140+
#### Checking whether a System's Update Life Cycles are Enabled
197141

198-
The [System](#systems) consists of an OnInitialized virtual method. This method can be overwritten and will be invoked when all [System](#systems) and [Services](#services) did initialize, and all the properties with the Injected and Asset attributes are assigned.
142+
To check whether the life cycle of a `System` or `Service` is enabled, use the `IsSystemEnabled` methods. This method accepts a `Type` generic, and returns a `bool` value indicating whether the life cycle of the `System` or `Service` is enabled.
199143

200144
```csharp
201-
public class MovementSystem : EntitySystem<MovementSystem, MovementComponent> {
202-
public override void OnInitialized () { }
145+
public class MainController: Controller {
146+
void SomeMethod() {
147+
if (IsSystemEnabled<ExampleSystem>()) { }
148+
}
203149
}
204150
```
205151

206-
### Virtual On Enabled
152+
#### Manually getting a reference to a System or Service
207153

208-
The [System](#systems) consists of an OnEnabled virtual method. This method can be overwritten and will be invoked when all [System](#systems) and [Services](#services) are initialized or when the [System](#systems) is enabled after being disabled.
154+
Something you might want to get a reference to a `System` or `Service` from within something outside of the Entity Component System. To do this, use the `GetSystem`, `GetService`, `HasSystem` and `HasService` methods respectively. These methods accept a `Type` generic, or a `Type` parameter and return the `System` or `Service` instance.
209155

210156
```csharp
211-
public class MovementSystem : EntitySystem<MovementSystem, MovementComponent> {
212-
public override void OnEnabled () { }
157+
public class MainController: Controller {
158+
void SomeMethod() {
159+
if (HasSystem<ExampleSystem>()) {
160+
var exampleSystem = GetSystem<ExampleSystem>();
161+
var exampleSystem = GetSystem(typeof(ExampleSystem));
162+
}
163+
if (HasService<ExampleService>()) {
164+
var exampleService = GetService<ExampleService>();
165+
var exampleService = GetService(typeof(ExampleService));
166+
}
167+
}
213168
}
214169
```
215170

216-
<!-- TODO OnEntityInitialzed, OnEntityEnabled, OnPhysics, ShouldUpdate, OnUpdate, OnRender, OnDrawGui, OnDrawGizmos, OnDisabled, OnEntityDisabled, OnEntityWillDestroy, OnWillDestroy -->
217-
218-
### Checking wether an Entity is enabled
171+
#### Manually getting Assets
219172

220-
To check whether Entities are enable or disabled, the [Component](#components) consists of a property isEnabled. Getting the value will return a boolean informing if the Entity is enabled or not.
173+
Something you might want to get a reference to an `Asset` from within something outside of the Entity Component System. To do this, use the `GetAsset` and `HasAsset` methods respectively. These methods accepts an optional `Type` generic and a `name` parameter and returns the `Type` or `Object`
221174

222175
```csharp
223-
public class MovementSystem : EntitySystem<MovementSystem, MovementComponent> {
224-
private void SomeMethod () {
225-
if (this.entity.isEnabled == true) { }
176+
public class MainController: Controller {
177+
void SomeMethod() {
178+
if (HasAsset<ExampleAsset>()) {
179+
var exampleAsset = GetAsset<ExampleAsset>("MyAssetName");
180+
var exampleAssetObject = GetAsset("MyAssetName");
181+
}
226182
}
227183
}
228184
```
229185

230-
### Dependency Injection
186+
### Attributes
231187

232-
The [System](#systems) allows the use of the Injected attribute on properties to automatically assign the values of referenced [Systems](#Systems), [Services](#Services) and [Controllers](#controllers), making all public methods and properties accessible. These properties are assigned during the OnInitialize cycle and are available for use at the OnInitialized cycle.
188+
#### Assets
189+
190+
The `Controller` allows the use of the `Asset` attribute on properties to automatically assign the values of referenced Assets. Assets can be assigned on the `Controller` instance in your Scene. When assigning using the empty contructor, the property's name will be used for searching the Asset, to find an Asset by its name, use the string overload. All types of UnityEngine's Object can be used in these fields. These properties are assigned during the OnInitialize cycle and are available for use at the OnInitialized cycle. When an asset is not found, an error is thrown.
233191

234192
```csharp
235-
public class MovementSystem : EntitySystem<MovementSystem, MovementComponent> {
236-
[Injected] private MainController mainController;
237-
[Injected] private HealthSystem healthSystem;
238-
[Injected] private AudioService audioService;
193+
public class MainController: Controller {
194+
[Asset] public ExampleAsset exampleAsset;
195+
[Asset("MyAssetName")] public ExampleAsset exampleAsset;
239196
}
240197
```
241198

242-
### Assets
199+
#### Injection
243200

244-
The [System](#system) allows the use of the Asset attribute on properties to automatically assign the values of referenced Assets. Assets can be assigned on the [Controller](#controllers) instance in your Scene. When assigning using the empty contructor, the property's name will be used for searching the Asset, to find an Asset by it's name, use the string overload. All types of UnityEngine's Object can be used in these fields. These properties are assigned during the OnInitialize cycle and are available for use at the OnInitialized cycle. When an asset is not found, an error is thrown.
201+
The `Controller` allows the use of the `Injected` attribute on properties to automatically assign the values of referenced Systems and Services, making all public methods and properties accessible. These properties are assigned during the OnInitialize cycle and are available for use at the OnInitialized cycle.
245202

246203
```csharp
247-
public class MovementSystem : EntitySystem<MovementSystem, MovementComponent> {
248-
[Asset] private GameObject playerPrefab;
249-
[Asset ("ShopDialog")] private NpcDialog npcDialog;
204+
public class MainController: Controller {
205+
[Injected] public ExampleSystem exampleSystem;
206+
[Injected] public ExampleService exampleService;
250207
}
251208
```
252209

253-
_The systems section of the documentation is in process!_
254-
255-
## Services
210+
## Components
256211

257212
### Introduction
258213

259-
```csharp
260-
public class AudioService : Service<AudioService> { }
261-
```
262-
263-
<!-- TODO OnInitialize, OnInitialized, OnDrawGui, OnDrawGizmos, OnWillDestroy -->
264-
265-
### Dependency Injection
266-
267-
The [Service](#services) allows the use of the Injected attribute on properties to automatically assign the values of referenced [Systems](#Systems), [Services](#Services) and [Controllers](#controllers), making all public methods and properties accessible. These properties are assigned during the OnInitialize cycle and are available for use at the OnInitialized cycle.
214+
`Components` are responsible for storing the data of your `entities` while `Systems` are responsible for manipulating that data. `Components` are added to your `entities` (`GameObjects`) in the `Scene`, an `Entity` is not limited to one `Component` and can hold as many as needed.
268215

269216
```csharp
270-
public class AudioService : Service<AudioService> {
271-
[Injected] private MainController mainController;
272-
[Injected] private MovementSystem movementSystem;
273-
[Injected] private NetworkService networkService;
274-
}
217+
public class MovementComponent : EntityComponent<MovementComponent, MovementSystem> { }
275218
```
276219

277-
### Assets
220+
#### Entity Data
278221

279-
The [Service](#services) allows the use of the Asset attribute on properties to automatically assign the values of referenced Assets. Assets can be assigned on the [Controller](#controllers) instance in your Scene. When assigning using the empty contructor, the property's name will be used for searching the Asset, to find an Asset by it's name, use the string overload. All types of UnityEngine's Object can be used in these fields. These properties are assigned during the OnInitialize cycle and are available for use at the OnInitialized cycle. When an asset is not found, an error is thrown.
222+
To provide `Systems` entity data, we'll use properties to store this. All properties should be public and will be accessible to all `Systems` and `Controllers` since there is no need for privates.
280223

281224
```csharp
282-
public class AudioService : Service<AudioService> {
283-
[Asset] private GameObject playerPrefab;
284-
[Asset ("ShopDialog")] private NpcDialog npcDialog;
225+
public class MovementComponent : EntityComponent<MovementComponent, MovementSystem> {
226+
public float speed;
227+
public Vector3 targetPosition;
228+
public int[] ids;
229+
public NpcDialog dialog;
230+
[HideInInspector] public bool isMoving;
285231
}
286232
```
287-
288-
_The services section of the documentation is in process!_

0 commit comments

Comments
 (0)