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; if (playerLoop.subSystemList == null || playerLoop.subSystemList.Length == 0) { playerLoop = PlayerLoop.GetDefaultPlayerLoop(); } #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 && UNITY_2019_1_OR_NEWER) // ECS併用 ScriptBehaviourUpdateOrder.SetPlayerLoop(playerLoop); // この関数はUnity2019以上でなければ存在しない(※正確にはEntity0.1.1) #else PlayerLoop.SetPlayerLoop(playerLoop); #endif }
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 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 static void UpdatePlayerLoop(World world) { var playerLoop = PlayerLoop.GetDefaultPlayerLoop(); if (ScriptBehaviourUpdateOrder.CurrentPlayerLoop.subSystemList != null) { playerLoop = ScriptBehaviourUpdateOrder.CurrentPlayerLoop; } if (world != null) { for (var i = 0; i < playerLoop.subSystemList.Length; ++i) { int subsystemListLength = playerLoop.subSystemList[i].subSystemList.Length; 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]; } var mgr = world.GetOrCreateSystem <SimulationSystemGroup>(); var genericMethod = insertManagerIntoSubsystemListMethod.MakeGenericMethod(mgr.GetType()); genericMethod.Invoke(null, new object[] { newSubsystemList, subsystemListLength + 0, mgr }); playerLoop.subSystemList[i].subSystemList = newSubsystemList; } else 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]; } var mgr = world.GetOrCreateSystem <PresentationSystemGroup>(); var genericMethod = insertManagerIntoSubsystemListMethod.MakeGenericMethod(mgr.GetType()); genericMethod.Invoke(null, new object[] { newSubsystemList, subsystemListLength + 0, mgr }); 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]; } var mgr = world.GetOrCreateSystem <InitializationSystemGroup>(); var genericMethod = insertManagerIntoSubsystemListMethod.MakeGenericMethod(mgr.GetType()); genericMethod.Invoke(null, new object[] { newSubsystemList, subsystemListLength + 0, mgr }); playerLoop.subSystemList[i].subSystemList = newSubsystemList; } } } ScriptBehaviourUpdateOrder.SetPlayerLoop(playerLoop); }
void Awake() { foreach (World world in World.AllWorlds) { if (world.Name == "Server World") { serverWorld = world; server = serverWorld.GetOrCreateManager <Server>(); } if (world.Name == "Client World") { clientWorld = world; client = clientWorld.GetOrCreateManager <Client>(); } } CustomUpdateSystem customUpdateSystem = new CustomUpdateSystem(new ComponentSystem[] { client, server }); PlayerLoopSystem playerLoopSystem = ScriptBehaviourUpdateOrder.CurrentPlayerLoop; PlayerLoopSystem[] subsystems = playerLoopSystem.subSystemList; for (int i = 0; i < subsystems.Length; i++) { PlayerLoopSystem system = subsystems[i]; if (system.type == typeof(FixedUpdate)) { PlayerLoopSystem fixedUpdateSystem = system; List <PlayerLoopSystem> fixedUpdateSystems = new List <PlayerLoopSystem>(system.subSystemList); PlayerLoopSystem customPlayerLoop = new PlayerLoopSystem(); customPlayerLoop.type = typeof(CustomUpdateSystem); customPlayerLoop.updateDelegate = customUpdateSystem.FixedUpdate; fixedUpdateSystems.Add(customPlayerLoop); fixedUpdateSystem.subSystemList = fixedUpdateSystems.ToArray(); playerLoopSystem.subSystemList[i] = fixedUpdateSystem; } } ScriptBehaviourUpdateOrder.SetPlayerLoop(playerLoopSystem); }
public IEnumerator Delete() { var gameServerHandler = GameServerHandler.Get(); foreach (var p in players) { gameServerHandler.clients.Remove(p.client.ep.ToString()); } gameMaster.OnEveryPlayerLeaved(); blobAssetStore.Dispose(); world.QuitUpdate = true; ScriptBehaviourUpdateOrder.SetPlayerLoop(PlayerLoop.GetDefaultPlayerLoop()); world.EntityManager.CompleteAllJobs(); world.EntityManager.DestroyEntity(world.EntityManager.GetAllEntities()); yield return(new WaitForEndOfFrame()); world.Dispose(); gameServerHandler.matches.Remove(matchId); }
/// <summary> /// Update the player loop with a world's root-level systems /// </summary> /// <param name="world">World with root-level systems that need insertion into the player loop</param> /// <param name="existingPlayerLoop">Optional parameter to preserve existing player loops (e.g. ScriptBehaviourUpdateOrder.CurrentPlayerLoop)</param> public static void AddWorldSystemGroupsIntoPlayerLoop(World world, PlayerLoopSystem?existingPlayerLoop = null) { PlayerLoopSystem playerLoop = existingPlayerLoop ?? PlayerLoop.GetDefaultPlayerLoop(); if (world != null) { // Insert the root-level systems into the appropriate PlayerLoopSystem subsystems: for (var i = 0; i < playerLoop.subSystemList.Length; ++i) { if (playerLoop.subSystemList[i].type == typeof(Update)) { playerLoop.subSystemList[i].subSystemList = AddSystem <SimSimulationSystemGroup>( world, playerLoop.subSystemList[i].subSystemList); } else if (playerLoop.subSystemList[i].type == typeof(PreLateUpdate)) { playerLoop.subSystemList[i].subSystemList = AddSystem <SimPresentationSystemGroup>( world, playerLoop.subSystemList[i].subSystemList); } else if (playerLoop.subSystemList[i].type == typeof(Initialization)) { playerLoop.subSystemList[i].subSystemList = AddSystem <SimPreInitializationSystemGroup>( world, playerLoop.subSystemList[i].subSystemList); playerLoop.subSystemList[i].subSystemList = AddSystem <SimInitializationSystemGroup>( world, playerLoop.subSystemList[i].subSystemList); } } } ScriptBehaviourUpdateOrder.SetPlayerLoop(playerLoop); }
//Mostly copied from ScriptBehaviourUpdateOrder /// <summary> /// Update the player loop with a world's root-level systems including FixedUpdate /// </summary> /// <param name="world">World with root-level systems that need insertion into the player loop</param> /// <param name="existingPlayerLoop">Optional parameter to preserve existing player loops (e.g. ScriptBehaviourUpdateOrder.CurrentPlayerLoop)</param> public static void UpdatePlayerLoopWithFixedUpdate(World world, PlayerLoopSystem?existingPlayerLoop = null) { //Use reflection to snag the private delegate needed for this var insertMethodInfo = typeof(ScriptBehaviourUpdateOrder).GetMethod("InsertManagerIntoSubsystemList", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Static); var simMethod = insertMethodInfo.MakeGenericMethod(typeof(SimulationSystemGroup)); var presMethod = insertMethodInfo.MakeGenericMethod(typeof(PresentationSystemGroup)); var initMethod = insertMethodInfo.MakeGenericMethod(typeof(InitializationSystemGroup)); var fixedMethod = insertMethodInfo.MakeGenericMethod(typeof(FixedSimulationSystemGroup)); var playerLoop = existingPlayerLoop ?? PlayerLoop.GetDefaultPlayerLoop(); if (world != null) { // Insert the root-level systems into the appropriate PlayerLoopSystem subsystems: for (var i = 0; i < playerLoop.subSystemList.Length; ++i) { int 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]; } simMethod.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]; } presMethod.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]; } initMethod.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]; } fixedMethod.Invoke(null, new object[] { newSubsystemList, subsystemListLength + 0, world.GetOrCreateSystem <FixedSimulationSystemGroup>() }); playerLoop.subSystemList[i].subSystemList = newSubsystemList; } } } ScriptBehaviourUpdateOrder.SetPlayerLoop(playerLoop); }
static void 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 false // debug foreach (var header in playerLoop.subSystemList) { Debug.LogFormat("------{0}------", header.type.Name); foreach (var subSystem in header.subSystemList) { Debug.LogFormat("{0}.{1}", header.type.Name, subSystem.type.Name); } } #endif PlayerLoopSystem afterUpdate = new PlayerLoopSystem() { type = typeof(MagicaPhysicsManager), updateDelegate = () => { if (IsInstance()) { Instance.AfterUpdate(); } } }; PlayerLoopSystem beforeLateUpdate = new PlayerLoopSystem() { type = typeof(MagicaPhysicsManager), updateDelegate = () => { if (IsInstance()) { Instance.BeforeLateUpdate(); } } }; PlayerLoopSystem afterLateUpdate = new PlayerLoopSystem() { type = typeof(MagicaPhysicsManager), updateDelegate = () => { if (IsInstance()) { Instance.AfterLateUpdate(); } } }; PlayerLoopSystem postLateUpdate = new PlayerLoopSystem() { type = typeof(MagicaPhysicsManager), updateDelegate = () => { if (IsInstance()) { Instance.PostLateUpdate(); } } }; PlayerLoopSystem afterRendering = new PlayerLoopSystem() { type = typeof(MagicaPhysicsManager), updateDelegate = () => { if (IsInstance()) { Instance.AfterRendering(); } } }; // update int sysIndex = Array.FindIndex(playerLoop.subSystemList, (s) => s.type.Name == "Update"); PlayerLoopSystem updateSystem = playerLoop.subSystemList[sysIndex]; var updateSubsystemList = new List <PlayerLoopSystem>(updateSystem.subSystemList); int index = updateSubsystemList.FindIndex(h => h.type.Name.Contains("ScriptRunBehaviourUpdate")); updateSubsystemList.Insert(index + 1, afterUpdate); // Update() after updateSystem.subSystemList = updateSubsystemList.ToArray(); playerLoop.subSystemList[sysIndex] = updateSystem; // late update sysIndex = Array.FindIndex(playerLoop.subSystemList, (s) => s.type.Name == "PreLateUpdate"); PlayerLoopSystem lateUpdateSystem = playerLoop.subSystemList[sysIndex]; var lateUpdateSubsystemList = new List <PlayerLoopSystem>(lateUpdateSystem.subSystemList); index = lateUpdateSubsystemList.FindIndex(h => h.type.Name.Contains("ScriptRunBehaviourLateUpdate")); lateUpdateSubsystemList.Insert(index, beforeLateUpdate); // LateUpdate() before lateUpdateSubsystemList.Insert(index + 2, afterLateUpdate); // LateUpdate() after lateUpdateSystem.subSystemList = lateUpdateSubsystemList.ToArray(); playerLoop.subSystemList[sysIndex] = lateUpdateSystem; // post late update sysIndex = Array.FindIndex(playerLoop.subSystemList, (s) => s.type.Name == "PostLateUpdate"); PlayerLoopSystem postLateUpdateSystem = playerLoop.subSystemList[sysIndex]; var postLateUpdateSubsystemList = new List <PlayerLoopSystem>(postLateUpdateSystem.subSystemList); index = postLateUpdateSubsystemList.FindIndex(h => h.type.Name.Contains("ScriptRunDelayedDynamicFrameRate")); postLateUpdateSubsystemList.Insert(index + 1, postLateUpdate); // postLateUpdate() postLateUpdateSystem.subSystemList = postLateUpdateSubsystemList.ToArray(); playerLoop.subSystemList[sysIndex] = postLateUpdateSystem; // rendering sysIndex = Array.FindIndex(playerLoop.subSystemList, (s) => s.type.Name == "PostLateUpdate"); PlayerLoopSystem postLateSystem = playerLoop.subSystemList[sysIndex]; var postLateSubsystemList = new List <PlayerLoopSystem>(postLateSystem.subSystemList); index = postLateSubsystemList.FindIndex(h => h.type.Name.Contains("FinishFrameRendering")); postLateSubsystemList.Insert(index + 1, afterRendering); // rendering after postLateSystem.subSystemList = postLateSubsystemList.ToArray(); playerLoop.subSystemList[sysIndex] = postLateSystem; #if UNITY_2019_3_OR_NEWER PlayerLoop.SetPlayerLoop(playerLoop); #elif MAGICACLOTH_ECS // ECS併用 ScriptBehaviourUpdateOrder.SetPlayerLoop(playerLoop); #else PlayerLoop.SetPlayerLoop(playerLoop); #endif }