Example #1
0
        public void AddComponent(ComponentBase component)
        {
            var c = component as Component;

            if (c != null)
            {
                components.Add(c);
                OnAddComponent(c);
            }
            else
            {
                throw new Exception("Tried to AddComponent of wrong type to System "
                                    + component.GetType().ToString() + " to system for " + typeof(Component).ToString());
            }
        }
Example #2
0
        void OnAddComponent(Entity entity, ComponentBase component)
        {
            // search systems to insert the new component
            var componentType = component.GetType();
            var foundSystems  = systems.FindAll(
                s =>
                componentType.Equals(s.ForType()) ||
                componentType.IsSubclassOf(s.ForType())
                );

            if (foundSystems.Count == 0)
            {
                //Console.WriteLine("No System for component " + component.GetType().ToString());
            }

            foreach (IComponentSystem system in foundSystems)
            {
                system.AddComponent(component);
                //Console.WriteLine("add " + component.GetType().Name + " in " + system.GetType().Name);
                //Console.ReadKey(true);
            }
        }