-
-
Save Quantumplation/527decb99c3017fc853f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public interface IManager {} | |
public interface IManager<T> : IManager { public void AddComponent(T comp); } | |
public GraphicsManager : IManager<Sprite>, IManager<Camera> | |
{ | |
... | |
} | |
public void World | |
{ | |
IDictionary<Type, ManagerAdder> _adders; | |
public void AddManager<T>(IManager<T> mgr) | |
{ | |
_adders[typeof(T)]._managers.Add(mgr); | |
} | |
public void AddEntity(Entity e) | |
{ | |
foreach(var comp in e.Components) | |
_adders[comp.GetType()].AddComponent(comp); | |
} | |
} | |
public class BaseComponent {} | |
public class Entity { public List<BaseComponent> Components; } | |
interface ManagerAdder | |
{ | |
void AddComponent(BaseComponent c); | |
} | |
class ManagerAdder<T> : ManagerAdder | |
{ | |
pubic List<IManager<T>> _managers; | |
public ManagerAdder(IManager<T> manager) | |
{ | |
_manager = manager; | |
} | |
void AddComponent(BaseComponent c) | |
{ | |
_managers.ForEach(x => x.AddComponent((T)c)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment