private ComponentSystemBase CreateSystemInternal <T>() where T : new() { #if ENABLE_UNITY_COLLECTIONS_CHECKS if (!m_AllowGetSystem) { throw new ArgumentException( "During destruction of a system you are not allowed to create more systems."); } m_AllowGetSystem = true; #endif ComponentSystemBase system; try { #if !NET_DOTS system = new T() as ComponentSystemBase; #else system = TypeManager.ConstructSystem(typeof(T)); #endif } catch { #if ENABLE_UNITY_COLLECTIONS_CHECKS m_AllowGetSystem = false; #endif throw; } return(AddSystem(system)); }
public ComponentSystemBase GetOrCreateSystem(Type type) { CheckGetOrCreateSystem(); var system = GetExistingSystem(type); return(system ?? TypeManager.ConstructSystem(type)); }
/// <summary> /// Initialize the ComponentSystems. See <see cref="Initialize"/> for use. /// </summary> public static void InitializeSystems(World world) { var allSystemTypes = TypeManager.GetSystems(); var allSystemNames = TypeManager.SystemNames; if (allSystemTypes.Length == 0) { throw new InvalidOperationException("DefaultTinyWorldInitialization: No Systems found."); } // Create top level presentation system and simulation systems. InitializationSystemGroup initializationSystemGroup = new InitializationSystemGroup(); world.AddSystem(initializationSystemGroup); SimulationSystemGroup simulationSystemGroup = new SimulationSystemGroup(); world.AddSystem(simulationSystemGroup); PresentationSystemGroup presentationSystemGroup = new PresentationSystemGroup(); world.AddSystem(presentationSystemGroup); // Create the working set of systems. #if WRITE_LOG Console.WriteLine("--- Adding systems:"); #endif for (int i = 0; i < allSystemTypes.Length; i++) { if (TypeManager.GetSystemAttributes(allSystemTypes[i], typeof(DisableAutoCreationAttribute)).Length > 0) { continue; } if (allSystemTypes[i] == initializationSystemGroup.GetType() || allSystemTypes[i] == simulationSystemGroup.GetType() || allSystemTypes[i] == presentationSystemGroup.GetType()) { continue; } // Subtle issue. If the System was created by GetOrCreateSystem at the "right" time // before its own initialization, then it will exist. GetExistingSystem will return a valid // object. BUT, that object will not have been put into a SystemGroup. var sys = world.GetExistingSystem(allSystemTypes[i]); if (sys != null) { AddSystemToGroup(world, sys); continue; } #if WRITE_LOG Console.WriteLine(allSystemNames[i]); #endif AddSystem(world, TypeManager.ConstructSystem(allSystemTypes[i])); } }
ComponentSystemBase AllocateSystemInternal(Type type) { #if ENABLE_UNITY_COLLECTIONS_CHECKS if (!m_AllowGetSystem) { throw new ArgumentException( "During destruction of a system you are not allowed to create more systems."); } #endif return(TypeManager.ConstructSystem(type)); }
public static void InitializeSystems(World world) { var allSystemTypes = TypeManager.GetSystems(); var allSystemNames = TypeManager.SystemNames; if (allSystemTypes.Length == 0) { throw new InvalidOperationException("DefaultTinyWorldInitialization: No Systems found."); } // Create top level presentation system and simulation systems. InitializationSystemGroup initializationSystemGroup = new InitializationSystemGroup(); world.AddSystem(initializationSystemGroup); SimulationSystemGroup simulationSystemGroup = new SimulationSystemGroup(); world.AddSystem(simulationSystemGroup); PresentationSystemGroup presentationSystemGroup = new PresentationSystemGroup(); world.AddSystem(presentationSystemGroup); // Create the working set of systems. #if WRITE_LOG Console.WriteLine("--- Adding systems:"); #endif for (int i = 0; i < allSystemTypes.Length; i++) { if (TypeManager.GetSystemAttributes(allSystemTypes[i], typeof(DisableAutoCreationAttribute)).Length > 0) { continue; } if (allSystemTypes[i] == initializationSystemGroup.GetType() || allSystemTypes[i] == simulationSystemGroup.GetType() || allSystemTypes[i] == presentationSystemGroup.GetType()) { continue; } if (world.GetExistingSystem(allSystemTypes[i]) != null) { continue; } #if WRITE_LOG Console.WriteLine(allSystemNames[i]); #endif AddSystem(world, TypeManager.ConstructSystem(allSystemTypes[i])); } }
/// <summary> /// Initialize the ComponentSystems. See <see cref="Initialize"/> for use. /// </summary> public static void InitializeSystems(World world) { var allSystemTypes = TypeManager.GetSystems(); if (allSystemTypes.Length == 0) { throw new InvalidOperationException("DefaultTinyWorldInitialization: No Systems found."); } // Create top level presentation system and simulation systems. InitializationSystemGroup initializationSystemGroup = new InitializationSystemGroup(); world.AddSystem(initializationSystemGroup); SimulationSystemGroup simulationSystemGroup = new SimulationSystemGroup(); world.AddSystem(simulationSystemGroup); PresentationSystemGroup presentationSystemGroup = new PresentationSystemGroup(); world.AddSystem(presentationSystemGroup); // Create the working set of systems. // The full set of Systems must be created (and initialized with the World) before // they can be placed into SystemGroup. Else you get the problem that a System may // be put into a SystemGroup that hasn't been created. IterateAllAutoSystems(world, (World w, Type systemType) => { // Need the if check because game/test code may have auto-constructed a System already. if (world.GetExistingSystem(systemType) == null) { AddSystem(world, TypeManager.ConstructSystem(systemType), false); } }); IterateAllAutoSystems(world, (World w, Type systemType) => { AddSystemToGroup(world, world.GetExistingSystem(systemType)); }); }
public static void InitializeSystems(World world) { var allSystemTypes = TypeManager.GetSystems(); var allSystemNames = TypeManager.SystemNames; if (allSystemTypes.Length == 0) { throw new InvalidOperationException("DefaultTinyWorldInitialization: No Systems found."); } // Create top level presentation system and simulation systems. InitializationSystemGroup initializationSystemGroup = new InitializationSystemGroup(); world.AddManager(initializationSystemGroup); SimulationSystemGroup simulationSystemGroup = new SimulationSystemGroup(); world.AddManager(simulationSystemGroup); PresentationSystemGroup presentationSystemGroup = new PresentationSystemGroup(); world.AddManager(presentationSystemGroup); // Create the working set of systems. int nSystems = 0; Type[] systemTypes = new Type[allSystemTypes.Length]; ComponentSystem[] systems = new ComponentSystem[allSystemTypes.Length]; #if WRITE_LOG Console.WriteLine("--- Adding systems:"); #endif for (int i = 0; i < allSystemTypes.Length; i++) { if (TypeManager.GetSystemAttributes(allSystemTypes[i], typeof(DisableAutoCreationAttribute)).Length > 0) { continue; } if (allSystemTypes[i] == initializationSystemGroup.GetType() || allSystemTypes[i] == simulationSystemGroup.GetType() || allSystemTypes[i] == presentationSystemGroup.GetType()) { continue; } if (world.GetExistingManager(allSystemTypes[i]) != null) { continue; } #if WRITE_LOG Console.WriteLine(allSystemNames[i]); #endif systemTypes[nSystems] = allSystemTypes[i]; systems[nSystems] = TypeManager.ConstructSystem(allSystemTypes[i]); world.AddManager(systems[nSystems]); nSystems++; } #if WRITE_LOG Console.WriteLine("--- Adding systems Done."); #endif for (int i = 0; i < nSystems; ++i) { var sysType = systemTypes[i]; var system = systems[i]; var groups = TypeManager.GetSystemAttributes(sysType, typeof(UpdateInGroupAttribute)); if (groups.Length == 0) { simulationSystemGroup.AddSystemToUpdateList(system); } for (int g = 0; g < groups.Length; ++g) { var groupType = groups[g] as UpdateInGroupAttribute; var groupSystem = world.GetExistingManager(groupType.GroupType) as ComponentSystemGroup; if (groupSystem == null) { throw new Exception("DefaultTinyWorldInitialization failed to find existing SystemGroup."); } groupSystem.AddSystemToUpdateList(system); } } }