public Main() { Instance = this; AppDomain.CurrentDomain.UnhandledException += OnUnhandledException; Updateables.Add(CoopClient.Instance); Updateables.Add(GameLoopRunner.Instance); }
public void Add <T>(T component) where T : Component { Remove <T>(); component.GameObject = this; component.Transform = Transform; Components.Add(typeof(T), component); if (component is IUpdateable) { Updateables.Add(component as IUpdateable); } if (component is IRenderable) { Renderables.Add(component as IRenderable); } if (component is IDrawable) { Drawables.Add(component as IDrawable); } }
public T Add <T>() where T : Component, new() { Remove <T>(); T component = new T(); component.GameObject = this; Components.Add(typeof(T), component); if (component is IUpdateable) { Updateables.Add(component as IUpdateable); } if (component is IRenderable) { Renderables.Add(component as IRenderable); } if (component is IDrawable) { Drawables.Add(component as IDrawable); } return(component); }
/// <summary> /// Adds a given component to the system. If the component is a renderable it adds it to the scenes /// renderables, which in turn are picked up by the renderer, to render during draw calls. /// </summary> /// <param name="component">The component to add to the systems.</param> public void AddComponentToSystems(IComponent component) { // Could be an IRenderable if (component is IRenderable renderable) { if (Renderables == null) { Renderables = new List <IRenderable>(); } Renderables.Add(renderable); } // Could also be an IUpdateable TOO! // Some components can implement both IRenderable and IUpdateable so check for both. // TODO Optimize? If we only add components at the start of the scene it probably doesn't matter. // Updateables probably wants to become some kind of type map though. if (component is IUpdateable updateable) { if (Updateables == null) { Updateables = new List <IUpdateable>(); } Updateables.Add(updateable); } }