Skip to content

Instantly share code, notes, and snippets.

@Quantumplation
Forked from martindevans/gist:ff33155cbbb9e955d4a2
Last active August 29, 2015 14:13
Show Gist options
  • Save Quantumplation/527decb99c3017fc853f to your computer and use it in GitHub Desktop.
Save Quantumplation/527decb99c3017fc853f to your computer and use it in GitHub Desktop.
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