public List <Type> Initialize(List <Type> types) { if (World.Active.Name == "Default World") { DoBootstrap(); return(new List <Type>()); } if (World.Active.Name == "Server World") { for (int ti = 0; ti < types.Count; ti++) { var attrs = types[ti].GetCustomAttributes(false); for (int i = 0; i < attrs.Length; i++) { if (attrs[i].GetType() == typeof(UpdateInGroupAttribute)) { UpdateInGroupAttribute group = (UpdateInGroupAttribute)attrs[i]; if (group.GroupType == typeof(PresentationSystemGroup) || group.GroupType == typeof(SimulationSystemGroup)) { types.RemoveAt(ti); ti--; } } } } } return(types); }
public static void LoadSystemsFromModHosts() { if (null == ModHosts) { Debug.LogError("ECSToUmod.ModHosts needs to be set before calling ECSToUmod.LoadSystemsFromModHosts()"); return; } //ECS systems in mod code are not created/updated automatically so we must create them and add them to the update groups ourselves //Find the Systems to add foreach (var host in ModHosts) { if (!host.IsModLoaded) { continue; } foreach (var assembly in host.ScriptDomain.Assemblies) { //Only looking for Systems of type SystemBase, since ComponentSystem/JobComponentSystem look like they'll be deprecated foreach (var systemType in assembly.FindAllSubTypesOf <SystemBase>()) { //Find the [UpdateInGroup] attribute, if one exists, for the System //This holds which ComponentSystemGroup the System should be added to (InitializationSystemGroup, SimulationSystemGroup, etc) UpdateInGroupAttribute attribute = (UpdateInGroupAttribute)Attribute.GetCustomAttribute(systemType.RawType, typeof(UpdateInGroupAttribute)); if (null == attribute) { //Attribute not found, so no group was specified. Put the system into the default group, which is SimulationSystemGroup attribute = new UpdateInGroupAttribute(typeof(SimulationSystemGroup)); } //Ensure we are adding to a ComponentSystemGroup if (!typeof(ComponentSystemGroup).IsAssignableFrom(attribute.GroupType)) { throw new Exception($"Invalid Type in {systemType.Name} UpdateInGroupAttribute: {attribute.GroupType.Name}"); } //Find or create the ComponentSystemGroup instance for the system to attach to var desiredUpdateGroup = World.DefaultGameObjectInjectionWorld.GetOrCreateSystem(attribute.GroupType); //Spawn the system defined in the mod file var systemInMod = World.DefaultGameObjectInjectionWorld.CreateSystem(systemType.RawType); //Manually add the system to receive Update() calls (desiredUpdateGroup as ComponentSystemGroup).AddSystemToUpdateList(systemInMod); } } } }
public static World CreateServerWorld(World defaultWorld, string worldName) { World world = new World(worldName); var serverInitializationSystemGroup = world.CreateSystem <ServerInitializationSystemGroup>(); var serverSimulationSystemGroup = world.CreateSystem <ServerSimulationSystemGroup>(); var simulationTickSystem = defaultWorld.GetOrCreateSystem <ChainServerSimulationSystem>(); var systems = SystemStates.ServerSystems.Concat(DefaultWorldSystems); foreach (Type type in systems) { if (type == typeof(InitializationSystemGroup) || type == typeof(SimulationSystemGroup) || type == typeof(PresentationSystemGroup) || type == typeof(ServerInitializationSystemGroup) || type == typeof(ServerSimulationSystemGroup) || type == typeof(ChainServerSimulationSystem)) { continue; } var system = world.GetOrCreateSystem(type); UpdateInGroupAttribute attr = GetSystemAttribute <UpdateInGroupAttribute>(type); if (attr == null) { serverSimulationSystemGroup.AddSystemToUpdateList(system); } else { if (attr.GroupType == typeof(InitializationSystemGroup)) { serverInitializationSystemGroup.AddSystemToUpdateList(system); } else if (attr.GroupType == typeof(PresentationSystemGroup)) { } else if (attr.GroupType == typeof(SimulationSystemGroup)) { serverSimulationSystemGroup.AddSystemToUpdateList(system); } else if (attr.GroupType == typeof(ClientAndServerInitializationSystemGroup)) { serverInitializationSystemGroup.AddSystemToUpdateList(system); } else { var group = (ComponentSystemGroup)world.GetOrCreateSystem(attr.GroupType); group.AddSystemToUpdateList(system); } } } serverInitializationSystemGroup.SortSystems(); serverSimulationSystemGroup.SortSystems(); simulationTickSystem.SortSystems(); defaultWorld.GetExistingSystem <InitializationSystemGroup>() .AddSystemToUpdateList(serverInitializationSystemGroup); serverSimulationSystemGroup.ParentChainSystem = simulationTickSystem; simulationTickSystem.AddSystemToUpdateList(serverSimulationSystemGroup); return(world); }