feat: IGameManager Events
This commit is contained in:
parent
91aa26e15a
commit
9c2b098821
|
@ -7,6 +7,16 @@ namespace Syntriax.Engine.Core.Abstract;
|
|||
/// </summary>
|
||||
public interface IGameManager : IEntity, IEnumerable<IGameObject>
|
||||
{
|
||||
/// <summary>
|
||||
/// Event triggered when <see cref="Update(EngineTime)"/> is called on the <see cref="IGameManager"/>.
|
||||
/// </summary>
|
||||
event OnUpdateDelegate? OnUpdate;
|
||||
|
||||
/// <summary>
|
||||
/// Event triggered when <see cref="PreDraw"/> is called on the <see cref="IGameManager"/>.
|
||||
/// </summary>
|
||||
event OnPreDawDelegate? OnPreDraw;
|
||||
|
||||
/// <summary>
|
||||
/// Event triggered when a <see cref="IGameObject"/> is registered to the <see cref="IGameManager"/>.
|
||||
/// </summary>
|
||||
|
@ -69,6 +79,9 @@ public interface IGameManager : IEntity, IEnumerable<IGameObject>
|
|||
/// </summary>
|
||||
void PreDraw();
|
||||
|
||||
delegate void OnUpdateDelegate(IGameManager sender, EngineTime time);
|
||||
delegate void OnPreDawDelegate(IGameManager sender);
|
||||
|
||||
delegate void OnGameObjectRegisteredDelegate(IGameManager sender, IGameObject gameObjectRegistered);
|
||||
delegate void OnGameObjectUnRegisteredDelegate(IGameManager sender, IGameObject gameObjectUnregistered);
|
||||
delegate void OnHierarchyObjectRegisteredDelegate(IGameManager sender, IHierarchyObject hierarchyObjectRegistered);
|
||||
|
|
|
@ -11,6 +11,9 @@ namespace Syntriax.Engine.Core;
|
|||
[System.Diagnostics.DebuggerDisplay("GameObject Count: {_gameObjects.Count}")]
|
||||
public class GameManager : BaseEntity, IGameManager
|
||||
{
|
||||
public event IGameManager.OnUpdateDelegate? OnUpdate = null;
|
||||
public event IGameManager.OnPreDawDelegate? OnPreDraw = null;
|
||||
|
||||
public event IGameManager.OnGameObjectRegisteredDelegate? OnGameObjectRegistered = null;
|
||||
public event IGameManager.OnGameObjectUnRegisteredDelegate? OnGameObjectUnRegistered = null;
|
||||
public event IGameManager.OnHierarchyObjectRegisteredDelegate? OnHierarchyObjectRegistered = null;
|
||||
|
@ -94,12 +97,16 @@ public class GameManager : BaseEntity, IGameManager
|
|||
Time.SetTime(time);
|
||||
for (int i = 0; i < GameObjects.Count; i++)
|
||||
GameObjects[i].BehaviourController.Update();
|
||||
|
||||
OnUpdate?.Invoke(this, time);
|
||||
}
|
||||
|
||||
public void PreDraw()
|
||||
{
|
||||
for (int i = 0; i < GameObjects.Count; i++)
|
||||
GameObjects[i].BehaviourController.UpdatePreDraw();
|
||||
|
||||
OnPreDraw?.Invoke(this);
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////
|
||||
|
|
Loading…
Reference in New Issue