|
6 | 6 |
|
7 | 7 | # Entity Component System |
8 | 8 |
|
9 | | -[]() |
| 9 | +[]() |
10 | 10 | []() |
11 | 11 | []() |
12 | 12 |
|
@@ -61,191 +61,191 @@ Use build in file generator to create new instances for any of these types. |
61 | 61 | ```cs |
62 | 62 | /// Base class for every controller. |
63 | 63 | /// NOTE: This class allows the usage of [Injected] systems, services and controller. |
64 | | -public abstract class Controller { |
| 64 | +abstract class Controller { |
65 | 65 |
|
66 | 66 | /// A reference to the controller. |
67 | | - public static Controller Instance; |
| 67 | + static Controller Instance; |
68 | 68 |
|
69 | 69 | /// Method invoked when the controller is initializing. |
70 | | - public virtual void OnInitialize (); |
| 70 | + virtual void OnInitialize (); |
71 | 71 | /// Method invoked when the controller is initialized. |
72 | | - public virtual void OnInitialized (); |
| 72 | + virtual void OnInitialized (); |
73 | 73 | /// Method invoked when the controller updates, will be called every frame. |
74 | | - public virtual void OnUpdate (); |
| 74 | + virtual void OnUpdate (); |
75 | 75 |
|
76 | 76 | /// Register your systems and services to the controller. This can only be |
77 | 77 | /// done during 'OnInitialize' cycle. |
78 | | - public void Register (params System.Type[] typesOf); |
79 | | - /// Enables systems. |
80 | | - public void EnableSystems (params System.Type[] typesOf); |
81 | | - /// Disables systems. |
82 | | - public void DisableSystems (params System.Type[] typesOf); |
| 78 | + void Register (params System.Type[] typesOf); |
| 79 | + /// Enables or disabled a system, enabling the systems allows them to invoke |
| 80 | + /// their cycle methods such as OnUpdate, OnPhysics, OnDrawGui and others. |
| 81 | + void SetSystemEnabled<S> (bool value); |
| 82 | + /// Returns whether a system is enabled. |
| 83 | + bool IsSystemEnabled<S> (); |
83 | 84 | /// Gets a system from this controller. |
84 | | - public S GetSystem<S> () where S : IEntitySystem, new(); |
| 85 | + S GetSystem<S> () where S : IEntitySystem, new(); |
85 | 86 | /// Gets a system from this controller. |
86 | | - public System.Object GetSystem (System.Type typeOf); |
| 87 | + System.Object GetSystem (System.Type typeOf); |
87 | 88 | /// Check whether this controller has a system. |
88 | | - public bool HasSystem<S> () where S : IEntitySystem, new(); |
| 89 | + bool HasSystem<S> () where S : IEntitySystem, new(); |
89 | 90 | /// Gets a service from this controller. |
90 | | - public S GetService<S> () where S : IService, new(); |
| 91 | + S GetService<S> () where S : IService, new(); |
91 | 92 | /// Gets a system from this controller. |
92 | | - public System.Object GetService (System.Type typeOf); |
| 93 | + System.Object GetService (System.Type typeOf); |
93 | 94 | /// Check whether this controller has a service. |
94 | | - public bool HasService<S> () where S : IService, new(); |
| 95 | + bool HasService<S> () where S : IService, new(); |
95 | 96 | /// Gets an asset from this controller. |
96 | | - public AssetType GetAsset<AssetType> (string name); |
| 97 | + AssetType GetAsset<AssetType> (string name); |
97 | 98 | /// Check whether this controller has an asset. |
98 | | - public bool HasAsset (string name); |
| 99 | + bool HasAsset (string name); |
99 | 100 | } |
100 | 101 | ``` |
101 | 102 |
|
102 | 103 | ```cs |
103 | 104 | /// Base class for every entity component. |
104 | 105 | /// NOTE: This class allows the usage of [Referenced] and [Protected] objects and primitives. |
105 | | -public abstract class EntityComponent<EntityComponentType, EntitySystemType> : UnityEngine.MonoBehaviour, IEntityComponent |
| 106 | +abstract class EntityComponent<EntityComponentType, EntitySystemType> : UnityEngine.MonoBehaviour, IEntityComponent |
106 | 107 | where EntityComponentType : EntityComponent<EntityComponentType, EntitySystemType>, new() |
107 | 108 | where EntitySystemType : EntitySystem<EntitySystemType, EntityComponentType>, new() { |
108 | 109 |
|
109 | 110 | /// Defines whether this component is enabled. |
110 | | - public bool isEnabled { get; }; |
| 111 | + bool isEnabled { get; }; |
111 | 112 | /// Sets the game object of the entity active. |
112 | | - public void SetActive (bool value); |
| 113 | + void SetActive (bool value); |
113 | 114 | /// Destroys the game object of the entity. |
114 | | - public void Destroy (); |
| 115 | + void Destroy (); |
115 | 116 | /// Adds an asset to the entity. |
116 | | - public void AddAsset (UnityEngine.Object asset); |
| 117 | + void AddAsset (UnityEngine.Object asset); |
117 | 118 | /// Loads a asset from the controller and adds it as an asset to the entity. |
118 | | - public void AddAsset (string name); |
| 119 | + void AddAsset (string name); |
119 | 120 |
|
120 | 121 | /// Sets the position of an entity. |
121 | | - public void SetPosition (float x, float y, float z = 0); |
| 122 | + void SetPosition (float x, float y, float z = 0); |
122 | 123 | /// Adds to the position of an entity. |
123 | | - public void AddPosition (float x, float y, float z = 0); |
| 124 | + void AddPosition (float x, float y, float z = 0); |
124 | 125 | /// Sets the local position of an entity. |
125 | | - public void SetLocalPosition (float x, float y, float z = 0); |
| 126 | + void SetLocalPosition (float x, float y, float z = 0); |
126 | 127 | /// Adds to the local position of an entity. |
127 | | - public void AddLocalPosition (float x, float y, float z = 0); |
| 128 | + void AddLocalPosition (float x, float y, float z = 0); |
128 | 129 | /// Sets the EulerAngles of an entity. |
129 | | - public void SetEulerAngles (float x, float y, float z); |
| 130 | + void SetEulerAngles (float x, float y, float z); |
130 | 131 | /// Adds to the EulerAngles of an entity. |
131 | | - public void AddEulerAngles (float x, float y, float z); |
| 132 | + void AddEulerAngles (float x, float y, float z); |
132 | 133 | /// Sets the local EulerAngles of an entity. |
133 | | - public void SetLocalEulerAngles (float x, float y, float z); |
| 134 | + void SetLocalEulerAngles (float x, float y, float z); |
134 | 135 | /// Adds to the local EulerAngles of an entity. |
135 | | - public void AddLocalEulerAngles (float x, float y, float z); |
| 136 | + void AddLocalEulerAngles (float x, float y, float z); |
136 | 137 | /// Sets the local scale of an entity. |
137 | | - public void SetLocalScale (float x, float y, float z); |
| 138 | + void SetLocalScale (float x, float y, float z); |
138 | 139 | /// Adds to the local Scale of an entity. |
139 | | - public void AddLocalScale (float x, float y, float z); |
| 140 | + void AddLocalScale (float x, float y, float z); |
140 | 141 | } |
141 | 142 | ``` |
142 | 143 |
|
143 | 144 | ```cs |
144 | 145 | /// Base class for every entity system. |
145 | 146 | /// NOTE: This class allows the usage of [Injected] systems, services and controller. |
146 | | -public abstract class EntitySystem<EntitySystemType, EntityComponentType> : IEntitySystem |
| 147 | +abstract class EntitySystem<EntitySystemType, EntityComponentType> : IEntitySystem |
147 | 148 | where EntitySystemType : EntitySystem<EntitySystemType, EntityComponentType>, new() |
148 | 149 | where EntityComponentType : EntityComponent<EntityComponentType, EntitySystemType>, new() { |
149 | 150 |
|
150 | 151 | /// An instance reference to the controller. |
151 | | - public static EntitySystemType Instance; |
| 152 | + static EntitySystemType Instance; |
152 | 153 | /// A list of the system's instantiated entity components. |
153 | | - public System.Collections.Generic.List<EntityComponentType> entities; |
| 154 | + System.Collections.Generic.List<EntityComponentType> entities; |
154 | 155 | /// The first instantiated entity compoent if this system. |
155 | | - public EntityComponentType entity; |
| 156 | + EntityComponentType entity; |
156 | 157 | /// Defines the number of instantiated entity components this system has. |
157 | | - public int entityCount; |
| 158 | + int entityCount; |
158 | 159 | /// Defines whether the system has instantiated entity components. |
159 | | - public bool hasEntities; |
| 160 | + bool hasEntities; |
160 | 161 |
|
161 | 162 | /// Method invoked when the system will initialize. |
162 | | - public virtual void OnInitialize (); |
| 163 | + virtual void OnInitialize (); |
163 | 164 | /// Method invoked when the system is initialized. |
164 | | - public virtual void OnInitialized (); |
| 165 | + virtual void OnInitialized (); |
165 | 166 | /// Method invoked when the physics update, will be called every fixed frame. |
166 | 167 | /// NOTE: Define the ECS_PHYSICS scripting symbol to use this method. |
167 | | - public virtual void OnPhysics (); |
| 168 | + virtual void OnPhysics (); |
168 | 169 | /// Method invoked when the system is drawing the gizmos, will be called |
169 | 170 | /// every gizmos draw call. |
170 | | - public virtual void OnUpdate (); |
| 171 | + virtual void OnUpdate (); |
171 | 172 | /// Method invoked when the camera renders, will be called every late frame. |
172 | 173 | /// NOTE: Define the ECS_RENDER scripting symbol to use this method. |
173 | | - public virtual void OnRender (); |
| 174 | + virtual void OnRender (); |
174 | 175 | /// Method invoked when the system is drawing the gizmos, will be called |
175 | 176 | /// every gizmos draw call. |
176 | | - public virtual void OnDrawGizmos (); |
| 177 | + virtual void OnDrawGizmos (); |
177 | 178 | /// Method invoked when the system is drawing the gui, will be called every |
178 | 179 | /// on gui draw call. |
179 | | - public virtual void OnDrawGui (); |
| 180 | + virtual void OnDrawGui (); |
180 | 181 | /// Method invoked when the system becomes enabled. |
181 | | - public virtual void OnEnabled (); |
| 182 | + virtual void OnEnabled (); |
182 | 183 | /// Method invoked when the system becomes disabled. |
183 | | - public virtual void OnDisabled (); |
| 184 | + virtual void OnDisabled (); |
184 | 185 | /// Method invoked when an entity of this system is initializing. |
185 | | - public virtual void OnEntityInitialize (EntityComponentType entity); |
| 186 | + virtual void OnEntityInitialize (EntityComponentType entity); |
186 | 187 | /// Method invoked when an entity of this system is initialized. |
187 | | - public virtual void OnEntityInitialized (EntityComponentType entity); |
| 188 | + virtual void OnEntityInitialized (EntityComponentType entity); |
188 | 189 | /// Method invoked when an entity of this system becomes enabled. |
189 | | - public virtual void OnEntityEnabled (EntityComponentType entity); |
| 190 | + virtual void OnEntityEnabled (EntityComponentType entity); |
190 | 191 | /// Method invoked when an entity of this system becomes disabled. |
191 | | - public virtual void OnEntityDisabled (EntityComponentType entity); |
| 192 | + virtual void OnEntityDisabled (EntityComponentType entity); |
192 | 193 | /// Method invoked when an entity of this system will destroy. |
193 | | - public virtual void OnEntityWillDestroy (EntityComponentType entity); |
| 194 | + virtual void OnEntityWillDestroy (EntityComponentType entity); |
194 | 195 | /// Method invoked before the system will update, return whether this system |
195 | 196 | /// should update. will be called every frame. |
196 | | - public virtual bool ShouldUpdate (); |
| 197 | + virtual bool ShouldUpdate (); |
197 | 198 |
|
198 | 199 | /// Returns another component on an entity. |
199 | | - public void GetComponentOnEntity<C> (EntityComponentType entity, System.Action<C> then); |
| 200 | + void GetComponentOnEntity<C> (EntityComponentType entity, System.Action<C> then); |
200 | 201 | /// Returns another component on an entity. |
201 | | - public C GetComponentOnEntity<C> (EntityComponentType entity); |
| 202 | + C GetComponentOnEntity<C> (EntityComponentType entity); |
202 | 203 | /// Checks whether an entity has a specific component. |
203 | | - public bool HasComponentOnEntity<C> (EntityComponentType entity); |
| 204 | + bool HasComponentOnEntity<C> (EntityComponentType entity); |
204 | 205 | /// Creates a new entity. |
205 | | - public EntityComponentType CreateEntity (); |
| 206 | + EntityComponentType CreateEntity (); |
206 | 207 | /// Clones an entity. |
207 | | - public EntityComponentType CloneEntity (EntityComponentType entity); |
| 208 | + EntityComponentType CloneEntity (EntityComponentType entity); |
208 | 209 | /// Clones an entity on a given position in the hierarchy. |
209 | | - public EntityComponentType CloneEntity (EntityComponentType entity, UnityEngine.Transform parentTransform); |
| 210 | + EntityComponentType CloneEntity (EntityComponentType entity, UnityEngine.Transform parentTransform); |
210 | 211 | /// Finds entities using a predicate match. |
211 | | - public EntityComponentType[] MatchEntities (System.Predicate<EntityComponentType> match); |
| 212 | + EntityComponentType[] MatchEntities (System.Predicate<EntityComponentType> match); |
212 | 213 | /// Finds an entity using a predicate match. |
213 | | - public EntityComponentType[] MatchEntity (System.Predicate<EntityComponentType> match); |
| 214 | + EntityComponentType[] MatchEntity (System.Predicate<EntityComponentType> match); |
214 | 215 | /// Starts a coroutine on this system. |
215 | | - public UnityEngine.Coroutine StartCoroutine (System.Collections.IEnumerator routine); |
| 216 | + UnityEngine.Coroutine StartCoroutine (System.Collections.IEnumerator routine); |
216 | 217 | /// Stops a given coroutine. |
217 | | - public void StopCoroutine (System.Collections.IEnumerator routine); |
218 | | - public void StopCoroutine (UnityEngine.Coroutine routine); |
219 | | - /// Enables or disables this system. |
220 | | - public void SetEnabled (bool isEnabled); |
221 | | - /// Gets the enabled status of this system |
222 | | - public bool GetEnabled (); |
| 218 | + void StopCoroutine (System.Collections.IEnumerator routine); |
| 219 | + void StopCoroutine (UnityEngine.Coroutine routine); |
| 220 | + /// Sets whether the system is enabled or disabled, enabling the system allows |
| 221 | + /// it to invoke all of the cycle calls such as OnUpdate and OnDrawGizmos. |
| 222 | + void SetEnabled (bool value); |
223 | 223 | } |
224 | 224 | ``` |
225 | 225 |
|
226 | 226 | ```cs |
227 | 227 | /// Base class for every service |
228 | 228 | /// NOTE: This class allows the usage of [Injected] systems, services and controller. |
229 | | -public abstract class Service<ServiceType> : IService |
| 229 | +abstract class Service<ServiceType> : IService |
230 | 230 | where ServiceType : Service<ServiceType>, new() { |
231 | 231 |
|
232 | 232 | /// An instance reference to the service. |
233 | | - public static ServiceType Instance; |
| 233 | + static ServiceType Instance; |
234 | 234 |
|
235 | 235 | /// Method invoked when the service will initialize. |
236 | | - public virtual void OnInitialize (); |
| 236 | + virtual void OnInitialize (); |
237 | 237 | /// Method invoked when the system is initialized. |
238 | | - public virtual void OnInitialized (); |
| 238 | + virtual void OnInitialized (); |
239 | 239 | /// Method invoked when the service is drawing the gizmos, will be called |
240 | 240 | /// every gizmos draw call. |
241 | | - public virtual void OnDrawGizmos (); |
| 241 | + virtual void OnDrawGizmos (); |
242 | 242 | /// Method invoked when the service is drawing the gui, will be called every |
243 | 243 | /// on gui draw call. |
244 | | - public virtual void OnDrawGui (); |
| 244 | + virtual void OnDrawGui (); |
245 | 245 |
|
246 | 246 | /// Starts a coroutine on this service. |
247 | | - public UnityEngine.Coroutine StartCoroutine (System.Collections.IEnumerator routine); |
| 247 | + UnityEngine.Coroutine StartCoroutine (System.Collections.IEnumerator routine); |
248 | 248 | /// Stops a given coroutine. |
249 | | - public void StopCoroutine (System.Collections.IEnumerator routine); |
| 249 | + void StopCoroutine (System.Collections.IEnumerator routine); |
250 | 250 | } |
251 | 251 | ``` |
0 commit comments