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
Copy file name to clipboardExpand all lines: README.md
+48-4Lines changed: 48 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -60,26 +60,70 @@ It's recommended to build your entire project around these life cycle methods.
60
60
61
61
**Introduction:** The controller is the core of your application, it is of such importance that each application should only contain one of it. The controller is where your application will start from and all systems and services are registered. This can only be done during the OnInitialize method using the controller's Register method. To get started with your first controller you can use the generator, for the controller to work it should be assined to a game object in your scene.
62
62
63
+
```csharp
64
+
publicclassMainController : Controller { }
65
+
```
66
+
67
+
**Virtual OnInitialize:** The controller 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 none [injectables](#Injectables) or [assets](#Assets) 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).
68
+
63
69
```csharp
64
70
publicclassMainController : Controller {
65
71
publicoverridevoidOnInitialize () {
66
72
this.Register (
67
-
typeof (EnemyMovementSystem),
73
+
typeof (MovementSystem),
68
74
typeof (AudioService)
69
75
);
70
76
}
71
77
}
72
78
```
73
79
74
-
**Virtual OnInitialized:** The controller consists of a OnInitialized virtual method. This method can be overwritten and will be invoked during the very first start of your application. 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).
80
+
**Virtual OnInitialized:** The controller 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 [injectables](#Injectables) and [assets](#Assets) properties are assigned.
81
+
82
+
```csharp
83
+
publicclassMainController : Controller {
84
+
publicoverridevoidOnInitialized () { }
85
+
}
86
+
```
87
+
88
+
**Virtual OnUpdate:** The controller 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.
89
+
90
+
```csharp
91
+
publicclassMainController : Controller {
92
+
publicoverridevoidOnUpdate () { }
93
+
}
94
+
```
95
+
96
+
**Enabling Systems:** To enable or disable [systems](#Systems), the controller contains of a method EnableSystem which allows [systems](#Systems) to stop their life cycle methods such as OnUpdate, OnPhysics, OnDrawGui and others.
97
+
98
+
```csharp
99
+
publicclassMainController : Controller {
100
+
publicvoidDoSomething () {
101
+
this.SetSystemEnabled<MovementSystem>(true);
102
+
this.SetSystemEnabled<InteractableSystem>(false);
103
+
}
104
+
}
105
+
```
106
+
107
+
**Is System Enabled:** To check wether [systems](#Systems) are enable or disabled, the controller contains of a method IsSystemEnabled. Invoking the method will return a booling informing if the [systems](#Systems) is enabled or not.
108
+
109
+
```csharp
110
+
publicclassMainController : Controller {
111
+
publicvoidDoSomething () {
112
+
if (this.IsSystemEnabled<MovementSystem>()) { }
113
+
}
114
+
}
115
+
```
116
+
117
+
**Injection:** The controller can be be used as an [injected](#Injectables) property and allows insertion of other [injected](#Injectables)[systems](#Systems) and [services](#Services) properties. When being injected, all public methods and properties are accessibly.
75
118
76
119
```csharp
77
120
publicclassMainController : Controller {
78
-
publicoverridevoidOnInitialize () { }
121
+
[Injected] privateMovementSystemmovementSystem;
122
+
[Injected] privateAudioServiceaudioService;
79
123
}
80
124
```
81
125
82
-
**Notes:** While it is recommended to move as much logic into [services](#Services) and [systems](#Systems), it is possible to let your controller house any functionality. If you use the controller for this purpose, try to keep it down to only application wide and core functionality. All public methods and properties are accessibly when having the controller [injected](#Injectables).
126
+
**Notes:** While it is recommended to move as much logic into [services](#Services) and [systems](#Systems), it is possible to let your controller house any functionality. If you use the controller for this purpose, try to keep it down to only application wide and core functionality.
0 commit comments