/// <summary> /// Adds a system to the player loop in the same way that <see cref="Unity.Entities.ScriptBehaviourUpdateOrder"/> does. /// /// One difference is that this does not check to see if the system is already added. It is up to the users of this /// method to ensure that they do not add systems multiple times. /// </summary> /// <param name="parent"> /// Must be one of the top level types already in the player loop such as /// <see cref="UnityEngine.PlayerLoop.FixedUpdate"/> or <see cref="UnityEngine.PlayerLoop.Update"/>. /// </param> /// <param name="system"> /// The system to be added to the player loop. /// </param> /// <exception cref="Exception"> /// An exception is thrown if the reflection components could not be initialized or the parent type was not in the player /// loop. /// </exception> public static void AddSubSystem(Type parent, ComponentSystemBase system) { ValidateReflectionComponents(); PlayerLoopSystem currentPlayerLoop = PlayerLoop.GetCurrentPlayerLoop(); for (int i = 0; i < currentPlayerLoop.subSystemList.Length; i++) { if (currentPlayerLoop.subSystemList[i].type == parent) { PlayerLoopSystem[] oldSubSystems = currentPlayerLoop.subSystemList[i].subSystemList; PlayerLoopSystem[] newSubSystems = new PlayerLoopSystem[oldSubSystems.Length + 1]; Array.Copy(oldSubSystems, newSubSystems, oldSubSystems.Length); newSubSystems[oldSubSystems.Length].type = system.GetType(); newSubSystems[oldSubSystems.Length].updateDelegate = CreateDummyWrapper(system); currentPlayerLoop.subSystemList[i].subSystemList = newSubSystems; PlayerLoop.SetPlayerLoop(currentPlayerLoop); return; } } throw new Exception($"Could not add {system.GetType().Name} to player loop. Are you sure {parent.Name} is in the player loop?"); }
public void OneTimeTearDown() { m_World.TearDown(); m_SubSceneTest.TearDown(); m_TempAssets.TearDown(); PlayerLoop.SetPlayerLoop(m_PrevPlayerLoop); }
/// <summary> /// Remove all of this World's systems from the currently active player loop. /// </summary> /// <remarks> /// This is a convenience wrapper around RemoveWorldToPlayerLoop() that retrieves the current player loop, /// removes a World's systems from it, and sets the modified copy as the new active player loop. /// /// Note that modifications to the active player loop do not take effect until to the next iteration through the player loop. /// </remarks> /// <param name="world">All systems in the current player loop owned by this World will be removed from the player loop.</param> public static void RemoveWorldFromCurrentPlayerLoop(World world) { var playerLoop = PlayerLoop.GetCurrentPlayerLoop(); RemoveWorldFromPlayerLoopSystem(world, ref playerLoop); PlayerLoop.SetPlayerLoop(playerLoop); }
public void RegisterCustomLoopInTheMiddle() { // caching the current PlayerLoop (to prevent side-effects on other tests) var cachedPlayerLoop = PlayerLoop.GetCurrentPlayerLoop(); { // since current PlayerLoop already took NetworkUpdateLoop systems inside, // we are going to swap it with the default PlayerLoop temporarily for testing PlayerLoop.SetPlayerLoop(PlayerLoop.GetDefaultPlayerLoop()); NetworkUpdateLoop.RegisterLoopSystems(); var curPlayerLoop = PlayerLoop.GetCurrentPlayerLoop(); int initSubsystemCount = curPlayerLoop.subSystemList[0].subSystemList.Length; var newInitSubsystems = new PlayerLoopSystem[initSubsystemCount + 1]; Array.Copy(curPlayerLoop.subSystemList[0].subSystemList, newInitSubsystems, initSubsystemCount); newInitSubsystems[initSubsystemCount] = new PlayerLoopSystem { type = typeof(NetworkUpdateLoopTests) }; curPlayerLoop.subSystemList[0].subSystemList = newInitSubsystems; PlayerLoop.SetPlayerLoop(curPlayerLoop); NetworkUpdateLoop.UnregisterLoopSystems(); // our custom `PlayerLoopSystem` with the type of `NetworkUpdateLoopTests` should still exist Assert.AreEqual(typeof(NetworkUpdateLoopTests), PlayerLoop.GetCurrentPlayerLoop().subSystemList[0].subSystemList.Last().type); } // replace the current PlayerLoop with the cached PlayerLoop after the test PlayerLoop.SetPlayerLoop(cachedPlayerLoop); }
static void Init() { System.Type[] profilePoints = { // script typeof(Update.ScriptRunBehaviourUpdate), typeof(PreLateUpdate.ScriptRunBehaviourLateUpdate), typeof(FixedUpdate.ScriptRunBehaviourFixedUpdate), // script (Coroutine) typeof(Update.ScriptRunDelayedDynamicFrameRate), // Animator typeof(PreLateUpdate.DirectorUpdateAnimationBegin), typeof(PreLateUpdate.DirectorUpdateAnimationEnd), // Renderer typeof(PostLateUpdate.UpdateAllRenderers), typeof(PostLateUpdate.UpdateAllSkinnedMeshes), // Rendering(require) typeof(PostLateUpdate.FinishFrameRendering), // Physics typeof(FixedUpdate.PhysicsFixedUpdate), }; var playerLoop = PlayerLoop.GetDefaultPlayerLoop(); AppendProfilingLoopSystem(ref playerLoop, profilePoints); PlayerLoop.SetPlayerLoop(playerLoop); }
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 }
private static void Setup() { // 計測する項目 Type[] profilePoints = { typeof(Initialization.PlayerUpdateTime), typeof(Update.ScriptRunBehaviourUpdate), typeof(PreLateUpdate.ScriptRunBehaviourLateUpdate), typeof(FixedUpdate.ScriptRunBehaviourFixedUpdate), typeof(Update.ScriptRunDelayedDynamicFrameRate), typeof(PreLateUpdate.DirectorUpdateAnimationBegin), typeof(PreLateUpdate.DirectorUpdateAnimationEnd), typeof(PostLateUpdate.UpdateAllRenderers), typeof(PostLateUpdate.UpdateAllSkinnedMeshes), typeof(PostLateUpdate.FinishFrameRendering), typeof(FixedUpdate.PhysicsFixedUpdate) }; PlayerLoopSystem playerLoop = PlayerLoop.GetDefaultPlayerLoop(); AppendProfilingLoopSystem(ref playerLoop, profilePoints); // 計測機能を追加したPlayerLoopをセットする PlayerLoop.SetPlayerLoop(playerLoop); }
private static void Initialize() { if (isInitialized) { return; } #if UNITY_2019_3_OR_NEWER var rootSystem = PlayerLoop.GetCurrentPlayerLoop(); #else var rootSystem = PlayerLoop.GetDefaultPlayerLoop(); #endif var fixedUpdateSystem = rootSystem.subSystemList.First(s => s.type == typeof(FixedUpdate)); var fixedUpdateList = new List <PlayerLoopSystem>(fixedUpdateSystem.subSystemList) { new PlayerLoopSystem { type = typeof(HttxUnityWebRequestReporterFixedUpdate), updateDelegate = UpdateFunctionImpl } }; fixedUpdateSystem.subSystemList = fixedUpdateList.ToArray(); rootSystem.subSystemList = rootSystem.subSystemList.Select(s => s.type == typeof(FixedUpdate) ? fixedUpdateSystem : s).ToArray(); PlayerLoop.SetPlayerLoop(rootSystem); isInitialized = 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; PlayerLoop.SetPlayerLoop(PreviousPlayerLoop); // 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); }
private ZuKit(string influxdbUrl, string dbName, Func <ZuValues> onUpdateValues) { this.onUpdateValues = onUpdateValues; this.influxdbUrl = influxdbUrl; this.dbName = dbName; this.writeHeader = influxdbUrl + "/write?db=" + dbName + "&precision=ns";// このZuKitはnsまで見たいのでnsまで見る。基本的には順番。 // 初期リクエストをセット requestEnum = DBCreateRequest(influxdbUrl, dbName); // メインスレッドで動作する機構をセットする。lateUpdateの後に動作する。 { var zuKitSendSystem = new PlayerLoopSystem() { type = typeof(ZuKit), updateDelegate = this.OnZuKitUpdate }; var playerLoop = PlayerLoop.GetDefaultPlayerLoop(); // updateのシステムを取得する var updateSystem = playerLoop.subSystemList[6];// postLateUpdate var subSystem = new List <PlayerLoopSystem>(updateSystem.subSystemList); // 送信用の処理を末尾にセットする subSystem.Add(zuKitSendSystem); updateSystem.subSystemList = subSystem.ToArray(); playerLoop.subSystemList[6] = updateSystem;// postLateUpdate // セット PlayerLoop.SetPlayerLoop(playerLoop); } }
public static void Initialize(ref PlayerLoopSystem playerLoop) { yielders = new ContinuationQueue[7]; runners = new PlayerLoopRunner[7]; var copyList = playerLoop.subSystemList.ToArray(); copyList[0].subSystemList = InsertRunner(copyList[0], typeof(UniTaskLoopRunners.UniTaskLoopRunnerYieldInitialization), yielders[0] ?? (yielders[0] = new ContinuationQueue()), typeof(UniTaskLoopRunners.UniTaskLoopRunnerInitialization), runners[0] ?? (runners[0] = new PlayerLoopRunner())); copyList[1].subSystemList = InsertRunner(copyList[1], typeof(UniTaskLoopRunners.UniTaskLoopRunnerYieldEarlyUpdate), yielders[1] ?? (yielders[1] = new ContinuationQueue()), typeof(UniTaskLoopRunners.UniTaskLoopRunnerEarlyUpdate), runners[1] ?? (runners[1] = new PlayerLoopRunner())); copyList[2].subSystemList = InsertRunner(copyList[2], typeof(UniTaskLoopRunners.UniTaskLoopRunnerYieldFixedUpdate), yielders[2] ?? (yielders[2] = new ContinuationQueue()), typeof(UniTaskLoopRunners.UniTaskLoopRunnerFixedUpdate), runners[2] ?? (runners[2] = new PlayerLoopRunner())); copyList[3].subSystemList = InsertRunner(copyList[3], typeof(UniTaskLoopRunners.UniTaskLoopRunnerYieldPreUpdate), yielders[3] ?? (yielders[3] = new ContinuationQueue()), typeof(UniTaskLoopRunners.UniTaskLoopRunnerPreUpdate), runners[3] ?? (runners[3] = new PlayerLoopRunner())); copyList[4].subSystemList = InsertRunner(copyList[4], typeof(UniTaskLoopRunners.UniTaskLoopRunnerYieldUpdate), yielders[4] ?? (yielders[4] = new ContinuationQueue()), typeof(UniTaskLoopRunners.UniTaskLoopRunnerUpdate), runners[4] ?? (runners[4] = new PlayerLoopRunner())); copyList[5].subSystemList = InsertRunner(copyList[5], typeof(UniTaskLoopRunners.UniTaskLoopRunnerYieldPreLateUpdate), yielders[5] ?? (yielders[5] = new ContinuationQueue()), typeof(UniTaskLoopRunners.UniTaskLoopRunnerPreLateUpdate), runners[5] ?? (runners[5] = new PlayerLoopRunner())); copyList[6].subSystemList = InsertRunner(copyList[6], typeof(UniTaskLoopRunners.UniTaskLoopRunnerYieldPostLateUpdate), yielders[6] ?? (yielders[6] = new ContinuationQueue()), typeof(UniTaskLoopRunners.UniTaskLoopRunnerPostLateUpdate), runners[6] ?? (runners[6] = new PlayerLoopRunner())); playerLoop.subSystemList = copyList; PlayerLoop.SetPlayerLoop(playerLoop); }
public static PlayerLoopSystem Build(PlayerLoopSystem.UpdateFunction update) { PlayerLoopSystem defaultSystem = PlayerLoop.GetCurrentPlayerLoop(); PlayerLoopSystem newSystem = new PlayerLoopSystem(); newSystem.updateDelegate += update; PlayerLoopSystem[] defaultLoopSystem = defaultSystem.subSystemList; if (defaultLoopSystem == null || defaultLoopSystem.Length < 1) { defaultLoopSystem = new PlayerLoopSystem[1] { newSystem }; defaultSystem.subSystemList = defaultLoopSystem; } else { PlayerLoopSystem[] newLoopSystem = new PlayerLoopSystem[defaultLoopSystem.Length + 1]; System.Array.Copy(defaultLoopSystem, 0, newLoopSystem, 0, defaultLoopSystem.Length); newLoopSystem[newLoopSystem.Length - 1] = newSystem; defaultSystem.subSystemList = newLoopSystem; } PlayerLoop.SetPlayerLoop(defaultSystem); return(newSystem); }
private static void SetupUpdate() { var loop = PlayerLoop.GetCurrentPlayerLoop(); PlayerLoopSystemUtil.AddSubSystem(ref loop, _loopSystem); PlayerLoop.SetPlayerLoop(loop); }
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(); }
private static void RegisterCallbackFunction() { // Prepare the function for using player loop. var myPlayerLoopSystem = new PlayerLoopSystem() { type = typeof(CubismModel), // Identifier for Profiler Hierarchy view. updateDelegate = OnModelsUpdate // Register the function. }; // Get the default player loop. var playerLoopSystem = PlayerLoop.GetCurrentPlayerLoop(); // Get the "PreLateUpdate" system. var playerLoopSubSystem = playerLoopSystem.subSystemList[5]; var subSystemList = playerLoopSubSystem.subSystemList; // Register the model update function after "PreLateUpdate" system. Array.Resize(ref subSystemList, subSystemList.Length + 1); subSystemList[subSystemList.Length - 1] = myPlayerLoopSystem; // Restore the "PreLateUpdate" sytem. playerLoopSubSystem.subSystemList = subSystemList; playerLoopSystem.subSystemList[5] = playerLoopSubSystem; PlayerLoop.SetPlayerLoop(playerLoopSystem); }
// 余計なプレイヤーループを消す関数 private static void RemoveUpdateSystem(System.Func <PlayerLoopSystem, bool> shouldExcludeFunc, bool removeAllPhysics) { var currentLoop = PlayerLoop.GetCurrentPlayerLoop(); var replaceSubSystems = new List <PlayerLoopSystem>(); var replaceUpdateSystems = new List <PlayerLoopSystem>(); foreach (var subsystem in currentLoop.subSystemList) { // 物理丸っと消したい人向け if (removeAllPhysics && subsystem.type == typeof(UnityEngine.PlayerLoop.FixedUpdate)) { continue; } replaceUpdateSystems.Clear(); var newSubSystem = subsystem; foreach (var updateSystem in subsystem.subSystemList) { if (!shouldExcludeFunc(updateSystem)) { replaceUpdateSystems.Add(updateSystem); } } newSubSystem.subSystemList = replaceUpdateSystems.ToArray(); replaceSubSystems.Add(newSubSystem); } currentLoop.subSystemList = replaceSubSystems.ToArray(); PlayerLoop.SetPlayerLoop(currentLoop); }
void OnApplicationQuit() { PlayerLoopSystem loopSystemRoot = PlayerLoop.GetCurrentPlayerLoop(); EditPhysics(ref loopSystemRoot, true); PlayerLoop.SetPlayerLoop(loopSystemRoot); }
internal static void DomainUnloadOrPlayModeChangeShutdown() { #if !UNITY_DOTSRUNTIME if (!s_UnloadOrPlayModeChangeShutdownRegistered) { return; } var playerLoop = PlayerLoop.GetCurrentPlayerLoop(); foreach (var w in World.s_AllWorlds) { ScriptBehaviourUpdateOrder.RemoveWorldFromPlayerLoop(w, ref playerLoop); } PlayerLoop.SetPlayerLoop(playerLoop); World.DisposeAllWorlds(); WordStorage.Instance.Dispose(); WordStorage.Instance = null; s_UnloadOrPlayModeChangeShutdownRegistered = false; DefaultWorldDestroyed?.Invoke(); #endif }
public virtual void TearDown() { if (World != null && World.IsCreated) { // Clean up systems before calling CheckInternalConsistency because we might have filters etc // holding on SharedComponentData making checks fail while (World.Systems.Count > 0) { World.DestroySystem(World.Systems[0]); } m_ManagerDebug.CheckInternalConsistency(); World.Dispose(); World = null; World.DefaultGameObjectInjectionWorld = m_PreviousWorld; m_PreviousWorld = null; m_Manager = default; } JobsUtility.JobDebuggerEnabled = JobsDebuggerWasEnabled; #if !UNITY_DOTSRUNTIME PlayerLoop.SetPlayerLoop(m_PreviousPlayerLoop); #endif }
public void RemovePresenter(IPresenterEvents presenter) { var loop = PlayerLoop.GetCurrentPlayerLoop(); for (var i = 0; i < loop.subSystemList.Length; i++) { var system = loop.subSystemList[i]; if (system.type == typeof(PlayerLoopTypes.Update)) { for (var j = 0; j < system.subSystemList.Length; j++) { if (system.subSystemList[j].type == typeof(Presenter) && system.updateDelegate?.Target == presenter) { var newSubSystems = new PlayerLoopSystem[system.subSystemList.Length - 1]; var n = 0; for (var k = 0; k < system.subSystemList.Length; k++) { if (k != j) { newSubSystems[n++] = system.subSystemList[k]; } } system.subSystemList = newSubSystems; loop.subSystemList[i] = system; PlayerLoop.SetPlayerLoop(loop); break; } } } } }
/// <summary> /// Inserts a new player loop system in the player loop, just after another system. /// </summary> /// <param name="toInsert">System to insert. Needs to have updateDelegate and Type set.</param> /// <param name="insertAfter">The subsystem to insert the system after</param> public static void InsertSystemAfter(PlayerLoopSystem toInsert, Type insertAfter) { if (toInsert.type == null) { throw new ArgumentException("The inserted player loop system must have a marker type!", nameof(toInsert.type)); } if (toInsert.updateDelegate == null) { throw new ArgumentException("The inserted player loop system must have an update delegate!", nameof(toInsert.updateDelegate)); } if (insertAfter == null) { throw new ArgumentNullException(nameof(insertAfter)); } var rootSystem = PlayerLoop.GetCurrentPlayerLoop(); InsertSystem(ref rootSystem, toInsert, insertAfter, InsertType.After, out var couldInsert); if (!couldInsert) { throw new ArgumentException($"When trying to insert the type {toInsert.type.Name} into the player loop after {insertAfter.Name}, " + $"{insertAfter.Name} could not be found in the current player loop!"); } insertedSystems.Add(toInsert); PlayerLoop.SetPlayerLoop(rootSystem); }
public static void Listen <T>(UpdateFunction updateFunction) { var updateSystems = PlayerLoop.GetCurrentPlayerLoop(); Listen <T>(ref updateSystems, updateFunction); PlayerLoop.SetPlayerLoop(updateSystems); }
public IEnumerator RegisterAndUnregisterSystems() { // caching the current PlayerLoop (it will have NetworkUpdateLoop systems registered) var cachedPlayerLoop = PlayerLoop.GetCurrentPlayerLoop(); { // since current PlayerLoop already took NetworkUpdateLoop systems inside, // we are going to swap it with the default PlayerLoop temporarily for testing PlayerLoop.SetPlayerLoop(PlayerLoop.GetDefaultPlayerLoop()); var oldPlayerLoop = PlayerLoop.GetCurrentPlayerLoop(); NetworkUpdateLoop.RegisterLoopSystems(); int nextFrameNumber = Time.frameCount + 1; yield return(new WaitUntil(() => Time.frameCount >= nextFrameNumber)); NetworkUpdateLoop.UnregisterLoopSystems(); var newPlayerLoop = PlayerLoop.GetCurrentPlayerLoop(); // recursively compare old and new PlayerLoop systems and their subsystems AssertAreEqualPlayerLoopSystems(newPlayerLoop, oldPlayerLoop); } // replace the current PlayerLoop with the cached PlayerLoop after the test PlayerLoop.SetPlayerLoop(cachedPlayerLoop); }
private void OnEnable() { var worldNameA = "BuildConfiguration Test World A"; var worldNameB = "BuildConfiguration Test World B"; World.DisposeAllWorlds(); DefaultWorldInitialization.Initialize(worldNameA, !Application.isPlaying); DefaultWorldInitialization.Initialize(worldNameB, !Application.isPlaying); foreach (var world in World.All) { if (worldA == null && world.Name == worldNameA) { worldA = world; } else if (worldB == null && world.Name == worldNameB) { worldB = world; } } OnValidate(); var playerLoop = PlayerLoop.GetDefaultPlayerLoop(); // TODO(DOTS-2283): shouldn't stomp the default player loop here ScriptBehaviourUpdateOrder.AddWorldToPlayerLoop(worldA, ref playerLoop); ScriptBehaviourUpdateOrder.AddWorldToPlayerLoop(worldB, ref playerLoop); PlayerLoop.SetPlayerLoop(playerLoop); }
public static void Hook() { if (alreadyHooked) { return; } alreadyHooked = true; var playerLoop = PlayerLoop.GetCurrentPlayerLoop(); var update = playerLoop.subSystemList[5]; var updateAsList = new List <PlayerLoopSystem>(update.subSystemList); int updateLoopIndex = -1; for (int i = 0; i < updateAsList.Count; i++) { if (updateAsList[i].type == typeof(PreLateUpdate.ScriptRunBehaviourLateUpdate)) { updateLoopIndex = i; break; } } updateAsList.Insert(updateLoopIndex + 1, new PlayerLoopSystem() { type = typeof(CoreLateUpdatePoller), updateDelegate = UpdateFunction }); update.subSystemList = updateAsList.ToArray(); playerLoop.subSystemList[5] = update; PlayerLoop.SetPlayerLoop(playerLoop); }
/// <summary> /// Inserts a new player loop system in the player loop, just before another system. /// </summary> /// <param name="toInsert">System to insert. Needs to have updateDelegate and Type set.</param> /// <param name="insertBefore">The subsystem to insert the system before</param> public static void InsertSystemBefore(PlayerLoopSystem toInsert, Type insertBefore) { if (toInsert.type == null) { throw new ArgumentException("The inserted player loop system must have a marker type!", nameof(toInsert.type)); } if (toInsert.updateDelegate == null) { throw new ArgumentException("The inserted player loop system must have an update delegate!", nameof(toInsert.updateDelegate)); } if (insertBefore == null) { throw new ArgumentNullException(nameof(insertBefore)); } EnsureSystemFetched(); InsertSystem(ref system, toInsert, insertBefore, InsertType.Before, out var couldInsert); if (!couldInsert) { throw new ArgumentException($"When trying to insert the type {toInsert.type.Name} into the player loop before {insertBefore.Name}, " + $"{insertBefore.Name} could not be found in the current player loop!"); } PlayerLoop.SetPlayerLoop(system); }
/// <summary> /// Add this World's three default top-level system groups to the current Unity player loop. /// </summary> /// <remarks> /// This is a convenience wrapper around AddWorldToPlayerLoop() that retrieves the current player loop, /// adds a World's top-level system groups to it, and sets the modified copy as the new active player loop. /// /// Note that modifications to the active player loop do not take effect until to the next iteration through the player loop. /// </remarks> /// <param name="world">The three top-level system groups from this World will be added to the provided player loop.</param> public static void AddWorldToCurrentPlayerLoop(World world) { var playerLoop = PlayerLoop.GetCurrentPlayerLoop(); AddWorldToPlayerLoop(world, ref playerLoop); PlayerLoop.SetPlayerLoop(playerLoop); }
public virtual void TearDown() { if (World != null && World.IsCreated) { EntityManager.CompleteAllJobs(); // Clean up systems before calling CheckInternalConsistency because we might have filters etc // holding on SharedComponentData making checks fail while (World.Systems.Count > 0) { World.DestroySystem(World.Systems[0]); } World.Dispose(); World = null; World.DefaultGameObjectInjectionWorld = _previousWorld; _previousWorld = null; EntityManager = default; } JobsUtility.JobDebuggerEnabled = _jobsDebuggerWasEnabled; PlayerLoop.SetPlayerLoop(_previousPlayerLoop); }
static void RuntimeInitializeOnLoad() { //Debug.Log("Mirror: adding Network[Early/Late]Update to Unity..."); // get loop // 2019 has GetCURRENTPlayerLoop which is safe to use without // breaking other custom system's custom loops. // see also: https://github.com/vis2k/Mirror/pull/2627/files PlayerLoopSystem playerLoop = #if UNITY_2019_3_OR_NEWER PlayerLoop.GetCurrentPlayerLoop(); #else PlayerLoop.GetDefaultPlayerLoop(); #endif // add NetworkEarlyUpdate to the end of EarlyUpdate so it runs after // any Unity initializations but before the first Update/FixedUpdate AddToPlayerLoop(NetworkEarlyUpdate, typeof(NetworkLoop), ref playerLoop, typeof(EarlyUpdate), AddMode.End); // add NetworkLateUpdate to the end of PreLateUpdate so it runs after // LateUpdate(). adding to the beginning of PostLateUpdate doesn't // actually work. AddToPlayerLoop(NetworkLateUpdate, typeof(NetworkLoop), ref playerLoop, typeof(PreLateUpdate), AddMode.End); // set the new loop PlayerLoop.SetPlayerLoop(playerLoop); }
public bool Initialize(string defaultWorldName) { // LineWorld.World = new LineWorld(); var loop = PlayerLoop.GetDefaultPlayerLoop(); if (!UpdateSystem <Update, LineWorldSimGroup>(ref loop)) { throw new Exception("Unable to set LineWorldSimGroup player loop"); } if (!UpdateSystem <PreLateUpdate, LineWorldPresGroup>(ref loop)) { throw new Exception("Unable to set LineWorldPresGroup player loop"); } if (!UpdateSystem <Initialization, LineWorldInitGroup>(ref loop)) { throw new Exception("Unable to set LineWorldInitGroup player loop"); } PlayerLoop.SetPlayerLoop(loop); LineWorld.World.Initialise(); return(true); }