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; } } } } }
public static void Listen <T>(UpdateFunction updateFunction) { var updateSystems = PlayerLoop.GetCurrentPlayerLoop(); Listen <T>(ref updateSystems, updateFunction); PlayerLoop.SetPlayerLoop(updateSystems); }
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 }
// [RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSceneLoad)] public static void Initialize() { lock (Runners) { if (initialized) { return; } initialized = true; } for (var i = 0; i < Runners.Length; i++) { Runners[i] = new PlayerLoopRunner(); } var playerLoop = #if UNITY_2019_3_OR_NEWER PlayerLoop.GetCurrentPlayerLoop(); #else PlayerLoop.GetDefaultPlayerLoop(); #endif var copyList = playerLoop.subSystemList; ref var initializeSystem = ref FindSubSystem(typeof(Initialization), copyList);
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; }
// 余計なプレイヤーループを消す関数 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); }
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); }
protected void OnGUI() { playerLoopSystem = PlayerLoop.GetCurrentPlayerLoop(); scrollPos = EditorGUILayout.BeginScrollView(scrollPos); if (firstCall) { leftBold = new GUIStyle() { alignment = TextAnchor.MiddleLeft, fontStyle = FontStyle.Bold }; normalCenter = new GUIStyle() { alignment = TextAnchor.MiddleCenter }; firstCall = false; } foreach (var header in playerLoopSystem.subSystemList) { EditorGUILayout.BeginVertical(GUI.skin.box); GUILayout.Label(header.type.Name, leftBold); foreach (var subSystem in header.subSystemList) { GUILayout.Label(subSystem.type.Name, normalCenter); } EditorGUILayout.EndVertical(); } EditorGUILayout.EndScrollView(); }
private static void SetupUpdate() { var loop = PlayerLoop.GetCurrentPlayerLoop(); PlayerLoopSystemUtil.AddSubSystem(ref loop, _loopSystem); PlayerLoop.SetPlayerLoop(loop); }
public 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), }; #if UNITY_2019_3_OR_NEWER var playerLoop = PlayerLoop.GetCurrentPlayerLoop(); #else var playerLoop = PlayerLoop.GetDefaultPlayerLoop(); #endif AppendProfilingLoopSystem(ref playerLoop, profilePoints); PlayerLoop.SetPlayerLoop(playerLoop); }
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(); }
internal void TryRestorePreviousSelection(bool showingPlayerLoop, string lastSelectedWorldName) { if (!showingPlayerLoop && PlayerLoop.GetCurrentPlayerLoop().subSystemList != null) { if (lastSelectedWorldName == kNoWorldName) { if (World.All.Count > 0) { setWorldSelection(World.All[0]); } } else { foreach (var world in World.All) { if (world.Name != lastSelectedWorldName) { continue; } setWorldSelection(world); return; } } } }
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); }
public void Setup() { m_PrevPlayerLoop = PlayerLoop.GetCurrentPlayerLoop(); m_CustomInjectionWorld.Setup(); DefaultWorldInitialization.Initialize("TestWorld", false); m_World = World.DefaultGameObjectInjectionWorld; }
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 }
void BuildNodeTree() { systemsById.Clear(); worldsById.Clear(); recordersBySystem.Clear(); hideNodesById.Clear(); var currentID = kAllEntitiesItemId + 1; lastPlayerLoop = PlayerLoop.GetCurrentPlayerLoop(); rootNode = BuildNodesForPlayerLoopSystem(lastPlayerLoop, ref currentID) ?? new HideNode(new TreeViewItem { id = currentID, displayName = "Root" }); if (EntityDebugger.extraSystems != null) { foreach (var system in EntityDebugger.extraSystems) { if (system != null) { AddNodeIgnoreNulls(ref rootNode.Children, BuildNodesForComponentSystem(system, ref currentID)); } } } }
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); }
/// <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); }
/// <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 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); }
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 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 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); }
internal static void ValidateCurrentGraph(bool force = false) { var shouldRun = k_Cooldown.Update(DateTime.Now); if (!force && !shouldRun) { return; } foreach (var recorder in Current.RecordersBySystem.Values) { recorder.Update(); } var graph = new PlayerLoopSystemGraph(); ParsePlayerLoopSystem(PlayerLoop.GetCurrentPlayerLoop(), graph); if (!DidChange(Current, graph)) { graph.Reset(); return; } Current.Reset(); Current = graph; OnGraphChanged?.Invoke(); }
// [MenuItem("Test/Output current state to file")] private static void OutputCurrentStateToFile() { var str = PrintSystemToString(PlayerLoop.GetCurrentPlayerLoop()); Debug.Log(str); File.WriteAllText("playerLoopInterfaceOutput.txt", str); }
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 }
static void Init() { // capture default(unity) sync-context. unitySynchronizationContetext = SynchronizationContext.Current; mainThreadId = Thread.CurrentThread.ManagedThreadId; #if UNITY_EDITOR && UNITY_2019_3_OR_NEWER // When domain reload is disabled, re-initialization is required when entering play mode; // otherwise, pending tasks will leak between play mode sessions. var domainReloadDisabled = UnityEditor.EditorSettings.enterPlayModeOptionsEnabled && UnityEditor.EditorSettings.enterPlayModeOptions.HasFlag(UnityEditor.EnterPlayModeOptions.DisableDomainReload); if (!domainReloadDisabled && runners != null) { return; } #else if (runners != null) { return; // already initialized } #endif var playerLoop = #if UNITY_2019_3_OR_NEWER PlayerLoop.GetCurrentPlayerLoop(); #else PlayerLoop.GetDefaultPlayerLoop(); #endif Initialize(ref playerLoop); }
void OnApplicationQuit() { PlayerLoopSystem loopSystemRoot = PlayerLoop.GetCurrentPlayerLoop(); EditPhysics(ref loopSystemRoot, true); PlayerLoop.SetPlayerLoop(loopSystemRoot); }
/// <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?"); }
void OnGUI() { PlayerLoopSystem loop = PlayerLoop.GetCurrentPlayerLoop(); scrollPos = EditorGUILayout.BeginScrollView(scrollPos); DrawSystem(ref loop); EditorGUILayout.EndScrollView(); }