Syntriax.Engine/Engine.Core/GameManager.cs

63 lines
2.0 KiB
C#
Raw Normal View History

2023-11-23 22:07:49 +03:00
using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Syntriax.Engine.Core.Abstract;
using Syntriax.Engine.Core.Factory;
namespace Syntriax.Engine.Core;
public class GameManager
{
public Game Game { get; private set; } = null!;
private IList<IGameObject> _gameObjects = new List<IGameObject>(Constants.GAME_OBJECTS_SIZE_INITIAL);
private GameObjectFactory _gameObjectFactory = null!;
private GameObjectFactory GameObjectFactory
{
get
{
if (_gameObjectFactory is null)
_gameObjectFactory = new GameObjectFactory();
return _gameObjectFactory;
}
}
public IList<IGameObject> GameObjects => _gameObjects;
public void RegisterGameObject(IGameObject gameObject)
{
if (_gameObjects.Contains(gameObject))
throw new Exception($"{nameof(IGameComponent)} named {gameObject.Name} is already registered to the {nameof(GameManager)}.");
_gameObjects.Add(gameObject);
}
public T InstantiateGameObject<T>(params object?[]? args) where T : class, IGameObject
2023-11-23 22:07:49 +03:00
{
T gameObject = GameObjectFactory.Instantiate<T>(args);
2023-11-23 22:07:49 +03:00
_gameObjects.Add(gameObject);
return gameObject;
}
// public TGameObject RegisterGameObject<TGameObject, TTransform, TBehaviourController, TStateEnable>()
// where TGameObject : class, IGameObject
// where TTransform : class, ITransform
// where TBehaviourController : class, IBehaviourController
// where TStateEnable : class, IStateEnable
// {
// TGameObject gameObject = Factory.GameObjectFactory.Get<TGameObject>();
// _gameObjects.Add(gameObject);
// return gameObject;
// }
public void RemoveGameObject(IGameObject gameObject)
{
if (!_gameObjects.Contains(gameObject))
throw new Exception($"{nameof(IGameComponent)} named {gameObject.Name} is not registered to the {nameof(GameManager)}.");
_gameObjects.Remove(gameObject);
}
}