public override bool Initialize(string defaultWorldName) { var sceneName = UnityEngine.SceneManagement.SceneManager.GetActiveScene().name; if (sceneName == "Asteroids" || sceneName == "NetCube" || sceneName == "LagCompensation" || sceneName.StartsWith("BasicPrespawnTest") || sceneName.StartsWith("Test")) { return(base.Initialize(defaultWorldName)); } var world = new World(defaultWorldName); World.DefaultGameObjectInjectionWorld = world; var systems = DefaultWorldInitialization.GetAllSystems(WorldSystemFilterFlags.Default); GenerateSystemLists(systems); DefaultWorldInitialization.AddSystemsToRootLevelSystemGroups(world, DefaultWorldSystems); ScriptBehaviourUpdateOrder.AddWorldToCurrentPlayerLoop(world); return(true); }
public static void InitCustomGameLoop() { //Debug.Log("PhysicsManager.InitCustomGameLoop()"); #if UNITY_2019_3_OR_NEWER PlayerLoopSystem playerLoop = PlayerLoop.GetCurrentPlayerLoop(); #elif MAGICACLOTH_ECS // ECS併用 PlayerLoopSystem playerLoop = ScriptBehaviourUpdateOrder.CurrentPlayerLoop; #else PlayerLoopSystem playerLoop = PlayerLoop.GetDefaultPlayerLoop(); #endif // すでに設定されているならばスルー if (CheckRegist(ref playerLoop)) { //Debug.Log("Skip!!"); return; } // MagicaCloth用PlayerLoopを追加 SetCustomGameLoop(ref playerLoop); #if UNITY_2019_3_OR_NEWER PlayerLoop.SetPlayerLoop(playerLoop); #elif MAGICACLOTH_ECS // ECS併用 ScriptBehaviourUpdateOrder.SetPlayerLoop(playerLoop); #else PlayerLoop.SetPlayerLoop(playerLoop); #endif }
private void RecreatePlayerLoop() { var newPlayerLoop = BuildSystemFromList(rootItem); ScriptBehaviourUpdateOrder.SetPlayerLoopAndNotify(newPlayerLoop); Reload(); }
/// <summary> /// 创建服务端世界 /// </summary> public World CreateServerWorld(string ServerWorldName, params string[] EnableMods) { //创建世界 World ServerWorld = new World(ServerWorldName); EntityManager manager = ServerWorld.EntityManager; //添加世界信息组件 Entity e = manager.CreateEntity(ComponentType.ReadWrite <WorldTypeInfo>()); manager.SetComponentData(e, new WorldTypeInfo() { type = WorldTypes.ServerWorld }); manager.SetName(e, "WorldTypeInfo"); //为接下来将在ServerWorld中禁用的Presentation组的系统做缓存,节省查找开销 List <Type>[] types = new List <Type> [EnableMods.Length]; //轮询添加系统 for (int i = 0; i < EnableMods.Length; i++) { NativeModSystems mod = ModSystems[EnableMods[i]]; DefaultWorldInitialization.AddSystemsToRootLevelSystemGroups(ServerWorld, mod.DefaultWorldSystem); DefaultWorldInitialization.AddSystemsToRootLevelSystemGroups(ServerWorld, mod.ServerSystems); //缓存 types[i] = mod.DefaultPresentationSystems; } ScriptBehaviourUpdateOrder.AddWorldToCurrentPlayerLoop(ServerWorld); //获取ServerWorld中的PresentationSystemGroup并禁止其运行 for (int i = 0; i < types.Length; i++) { for (int j = 0; j < types[i].Count; j++) { ServerWorld.GetExistingSystem(types[i][j]).Enabled = false; } } return(ServerWorld); }
public sealed override void CleanUp() { _system.Clear(); World.DisposeAllWorlds(); ScriptBehaviourUpdateOrder.UpdatePlayerLoop(World.Active); }
public void Initialize(bool createClientWorld, bool createServerWorld) { var systems = DefaultWorldInitialization.GetAllSystems(WorldSystemFilterFlags.Default); GenerateSystemLists(systems); var world = new World("DefaultWorld"); World.DefaultGameObjectInjectionWorld = world; DefaultWorldInitialization.AddSystemsToRootLevelSystemGroups(world, ExplicitDefaultWorldSystems); var currentPlayerLoop = PlayerLoop.GetCurrentPlayerLoop(); ScriptBehaviourUpdateOrder.AddWorldToPlayerLoop(world, ref currentPlayerLoop); PlayerLoop.SetPlayerLoop(currentPlayerLoop); if (createClientWorld) { CreateClientWorld(world, "ClientWorld"); } if (createServerWorld) { CreateServerWorld(world, "ServerWorld"); } EntityWorldManager.Instance.Initialize(); }
public sealed override void Run() { InitEcs(); _system.Run(); ScriptBehaviourUpdateOrder.UpdatePlayerLoop(World.Active); }
public bool Initialize(string defaultWorldName) { var world = new LatiosWorld(defaultWorldName); World.DefaultGameObjectInjectionWorld = world; var initializationSystemGroup = world.GetExistingSystem <InitializationSystemGroup>(); var simulationSystemGroup = world.GetExistingSystem <SimulationSystemGroup>(); var presentationSystemGroup = world.GetExistingSystem <PresentationSystemGroup>(); var systems = new List <Type>(DefaultWorldInitialization.GetAllSystems(WorldSystemFilterFlags.Default)); systems.RemoveSwapBack(typeof(InitializationSystemGroup)); systems.RemoveSwapBack(typeof(SimulationSystemGroup)); systems.RemoveSwapBack(typeof(PresentationSystemGroup)); BootstrapTools.InjectUnitySystems(systems, world, simulationSystemGroup); BootstrapTools.InjectRootSuperSystems(systems, world, simulationSystemGroup); initializationSystemGroup.SortSystems(); simulationSystemGroup.SortSystems(); presentationSystemGroup.SortSystems(); ScriptBehaviourUpdateOrder.AddWorldToCurrentPlayerLoop(world); return(true); }
public void OneTimeTearDown() { // restore GameObject injection world if (World.DefaultGameObjectInjectionWorld != default) { World.DefaultGameObjectInjectionWorld.Dispose(); } if (PreviousGameObjectInjectionWorld != default && !PreviousGameObjectInjectionWorld.IsCreated) { PreviousGameObjectInjectionWorld = default; } World.DefaultGameObjectInjectionWorld = PreviousGameObjectInjectionWorld; ScriptBehaviourUpdateOrder.UpdatePlayerLoop(PreviousGameObjectInjectionWorld); // open an empty scene EditorSceneManager.SetActiveScene(EditorSceneManager.NewScene(NewSceneSetup.EmptyScene)); // clean up scene dependency cache const string k_SceneDependencyCachePath = "Assets/SceneDependencyCache"; if (AssetDatabase.IsValidFolder(k_SceneDependencyCachePath)) { AssetDatabase.DeleteAsset(k_SceneDependencyCachePath); } // delete all temporary assets AssetDatabase.DeleteAsset(TemporaryAssetsPath); }
void ToggleGravityTowards() { var system = World.Active.GetExistingSystem <GravitateToTargetSystem>(); if (system == null) { Debug.Log("Creating new GravitateToTargetSystem"); var world = World.Active; system = world.GetOrCreateSystem <GravitateToTargetSystem>(); system.Enabled = true; ScriptBehaviourUpdateOrder.UpdatePlayerLoop(world); //Had some weird trouble trying to create a system with [DisableAutoCreation], //systems need to be added to the right SimulationSystemGroup so that they are called at the right time of the player loop. //So in the end went with the pattern of creating all systems, and disabling them upon creation //AddSystem<GravitateToTargetSystem>(system); //SimulationSystemGroup.AddSystemToUpdateList(system); //SimulationSystemGroup.SortSystemUpdateList(); //ScriptBehaviourUpdateOrder.UpdatePlayerLoop(world); } else { system.Enabled = !system.Enabled; Debug.Log("Flipping Enabled on GravitateToTargetSystem to:" + system.Enabled); } }
public virtual bool Initialize(string defaultWorldName) { World defaultWorld = new World(defaultWorldName); World.DefaultGameObjectInjectionWorld = defaultWorld; var systems = DefaultWorldInitialization.GetAllSystems(WorldSystemFilterFlags.Default); GenerateSystemList(systems); DefaultWorldInitialization.AddSystemsToRootLevelSystemGroups(defaultWorld, SystemStates.ExplicitDefaultWorldSystems); ScriptBehaviourUpdateOrder.AddWorldToCurrentPlayerLoop(defaultWorld); Config = GetBootstrapConfig(); #if !UNITY_SERVER || UNITY_EDITOR if (Config.StartupWorld.HasFlag(TargetWorld.Client)) { for (int i = 0; i < Config.ClientNum; i++) { CreateClientWorld(defaultWorld, "ClientWorld" + i); } } #endif #if UNITY_SERVER || UNITY_EDITOR if (Config.StartupWorld.HasFlag(TargetWorld.Server)) { CreateServerWorld(defaultWorld, "ServerWorld"); } #endif return(true); }
private static void UpdatePlayerLoop(World world) { var playerLoop = PlayerLoop.GetDefaultPlayerLoop(); if (world != null) { // Insert the root-level systems into the appropriate PlayerLoopSystem subsystems: for (var i = 0; i < playerLoop.subSystemList.Length; ++i) { var subsystemListLength = playerLoop.subSystemList[i].subSystemList.Length; if (playerLoop.subSystemList[i].type == typeof(Update)) { var newSubsystemList = new PlayerLoopSystem[subsystemListLength + 1]; for (var j = 0; j < subsystemListLength; ++j) { newSubsystemList[j] = playerLoop.subSystemList[i].subSystemList[j]; } InsertManagerIntoSubsystemList <SimulationSystemGroup>().Invoke(null, new object[] { newSubsystemList, subsystemListLength + 0, world.GetOrCreateSystem <SimulationSystemGroup>() }); playerLoop.subSystemList[i].subSystemList = newSubsystemList; } else if (playerLoop.subSystemList[i].type == typeof(PreLateUpdate)) { var newSubsystemList = new PlayerLoopSystem[subsystemListLength + 1]; for (var j = 0; j < subsystemListLength; ++j) { newSubsystemList[j] = playerLoop.subSystemList[i].subSystemList[j]; } InsertManagerIntoSubsystemList <PresentationSystemGroup>().Invoke(null, new object[] { newSubsystemList, subsystemListLength + 0, world.GetOrCreateSystem <PresentationSystemGroup>() }); playerLoop.subSystemList[i].subSystemList = newSubsystemList; } else if (playerLoop.subSystemList[i].type == typeof(Initialization)) { var newSubsystemList = new PlayerLoopSystem[subsystemListLength + 1]; for (var j = 0; j < subsystemListLength; ++j) { newSubsystemList[j] = playerLoop.subSystemList[i].subSystemList[j]; } InsertManagerIntoSubsystemList <InitializationSystemGroup>().Invoke(null, new object[] { newSubsystemList, subsystemListLength + 0, world.GetOrCreateSystem <InitializationSystemGroup>() }); playerLoop.subSystemList[i].subSystemList = newSubsystemList; } else if (playerLoop.subSystemList[i].type == typeof(FixedUpdate)) { var newSubsystemList = new PlayerLoopSystem[subsystemListLength + 1]; for (var j = 0; j < subsystemListLength; ++j) { newSubsystemList[j] = playerLoop.subSystemList[i].subSystemList[j]; } InsertManagerIntoSubsystemList <FixedUpdateGroup>().Invoke(null, new object[] { newSubsystemList, subsystemListLength + 0, world.GetOrCreateSystem <FixedUpdateGroup>() }); playerLoop.subSystemList[i].subSystemList = newSubsystemList; } } } ScriptBehaviourUpdateOrder.SetPlayerLoop(playerLoop); }
public void TearDown() { World.DefaultGameObjectInjectionWorld.Dispose(); World.DefaultGameObjectInjectionWorld = null; World.DefaultGameObjectInjectionWorld = m_PreviousWorld; ScriptBehaviourUpdateOrder.UpdatePlayerLoop(null); }
void Start() { var world = World.Active = new World("count up"); world.CreateManager(typeof(CountUpSystem), countText); world.CreateManager(typeof(ClickSystem)); ScriptBehaviourUpdateOrder.UpdatePlayerLoop(world); }
private static void DomainUnloadShutdown() { World.DisposeAllWorlds(); WordStorage.Instance.Dispose(); WordStorage.Instance = null; ScriptBehaviourUpdateOrder.UpdatePlayerLoop(null); }
public void TearDown() { World.Active.Dispose(); World.Active = null; World.Active = m_PreviousWorld; ScriptBehaviourUpdateOrder.UpdatePlayerLoop(); }
void LoadScene(Switch sceneSwitch) { PlayType playModeType = RequestedPlayType; if (sceneSwitch.switchClientorServer == "server") { playModeType = PlayType.ClientAndServer; } if (sceneSwitch.switchClientorServer == "client") { playModeType = PlayType.Client; } var systems = DefaultWorldInitialization.GetAllSystems(WorldSystemFilterFlags.Default); GenerateSystemLists(systems); var world = new World("Default World"); World.DefaultGameObjectInjectionWorld = world; DefaultWorldInitialization.AddSystemsToRootLevelSystemGroups(world, ExplicitDefaultWorldSystems); ScriptBehaviourUpdateOrder.UpdatePlayerLoop(world); int numClientWorlds = RequestedNumClients; int totalNumClients = numClientWorlds; if (playModeType != PlayType.Server) { #if UNITY_EDITOR int numThinClients = RequestedNumThinClients; totalNumClients += numThinClients; #endif for (int i = 0; i < numClientWorlds; ++i) { CreateClientWorld(world, "ClientWorld" + i); } #if UNITY_EDITOR for (int i = numClientWorlds; i < totalNumClients; ++i) { var clientWorld = CreateClientWorld(world, "ClientWorld" + i); clientWorld.EntityManager.CreateEntity(typeof(ThinClientComponent)); } #endif } if (playModeType != PlayType.Client) { CreateServerWorld(world, "ServerWorld"); } var sceneName = sceneSwitch.switchName.ToString(); var async = SceneManager.LoadSceneAsync(sceneName, LoadSceneMode.Single); async.allowSceneActivation = true; }
public override void Setup() { base.Setup(); KeyDomainUtility.Initialize(World); m_StateManager = World.GetOrCreateSystem <StateManager>(); ScriptBehaviourUpdateOrder.AddWorldToCurrentPlayerLoop(World); }
public void IsInPlayerLoop_WorldNotInPlayerLoop_ReturnsFalse() { using (var world = new World("Test World")) { world.CreateSystem <InitializationSystemGroup>(); var playerLoop = PlayerLoop.GetDefaultPlayerLoop(); Assert.IsFalse(ScriptBehaviourUpdateOrder.IsWorldInPlayerLoop(world, playerLoop)); } }
private static IEnumerator DisposeWorld() { World.DefaultGameObjectInjectionWorld.QuitUpdate = true; ScriptBehaviourUpdateOrder.UpdatePlayerLoop(null); yield return(null); World.DisposeAllWorlds(); }
public void RecursiveGroupIsError() { LogAssert.Expect(LogType.Error, new System.Text.RegularExpressions.Regex("Found circular chain in update groups involving:")); var systems = new HashSet <ScriptBehaviourManager>(); systems.Add(new RecursiveSystem()); ScriptBehaviourUpdateOrder.InsertManagersInPlayerLoop(systems, m_fakePlayerLoop); }
public override void TearDown() { World2.Dispose(); World2 = null; base.TearDown(); ScriptBehaviourUpdateOrder.UpdatePlayerLoop(null); }
public void RemoveFromPlayerLoop_WorldNotInPlayerLoop_DoesntThrow() { using (var world = new World("Test World")) { world.CreateSystem <InitializationSystemGroup>(); var playerLoop = PlayerLoop.GetDefaultPlayerLoop(); ScriptBehaviourUpdateOrder.RemoveWorldFromPlayerLoop(world, ref playerLoop); Assert.IsFalse(ScriptBehaviourUpdateOrder.IsWorldInPlayerLoop(world, playerLoop)); } }
public static void DomainUnloadShutdown() { foreach (var worker in Workers) { worker.Dispose(); } World.DisposeAllWorlds(); ScriptBehaviourUpdateOrder.UpdatePlayerLoop(); }
void OnDestroy() { ScriptBehaviourUpdateOrder.UpdatePlayerLoop(null); if (TestECSWorld != null) { TestECSWorld.Dispose(); TestECSWorld = null; } }
static World GetLiveLinkWorld() { DefaultWorldInitialization.DefaultLazyEditModeInitialize(); var world = World.DefaultGameObjectInjectionWorld; // This should be a fresh world, but make sure that it is not part of the player loop so we have manual // control on its updates. ScriptBehaviourUpdateOrder.RemoveWorldFromCurrentPlayerLoop(world); return(world); }
private void InitializeWorker(Worker worker) { Worker = worker; AddWorkerSystems(); InstantiateLevel(); Worker.OnDisconnect += OnDisconnected; World.Active = World.Active ?? Worker.World; ScriptBehaviourUpdateOrder.UpdatePlayerLoop(World.AllWorlds.ToArray()); }
public void OverConstrainedEngineIsError() { // The error is triggered for each system in a chain, not for each chain - so there will be three errors LogAssert.Expect(LogType.Error, new System.Text.RegularExpressions.Regex("is over constrained with engine containts")); var systems = new HashSet <ScriptBehaviourManager>(); systems.Add(new SimpleOverconstrainedSystem()); ScriptBehaviourUpdateOrder.InsertManagersInPlayerLoop(systems, m_fakePlayerLoop); }
public override void TearDown() { CloseAllDebuggers(); World2.Dispose(); World2 = null; base.TearDown(); ScriptBehaviourUpdateOrder.UpdatePlayerLoop(World.Active); }
public override void Setup() { base.Setup(); World2 = new World("Test World 2"); World2.GetOrCreateManager <EntityManager>(); World2.GetOrCreateManager <EmptySystem>(); ScriptBehaviourUpdateOrder.UpdatePlayerLoop(World.AllWorlds.ToArray()); }