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 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 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); }
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); }
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); } }
private static PlayerLoopSystem GenerateCustomLoop() { // Note: this also resets the loop to its defalt state first. var playerLoop = PlayerLoop.GetDefaultPlayerLoop(); for (int i = 0; i < playerLoop.subSystemList.Length; ++i) { var subSystem = playerLoop.subSystemList[i]; // FixedUpdateの中身消します if (subSystem.type == typeof(FixedUpdate)) { subSystem.subSystemList = CreateSubSystems(); } // PreLateUpdateの中身消します if (subSystem.type == typeof(PreLateUpdate)) { subSystem.subSystemList = CreateSubSystems(typeof(UnityEngine.Experimental.PlayerLoop.PreLateUpdate.EndGraphicsJobsLate)); } // Preupdateも大体削る else if (subSystem.type == typeof(PreUpdate)) { subSystem.subSystemList = CreateSubSystems(typeof(UnityEngine.Experimental.PlayerLoop.PreUpdate.CheckTexFieldInput)); } else { continue; } // 構造体なので上書きしないとセットされないです playerLoop.subSystemList[i] = subSystem; } return(playerLoop); }
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); }
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); }
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); }
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 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); }
PlayerLoopSystem GenerateCustomLoop() { // Note: this also resets the loop to its defalt state first. var playerLoop = PlayerLoop.GetDefaultPlayerLoop(); hasCustomPlayerLoop = true; // Grab the 4th subsystem - This is the man Update Phase var update = playerLoop.subSystemList[4]; // convert the subsytem array to a List to make it easier to work with... var newList = new List <PlayerLoopSystem>(update.subSystemList); // add a demo system to the start of it (implementation at the end of this file) PlayerLoopSystem beginUpdateSystem = new PlayerLoopSystem(); beginUpdateSystem.type = typeof(CustomPlayerLoopStartUpdate); // Unity uses the name of the type here to identify the System - we would see this show up in the Profiler for example beginUpdateSystem.updateDelegate = CustomPlayerLoopStartUpdate.UpdateFunction; // we can plug a C# method into this delegate to control what actually happens when this System updates newList.Insert(0, beginUpdateSystem); // Finally lets insert it into the front! // Also lets put one on the end (implementation at the end of this file) newList.Add(CustomPlayerLoopEndUpdate.GetNewSystem()); // this time, lets use a small static helper method i added to the Systems type to generate the PlayerLoopSystem. this pattern is much cleaner :) // convert the list back to an array and plug it into the Update system. update.subSystemList = newList.ToArray(); // dont forget to put our newly edited System back into the main player loop system!! playerLoop.subSystemList[4] = update; return(playerLoop); }
// [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 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.GetDefaultPlayerLoop(); // 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 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); }
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 Task InitAsync() { // ReSharper disable PossibleNullReferenceException IsComponentAlive = true; m_UnturnedCommandHandler.Subscribe(); BindUnturnedEvents(); var ioHandlers = (List <ICommandInputOutput>) typeof(CommandWindow) .GetField("ioHandlers", BindingFlags.NonPublic | BindingFlags.Instance) .GetValue(Dedicator.commandWindow); /* Fix Unturned destroying console and breaking Serilog formatting and colors */ var shouldManageConsoleField = typeof(WindowsConsole).GetField("shouldManageConsole", BindingFlags.Static | BindingFlags.NonPublic); var shouldManageConsole = (CommandLineFlag)shouldManageConsoleField.GetValue(null); shouldManageConsole.value = false; // unturned built-in io handlers var defaultIoHandlers = ioHandlers.Where(c => c.GetType() == typeof(ThreadedWindowsConsoleInputOutput) || c.GetType() == typeof(WindowsConsoleInputOutput) || c.GetType() == typeof(ThreadedConsoleInputOutput) || c.GetType() == typeof(ConsoleInputOutput)).ToList(); foreach (var ioHandler in defaultIoHandlers) { Dedicator.commandWindow.removeIOHandler(ioHandler); } if (PlatformHelper.IsLinux) { Dedicator.commandWindow.addIOHandler(new SerilogConsoleInputOutput(m_LoggerFactory)); } else { Dedicator.commandWindow.addIOHandler(new SerilogWindowsConsoleInputOutput(m_LoggerFactory)); } m_Logger.LogInformation($"OpenMod for Unturned v{Version} is initializing..."); m_Harmony.PatchAll(typeof(OpenModUnturnedHost).Assembly); TlsWorkaround.Install(); var unitySynchronizationContetextField = typeof(PlayerLoopHelper).GetField("unitySynchronizationContetext", BindingFlags.Static | BindingFlags.NonPublic); unitySynchronizationContetextField.SetValue(null, SynchronizationContext.Current); var mainThreadIdField = typeof(PlayerLoopHelper).GetField("mainThreadId", BindingFlags.Static | BindingFlags.NonPublic); mainThreadIdField.SetValue(null, Thread.CurrentThread.ManagedThreadId); var playerLoop = PlayerLoop.GetDefaultPlayerLoop(); PlayerLoopHelper.Initialize(ref playerLoop); m_Logger.LogInformation("OpenMod for Unturned is ready."); return(Task.CompletedTask); // ReSharper restore PossibleNullReferenceException }
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); }
private void InsertToPlayerLoop() { var type = typeof(PostLateUpdate.PlayerUpdateCanvases); var playerLoop = PlayerLoop.GetDefaultPlayerLoop(); AppendProfilingLoopSystem(ref playerLoop, type); PlayerLoop.SetPlayerLoop(playerLoop); }
static private void Integrate() { var loop = PlayerLoop.GetDefaultPlayerLoop(); loop = PatchSystem(loop, 0, loop.updateFunction); PlayerLoop.SetPlayerLoop(loop); }
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)); } }
public static void PhysicsON() { var playerLoop = PlayerLoop.GetDefaultPlayerLoop(); var sub = playerLoop.subSystemList[2]; sub.subSystemList = originalPlayerLoop; playerLoop.subSystemList[2] = sub; PlayerLoop.SetPlayerLoop(playerLoop); }
public static void PhysicsOFF() { var playerLoop = PlayerLoop.GetDefaultPlayerLoop(); var sub = playerLoop.subSystemList[2]; sub.subSystemList = updatedPlayerLoop; playerLoop.subSystemList[2] = sub; PlayerLoop.SetPlayerLoop(playerLoop); }
static void RuntimeStart() { var defaultPlayerLoop = PlayerLoop.GetDefaultPlayerLoop(); // Assumptions: project does not use: // XR, Analytics, WebRequest, Kinect, TangoUpdate, iOS, TextureStreaming, Audio, Physics2D, Wind, // Video, Pathfinding, runtime Substance, Englighten, VFX, PhysicsCloth, // ParticleSystems, ScreenCapture. // If one of those are used in the project, appropriate lines removing such functionality system updates should be commented out. RemoveEngineLoopSystem <Initialization.XREarlyUpdate>(ref defaultPlayerLoop); RemoveEngineLoopSystem <EarlyUpdate.AnalyticsCoreStatsUpdate>(ref defaultPlayerLoop); RemoveEngineLoopSystem <EarlyUpdate.UnityWebRequestUpdate>(ref defaultPlayerLoop); RemoveEngineLoopSystem <EarlyUpdate.UpdateAllUnityWebStreams>(ref defaultPlayerLoop); RemoveEngineLoopSystem <EarlyUpdate.XRUpdate>(ref defaultPlayerLoop); RemoveEngineLoopSystem <EarlyUpdate.ProcessRemoteInput>(ref defaultPlayerLoop); RemoveEngineLoopSystem <EarlyUpdate.TangoUpdate>(ref defaultPlayerLoop); RemoveEngineLoopSystem <EarlyUpdate.UpdateKinect>(ref defaultPlayerLoop); RemoveEngineLoopSystem <EarlyUpdate.DeliverIosPlatformEvents>(ref defaultPlayerLoop); RemoveEngineLoopSystem <EarlyUpdate.SpriteAtlasManagerUpdate>(ref defaultPlayerLoop); RemoveEngineLoopSystem <EarlyUpdate.UpdateStreamingManager>(ref defaultPlayerLoop); RemoveEngineLoopSystem <EarlyUpdate.UpdateTextureStreamingManager>(ref defaultPlayerLoop); RemoveEngineLoopSystem <FixedUpdate.AudioFixedUpdate>(ref defaultPlayerLoop); RemoveEngineLoopSystem <FixedUpdate.XRFixedUpdate>(ref defaultPlayerLoop); RemoveEngineLoopSystem <FixedUpdate.Physics2DFixedUpdate>(ref defaultPlayerLoop); RemoveEngineLoopSystem <PreUpdate.Physics2DUpdate>(ref defaultPlayerLoop); RemoveEngineLoopSystem <PreUpdate.AIUpdate>(ref defaultPlayerLoop); RemoveEngineLoopSystem <PreUpdate.WindUpdate>(ref defaultPlayerLoop); RemoveEngineLoopSystem <PreUpdate.UpdateVideo>(ref defaultPlayerLoop); RemoveEngineLoopSystem <PreLateUpdate.AIUpdatePostScript>(ref defaultPlayerLoop); RemoveEngineLoopSystem <PreLateUpdate.UNetUpdate>(ref defaultPlayerLoop); RemoveEngineLoopSystem <PreLateUpdate.UpdateMasterServerInterface>(ref defaultPlayerLoop); RemoveEngineLoopSystem <PreLateUpdate.UpdateNetworkManager>(ref defaultPlayerLoop); RemoveEngineLoopSystem <PreLateUpdate.ParticleSystemBeginUpdateAll>(ref defaultPlayerLoop); RemoveEngineLoopSystem <PostLateUpdate.UpdateAudio>(ref defaultPlayerLoop); RemoveEngineLoopSystem <PostLateUpdate.UpdateVideo>(ref defaultPlayerLoop); RemoveEngineLoopSystem <PostLateUpdate.UpdateSubstance>(ref defaultPlayerLoop); RemoveEngineLoopSystem <PostLateUpdate.UpdateVideoTextures>(ref defaultPlayerLoop); RemoveEngineLoopSystem <PostLateUpdate.EnlightenRuntimeUpdate>(ref defaultPlayerLoop); RemoveEngineLoopSystem <PostLateUpdate.VFXUpdate>(ref defaultPlayerLoop); RemoveEngineLoopSystem <PostLateUpdate.XRPostPresent>(ref defaultPlayerLoop); RemoveEngineLoopSystem <PostLateUpdate.ProcessWebSendMessages>(ref defaultPlayerLoop); RemoveEngineLoopSystem <PostLateUpdate.ExecuteGameCenterCallbacks>(ref defaultPlayerLoop); RemoveEngineLoopSystem <PostLateUpdate.PhysicsSkinnedClothBeginUpdate>(ref defaultPlayerLoop); RemoveEngineLoopSystem <PostLateUpdate.PhysicsSkinnedClothFinishUpdate>(ref defaultPlayerLoop); RemoveEngineLoopSystem <PostLateUpdate.UpdateCaptureScreenshot>(ref defaultPlayerLoop); RemoveEngineLoopSystem <PostLateUpdate.ParticleSystemEndUpdateAll>(ref defaultPlayerLoop); PlayerLoop.SetPlayerLoop(defaultPlayerLoop); Debug.Log("Setup of CustomOTCEngineLoop done."); }
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)); } }
static void Init() { if (runners != null) { return; // already initialized } var playerLoop = PlayerLoop.GetDefaultPlayerLoop(); Initialize(ref playerLoop); }
static void Init() { // capture default(unity) sync-context. unitySynchronizationContetext = SynchronizationContext.Current; mainThreadId = Thread.CurrentThread.ManagedThreadId; if (runners != null) return; // already initialized var playerLoop = PlayerLoop.GetDefaultPlayerLoop(); Initialize(ref playerLoop); }
/// <summary> /// Update the PlayerLoop to run simulation after rendering. /// </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 UpdatePlayerLoopWithDelayedSimulation(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 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(PostLateUpdate)) { 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; } } } PlayerLoop.SetPlayerLoop(playerLoop); }
public void AppendSystemToPlayerLoopList_AddToNestedList_Works() { using (var world = new World("Test World")) { var playerLoop = PlayerLoop.GetDefaultPlayerLoop(); var sys = world.CreateSystem <TestSystem>(); Type targetStageType = typeof(PreLateUpdate.LegacyAnimationUpdate); ScriptBehaviourUpdateOrder.AppendSystemToPlayerLoopList(sys, ref playerLoop, targetStageType); ValidatePostAppendPlayerLoop(playerLoop, targetStageType, sys); } }
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); }