Skip to content

Commit c3f1050

Browse files
Implemented internals
1 parent 55f832b commit c3f1050

13 files changed

+99
-51
lines changed

Runtime/Controller.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,9 @@ private void Update () {
4444

4545
// Invoking 'Internal_OnUpdate' on each system.
4646
for (var _systemIndex = 0; _systemIndex < this.systems.Count; _systemIndex++)
47-
this.systems[_systemIndex].Internal_OnUpdate ();
47+
(this.systems[_systemIndex] as IEntitySystemInternals).OnUpdateInternal ();
4848
for (var _serviceIndex = 0; _serviceIndex < this.services.Count; _serviceIndex++)
49-
this.services[_serviceIndex].Internal_OnUpdate ();
49+
(this.services[_serviceIndex] as IServiceInternals).OnUpdateInternal ();
5050
// Invoking 'OnUpdate' on the controller.
5151
this.OnUpdate ();
5252
// Invoking 'OnUpdate' on each enabled system that Should to be updated.
@@ -133,15 +133,15 @@ public void Register (params System.Type[] typesOf) {
133133
this.systems.Add (_system);
134134
this.enabledSystemsCache.Add (_system);
135135
_system.OnInitialize ();
136-
_system.Internal_OnInitialize ();
136+
(_system as IEntitySystemInternals).OnInitializeInternal ();
137137
}
138138

139139
// When the instance is a type of the system, add it to the services
140140
if (_instance is IService) {
141141
var _service = _instance as IService;
142142
this.services.Add (_service);
143143
_service.OnInitialize ();
144-
_service.Internal_OnInitialize ();
144+
(_service as IServiceInternals).OnInitializeInternal ();
145145
}
146146
}
147147

Runtime/EntityComponent.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
namespace ElRaccoone.EntityComponentSystem {
22

33
/// Base class for every entity component.
4-
public abstract class EntityComponent<EntityComponentType, EntitySystemType> : UnityEngine.MonoBehaviour, IEntityComponent
4+
public abstract class EntityComponent<EntityComponentType, EntitySystemType> : UnityEngine.MonoBehaviour, IEntityComponent, IEntityComponentInternals
55
where EntityComponentType : EntityComponent<EntityComponentType, EntitySystemType>, new()
66
where EntitySystemType : EntitySystem<EntitySystemType, EntityComponentType>, new() {
77

@@ -27,7 +27,7 @@ private EntitySystemType GetSystem () {
2727
/// During the 'Start' the entity component will be registered
2828
/// to the matching system.
2929
private void Start () =>
30-
this.GetSystem ().Internal_AddEntity ((EntityComponentType)this);
30+
this.GetSystem ().AddEntity ((EntityComponentType)this);
3131

3232
/// During the 'OnDisabled' the entity component will invoke its
3333
/// 'OnEntityDisabled' on the system.
@@ -39,7 +39,7 @@ private void OnDisable () {
3939
/// During the 'OnDestroy' the entity component will unregister it self
4040
/// to the matching system.
4141
private void OnDestroy () =>
42-
this.GetSystem ().Internal_RemoveEntry ((EntityComponentType)this);
42+
this.GetSystem ().RemoveEntry ((EntityComponentType)this);
4343

4444
/// Sets the game object of the entity active.
4545
public void SetActive (bool value) =>
@@ -119,7 +119,7 @@ public void AddLocalScale (float x, float y, float z) =>
119119

120120
/// During the 'InteralOnUpdate' the entity component will invoke its
121121
/// 'OnEntityEnabled' and 'OnEntityInitialized' if needed.
122-
public void Internal_OnUpdate () {
122+
void IEntityComponentInternals.OnUpdateInternal () {
123123
if (this.isInitialized == false) {
124124
this.isInitialized = true;
125125
this.GetSystem ().OnEntityInitialized ((EntityComponentType)this);

Runtime/EntitySystem.cs

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
namespace ElRaccoone.EntityComponentSystem {
22

33
/// Base class for every entity system.
4-
public abstract class EntitySystem<EntitySystemType, EntityComponentType> : IEntitySystem
4+
public abstract class EntitySystem<EntitySystemType, EntityComponentType> : IEntitySystem, IEntitySystemInternals
55
where EntitySystemType : EntitySystem<EntitySystemType, EntityComponentType>, new()
66
where EntityComponentType : EntityComponent<EntityComponentType, EntitySystemType>, new() {
77

@@ -132,25 +132,8 @@ public void StopCoroutine (UnityEngine.Coroutine routine) =>
132132
public void SetEnabled (bool value) =>
133133
Controller.Instance.SetSystemEnabled<EntitySystemType> (value);
134134

135-
/// Internal method to set the instance reference. This method will
136-
/// be called after the controller and system initialization.
137-
public void Internal_OnInitialize () =>
138-
Instance = Controller.Instance.GetSystem<EntitySystemType> ();
139-
140-
/// Internal method to update the children of the system.
141-
public void Internal_OnUpdate () {
142-
if (this.isInitialized == false) {
143-
this.OnInitialized ();
144-
if (Controller.Instance.IsSystemEnabled<EntitySystemType> () == true)
145-
this.OnEnabled ();
146-
this.isInitialized = true;
147-
}
148-
for (var _entityIndex = 0; _entityIndex < this.entityCount; _entityIndex++)
149-
this.entities[_entityIndex].Internal_OnUpdate ();
150-
}
151-
152135
/// Internal method to add an entity's component to this system.
153-
public void Internal_AddEntity (EntityComponentType component) {
136+
internal void AddEntity (EntityComponentType component) {
154137
if (this.hasEntities == false)
155138
this.entity = component;
156139
this.entityCount++;
@@ -160,12 +143,29 @@ public void Internal_AddEntity (EntityComponentType component) {
160143
}
161144

162145
/// Internal method to remove an entity's component from this system.
163-
public void Internal_RemoveEntry (EntityComponentType component) {
146+
internal void RemoveEntry (EntityComponentType component) {
164147
this.entityCount--;
165148
this.hasEntities = this.entityCount > 0;
166149
this.OnEntityWillDestroy (component);
167150
this.entities.Remove (component);
168151
this.entity = this.hasEntities == false ? null : this.entities[0];
169152
}
153+
154+
/// Internal method to set the instance reference. This method will
155+
/// be called after the controller and system initialization.
156+
void IEntitySystemInternals.OnInitializeInternal () =>
157+
Instance = Controller.Instance.GetSystem<EntitySystemType> ();
158+
159+
/// Internal method to update the children of the system.
160+
void IEntitySystemInternals.OnUpdateInternal () {
161+
if (this.isInitialized == false) {
162+
this.OnInitialized ();
163+
if (Controller.Instance.IsSystemEnabled<EntitySystemType> () == true)
164+
this.OnEnabled ();
165+
this.isInitialized = true;
166+
}
167+
for (var _entityIndex = 0; _entityIndex < this.entityCount; _entityIndex++)
168+
(this.entities[_entityIndex] as IEntityComponentInternals).OnUpdateInternal ();
169+
}
170170
}
171171
}
Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
11
namespace ElRaccoone.EntityComponentSystem {
22

33
/// Base interface for every component
4-
public interface IEntityComponent {
5-
6-
/// During the 'InteralOnUpdate' the entity component will invoke its
7-
/// 'OnEntityEnabled' and 'OnEntityInitialized' if needed.
8-
void Internal_OnUpdate ();
9-
}
4+
public interface IEntityComponent { }
105
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
namespace ElRaccoone.EntityComponentSystem {
2+
3+
/// Base interface for component internals.
4+
internal interface IEntityComponentInternals {
5+
6+
/// During the 'InteralOnUpdate' the entity component will invoke its
7+
/// 'OnEntityEnabled' and 'OnEntityInitialized' if needed.
8+
void OnUpdateInternal ();
9+
}
10+
}

Runtime/Interfaces/IEntityComponentInternals.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Runtime/Interfaces/IEntitySystem.cs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,5 @@ public interface IEntitySystem {
4747
/// Sets whether the system is enabled or disabled, enabling the system allows
4848
/// it to invoke all of the cycle calls such as OnUpdate and OnDrawGizmos.
4949
void SetEnabled (bool value);
50-
51-
/// Internal method to set the instance reference. This method will
52-
/// be called after the controller and system initialization.
53-
void Internal_OnInitialize ();
54-
55-
/// Internal method to update the children of the system.
56-
void Internal_OnUpdate ();
5750
}
5851
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
namespace ElRaccoone.EntityComponentSystem {
2+
3+
/// Base interface for system internals.
4+
internal interface IEntitySystemInternals {
5+
/// Internal method to set the instance reference. This method will
6+
/// be called after the controller and system initialization.
7+
void OnInitializeInternal ();
8+
9+
/// Internal method to update the children of the system.
10+
void OnUpdateInternal ();
11+
}
12+
}

Runtime/Interfaces/IEntitySystemInternals.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Runtime/Interfaces/IService.cs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,5 @@ public interface IService {
2020
/// Method invoked when the service will be destroyed, this will happen when
2121
/// the application is closing or the controller is being destroyed.
2222
void OnWillDestroy ();
23-
24-
/// Internal method to set the instance reference. This method will
25-
/// be called after the controller and service initialization.
26-
void Internal_OnInitialize ();
27-
28-
/// Internal method to update the service.
29-
void Internal_OnUpdate ();
3023
}
3124
}

0 commit comments

Comments
 (0)