Compare commits
2 Commits
39e553ebbf
...
d08495afbb
Author | SHA1 | Date | |
---|---|---|---|
d08495afbb | |||
fdb5936573 |
@@ -1,4 +1,5 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using System.Collections;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
|
||||||
using Syntriax.Engine.Core.Abstract;
|
using Syntriax.Engine.Core.Abstract;
|
||||||
@@ -7,9 +8,12 @@ using Syntriax.Engine.Core.Factory;
|
|||||||
|
|
||||||
namespace Syntriax.Engine.Core;
|
namespace Syntriax.Engine.Core;
|
||||||
|
|
||||||
public class GameManager : IEntity
|
public class GameManager : IEntity, IEnumerable<IGameObject>
|
||||||
{
|
{
|
||||||
public Action<GameManager>? OnCameraChanged { get; set; } = null;
|
public Action<GameManager>? OnCameraChanged { get; set; } = null;
|
||||||
|
public Action<GameManager, IGameObject>? OnGameObjectRegistered { get; set; } = null;
|
||||||
|
public Action<GameManager, IGameObject>? OnGameObjectUnRegistered { get; set; } = null;
|
||||||
|
|
||||||
public Action<IInitialize>? OnInitialized { get; set; } = null;
|
public Action<IInitialize>? OnInitialized { get; set; } = null;
|
||||||
public Action<IInitialize>? OnFinalized { get; set; } = null;
|
public Action<IInitialize>? OnFinalized { get; set; } = null;
|
||||||
public Action<IAssignable>? OnUnassigned { get; set; } = null;
|
public Action<IAssignable>? OnUnassigned { get; set; } = null;
|
||||||
@@ -148,18 +152,20 @@ public class GameManager : IEntity
|
|||||||
|
|
||||||
/////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
private void Unregister(IGameObject gameObject)
|
|
||||||
{
|
|
||||||
gameObject.OnFinalized -= OnGameObjectFinalize;
|
|
||||||
|
|
||||||
_gameObjects.Remove(gameObject);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void Register(IGameObject gameObject)
|
private void Register(IGameObject gameObject)
|
||||||
{
|
{
|
||||||
gameObject.OnFinalized += OnGameObjectFinalize;
|
gameObject.OnFinalized += OnGameObjectFinalize;
|
||||||
|
|
||||||
_gameObjects.Add(gameObject);
|
_gameObjects.Add(gameObject);
|
||||||
|
OnGameObjectRegistered?.Invoke(this, gameObject);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void Unregister(IGameObject gameObject)
|
||||||
|
{
|
||||||
|
gameObject.OnFinalized -= OnGameObjectFinalize;
|
||||||
|
|
||||||
|
_gameObjects.Remove(gameObject);
|
||||||
|
OnGameObjectUnRegistered?.Invoke(this, gameObject);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnGameObjectFinalize(IInitialize initialize)
|
private void OnGameObjectFinalize(IInitialize initialize)
|
||||||
@@ -167,4 +173,9 @@ public class GameManager : IEntity
|
|||||||
if (initialize is IGameObject gameObject)
|
if (initialize is IGameObject gameObject)
|
||||||
Unregister(gameObject);
|
Unregister(gameObject);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
public IEnumerator<IGameObject> GetEnumerator() => _gameObjects.GetEnumerator();
|
||||||
|
IEnumerator IEnumerable.GetEnumerator() => _gameObjects.GetEnumerator();
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user