Skip to content

Commit 6a3dcc4

Browse files
Added ShouldUpdate and Update to Services
1 parent c02d9f4 commit 6a3dcc4

File tree

3 files changed

+30
-0
lines changed

3 files changed

+30
-0
lines changed

Diff for: Runtime/Controller.cs

+8
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,14 @@ void Update () {
8282
}
8383
system.OnUpdate ();
8484
}
85+
// Invoking update method on each service.
86+
for (var serviceIndex = 0; serviceIndex < services.Count; serviceIndex++) {
87+
var service = services[serviceIndex];
88+
if (!service.ShouldUpdate ()) {
89+
continue;
90+
}
91+
service.OnUpdate ();
92+
}
8593
}
8694

8795
#if ECS_PHYSICS || ECS_ALL

Diff for: Runtime/Interfaces/IService.cs

+11
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,17 @@ public interface IService {
1313
/// </summary>
1414
void OnInitialized ();
1515

16+
/// <summary>
17+
/// Method invoked when the service updates, will be called every frame.
18+
/// </summary>
19+
void OnUpdate () { }
20+
21+
/// <summary>
22+
// Method invoked before the system will update, return whether this system
23+
// should update. will be called every frame.
24+
/// </summary>
25+
bool ShouldUpdate ();
26+
1627
/// <summary>
1728
// Method invoked when the service is drawing the gizmos, will be called
1829
// every gizmos draw call.

Diff for: Runtime/Service.cs

+11
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,11 @@ public virtual void OnInitialize () { }
4949
/// </summary>
5050
public virtual void OnInitialized () { }
5151

52+
/// <summary>
53+
/// Method invoked when the service updates, will be called every frame.
54+
/// </summary>
55+
public virtual void OnUpdate () { }
56+
5257
/// <summary>
5358
/// Method invoked when the service is drawing the gizmos, will be called
5459
/// every gizmos draw call.
@@ -67,6 +72,12 @@ public virtual void OnDrawGui () { }
6772
/// </summary>
6873
public virtual void OnWillDestroy () { }
6974

75+
/// <summary>
76+
/// Method invoked before the system will update, return whether this system
77+
/// should update. will be called every frame.
78+
/// </summary>
79+
public virtual bool ShouldUpdate () { return true; }
80+
7081
/// <summary>
7182
/// Starts a coroutine on this service.
7283
/// </summary>

0 commit comments

Comments
 (0)