protected override void OnUpdate() { if (Input.GetKeyDown(KeyCode.W)) { var newWorld = new World("TurboWorld"); var playerLoop = PlayerLoop.GetCurrentPlayerLoop(); ScriptBehaviourUpdateOrder.AddWorldToPlayerLoop(newWorld, ref playerLoop); var turboManager = newWorld.EntityManager; var newEnt = turboManager.CreateEntity(); turboManager.AddComponent <BravoTag>(newEnt); //var newSys = newWorld.GetOrCreateSystem<TestSystem2>(); newWorld.AddSystem(new TestSystem2()); //newWorld.AddSystem(newSys); } }
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] = new ContinuationQueue(), typeof(UniTaskLoopRunners.UniTaskLoopRunnerInitialization), runners[0] = new PlayerLoopRunner()); copyList[1].subSystemList = InsertRunner(copyList[1], typeof(UniTaskLoopRunners.UniTaskLoopRunnerYieldEarlyUpdate), yielders[1] = new ContinuationQueue(), typeof(UniTaskLoopRunners.UniTaskLoopRunnerEarlyUpdate), runners[1] = new PlayerLoopRunner()); copyList[2].subSystemList = InsertRunner(copyList[2], typeof(UniTaskLoopRunners.UniTaskLoopRunnerYieldFixedUpdate), yielders[2] = new ContinuationQueue(), typeof(UniTaskLoopRunners.UniTaskLoopRunnerFixedUpdate), runners[2] = new PlayerLoopRunner()); copyList[3].subSystemList = InsertRunner(copyList[3], typeof(UniTaskLoopRunners.UniTaskLoopRunnerYieldPreUpdate), yielders[3] = new ContinuationQueue(), typeof(UniTaskLoopRunners.UniTaskLoopRunnerPreUpdate), runners[3] = new PlayerLoopRunner()); copyList[4].subSystemList = InsertRunner(copyList[4], typeof(UniTaskLoopRunners.UniTaskLoopRunnerYieldUpdate), yielders[4] = new ContinuationQueue(), typeof(UniTaskLoopRunners.UniTaskLoopRunnerUpdate), runners[4] = new PlayerLoopRunner()); copyList[5].subSystemList = InsertRunner(copyList[5], typeof(UniTaskLoopRunners.UniTaskLoopRunnerYieldPreLateUpdate), yielders[5] = new ContinuationQueue(), typeof(UniTaskLoopRunners.UniTaskLoopRunnerPreLateUpdate), runners[5] = new PlayerLoopRunner()); copyList[6].subSystemList = InsertRunner(copyList[6], typeof(UniTaskLoopRunners.UniTaskLoopRunnerYieldPostLateUpdate), yielders[6] = new ContinuationQueue(), typeof(UniTaskLoopRunners.UniTaskLoopRunnerPostLateUpdate), runners[6] = new PlayerLoopRunner()); playerLoop.subSystemList = copyList; PlayerLoop.SetPlayerLoop(playerLoop); }
public void RemoveFromPlayerLoop_OtherWorldsInPlayerLoop_NotAffected() { using (var worldA = new World("Test World A")) using (var worldB = new World("Test World B")) { worldA.CreateSystem <InitializationSystemGroup>(); worldB.CreateSystem <InitializationSystemGroup>(); var playerLoop = PlayerLoop.GetDefaultPlayerLoop(); ScriptBehaviourUpdateOrder.AddWorldToPlayerLoop(worldA, ref playerLoop); ScriptBehaviourUpdateOrder.AddWorldToPlayerLoop(worldB, ref playerLoop); Assert.IsTrue(ScriptBehaviourUpdateOrder.IsWorldInPlayerLoop(worldA, playerLoop)); Assert.IsTrue(ScriptBehaviourUpdateOrder.IsWorldInPlayerLoop(worldB, playerLoop)); ScriptBehaviourUpdateOrder.RemoveWorldFromPlayerLoop(worldA, ref playerLoop); Assert.IsFalse(ScriptBehaviourUpdateOrder.IsWorldInPlayerLoop(worldA, playerLoop)); Assert.IsTrue(ScriptBehaviourUpdateOrder.IsWorldInPlayerLoop(worldB, playerLoop)); } }
static void Init() { // capture default(unity) sync-context. unitySynchronizationContetext = SynchronizationContext.Current; mainThreadId = Thread.CurrentThread.ManagedThreadId; if (runners != null) { return; // already initialized } var playerLoop = #if UNITY_2019_3_OR_NEWER PlayerLoop.GetCurrentPlayerLoop(); #else PlayerLoop.GetDefaultPlayerLoop(); #endif Initialize(ref playerLoop); }
private IEnumerator DelayedDisposeServices() { yield return(null); PlayerLoop.SetPlayerLoop(PlayerLoop.GetDefaultPlayerLoop()); Resources.UnloadUnusedAssets(); GC.Collect(GC.MaxGeneration, GCCollectionMode.Forced, true, false); GC.WaitForPendingFinalizers(); ServiceContainer.Dispose(); #if UNITY_EDITOR UnityEditor.EditorApplication.isPlaying = false; #else Application.Quit(); #endif }
private void OnEnable() { var worldNameA = "BuildSettings Test World A"; var worldNameB = "BuildSettings Test World B"; World.DisposeAllWorlds(); DefaultWorldInitialization.Initialize(worldNameA, !Application.isPlaying); DefaultWorldInitialization.Initialize(worldNameB, !Application.isPlaying); worldA = World.AllWorlds.First(w => w.Name == worldNameA); worldB = World.AllWorlds.First(w => w.Name == worldNameB); OnValidate(); //@TODO: This API is confusing. Should be way more explicit. // Current API makes it very easy to have the same system injected multiple times ScriptBehaviourUpdateOrder.UpdatePlayerLoop(worldA, null); ScriptBehaviourUpdateOrder.UpdatePlayerLoop(worldB, PlayerLoop.GetCurrentPlayerLoop()); }
// Start is called before the first frame update public void Setup() { if (Application.IsPlaying(gameObject)) { DontDestroyOnLoad(gameObject); PlayerLoopSystem loopSystemRoot = PlayerLoop.GetCurrentPlayerLoop(); EditPhysics(ref loopSystemRoot, false); //physicsLoopSystem. //physicsLoopSystem.updateDelegate PlayerLoop.SetPlayerLoop(loopSystemRoot); //Debug.Log(PhysXLib.AddNumberses(12, 7)); } }
public bool Initialize(string defaultWorldName) { var world = new LatiosWorld(defaultWorldName); World.DefaultGameObjectInjectionWorld = world; world.useExplicitSystemOrdering = true; var initializationSystemGroup = world.initializationSystemGroup; var simulationSystemGroup = world.simulationSystemGroup; var presentationSystemGroup = world.presentationSystemGroup; var systems = new List <Type>(DefaultWorldInitialization.GetAllSystems(WorldSystemFilterFlags.Default)); systems.RemoveSwapBack(typeof(LatiosInitializationSystemGroup)); systems.RemoveSwapBack(typeof(LatiosSimulationSystemGroup)); systems.RemoveSwapBack(typeof(LatiosPresentationSystemGroup)); systems.RemoveSwapBack(typeof(InitializationSystemGroup)); systems.RemoveSwapBack(typeof(SimulationSystemGroup)); systems.RemoveSwapBack(typeof(PresentationSystemGroup)); BootstrapTools.InjectUnitySystems(systems, world, simulationSystemGroup); BootstrapTools.InjectRootSuperSystems(systems, world, simulationSystemGroup); initializationSystemGroup.SortSystems(); simulationSystemGroup.SortSystems(); presentationSystemGroup.SortSystems(); //Reset playerloop so we don't infinitely add systems. PlayerLoop.SetPlayerLoop(PlayerLoop.GetDefaultPlayerLoop()); var beforeGpuProfiling = world.CreateSystem <Lsss.Tools.BeginGpuWaitProfilingSystem>(); var afterGpuProfiling = world.CreateSystem <Lsss.Tools.EndGpuWaitProfilingSystem>(); BootstrapTools.AddWorldToCurrentPlayerLoopWithDelayedSimulation(world); var loop = PlayerLoop.GetCurrentPlayerLoop(); #if UNITY_EDITOR ScriptBehaviourUpdateOrder.AppendSystemToPlayerLoopList(beforeGpuProfiling, ref loop, typeof(PostLateUpdate)); #else ScriptBehaviourUpdateOrder.AppendSystemToPlayerLoopList(beforeGpuProfiling, ref loop, typeof(UnityEngine.PlayerLoop.PostLateUpdate.PlayerEmitCanvasGeometry)); #endif PlayerLoop.SetPlayerLoop(loop); return(true); }
static void InsertPlayerLoopSystem() { var customSystem = new PlayerLoopSystem() { type = typeof(MemoryPool), updateDelegate = OnEndOfFrame }; var playerLoop = PlayerLoop.GetCurrentPlayerLoop(); for (var i = 0; i < playerLoop.subSystemList.Length; i++) { ref var phase = ref playerLoop.subSystemList[i]; if (phase.type == typeof(UnityEngine.PlayerLoop.PostLateUpdate)) { phase.subSystemList = phase.subSystemList .Concat(new [] { customSystem }).ToArray(); break; } }
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); }
private static void SetupHook() { if (!Application.isPlaying) { return; } var loop = PlayerLoop.GetCurrentPlayerLoop(); for (var i = 0; i < loop.subSystemList.Length; ++i) { if (loop.subSystemList[i].type == typeof(Initialization)) { loop.subSystemList[i].updateDelegate += InitOpenLoader; } } PlayerLoop.SetPlayerLoop(loop); }
private void SetStuff(World world) { var playerLoop = PlayerLoop.GetCurrentPlayerLoop(); for (int i = 0; i < playerLoop.subSystemList.Length; i++) { ComponentSystemGroup mgr; var group = playerLoop.subSystemList[i]; if (@group.type == typeof(FixedUpdate)) { mgr = world.GetOrCreateSystem <SimulationSystemGroup>(); } else if (@group.type == typeof(PreLateUpdate)) { mgr = world.GetOrCreateSystem <PresentationSystemGroup>(); } else if (@group.type == typeof(Initialization)) { mgr = world.GetOrCreateSystem <InitializationSystemGroup>(); } else { continue; } var newSubsystemList = new PlayerLoopSystem[@group.subSystemList.Length + 1]; for (var ii = 0; ii < @group.subSystemList.Length; ++ii) { newSubsystemList[ii] = @group.subSystemList[ii]; } insertManagerIntoSubsystemListMethod.MakeGenericMethod(mgr.GetType()) .Invoke(null, new object[] { newSubsystemList, @group.subSystemList.Length + 0, mgr }); playerLoop.subSystemList[i].subSystemList = newSubsystemList; } PlayerLoop.SetPlayerLoop(playerLoop); }
public override void Setup() { base.Setup(); #if !UNITY_DOTSRUNTIME // unit tests preserve the current player loop to restore later, and start from a blank slate. m_PreviousPlayerLoop = PlayerLoop.GetCurrentPlayerLoop(); PlayerLoop.SetPlayerLoop(PlayerLoop.GetDefaultPlayerLoop()); #endif m_PreviousWorld = World.DefaultGameObjectInjectionWorld; World = World.DefaultGameObjectInjectionWorld = new World("Test World"); m_Manager = World.EntityManager; m_ManagerDebug = new EntityManager.EntityManagerDebug(m_Manager); // Many ECS tests will only pass if the Jobs Debugger enabled; // force it enabled for all tests, and restore the original value at teardown. JobsDebuggerWasEnabled = JobsUtility.JobDebuggerEnabled; JobsUtility.JobDebuggerEnabled = true; }
// [RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.SubsystemRegistration)] public static void Inject() { var system = PlayerLoop.GetCurrentPlayerLoop(); for (int i = 0; i < system.subSystemList.Length; i++) { var loop = system.subSystemList[i].subSystemList.SelectMany(x => { var t = typeof(WrapLoop <>).MakeGenericType(x.type); var instance = (ILoopRunner)Activator.CreateInstance(t, x.type); return(new[] { new PlayerLoopSystem { type = t, updateDelegate = instance.Run }, x }); }).ToArray(); system.subSystemList[i].subSystemList = loop; } PlayerLoop.SetPlayerLoop(system); }
public static void Shutdown() { // shutdown ECS var playerLoop = PlayerLoop.GetCurrentPlayerLoop(); foreach (var w in World.All) { ScriptBehaviourUpdateOrder.RemoveWorldFromPlayerLoop(w, ref playerLoop); } PlayerLoop.SetPlayerLoop(playerLoop); World.DisposeAllWorlds(); WordStorage.Instance.Dispose(); WordStorage.Instance = null; // clean module Clean(); }
static void InsertPlayerLoopSystem() { var customSystem = new PlayerLoopSystem() { type = typeof(MidiSystemWrangler), updateDelegate = () => _driver?.Update() }; var playerLoop = PlayerLoop.GetCurrentPlayerLoop(); for (var i = 0; i < playerLoop.subSystemList.Length; i++) { ref var phase = ref playerLoop.subSystemList[i]; if (phase.type == typeof(UnityEngine.PlayerLoop.EarlyUpdate)) { phase.subSystemList = phase.subSystemList.Concat(new [] { customSystem }).ToArray(); break; } }
public static void SetupLateAwake(Corner corner) { // 初期化順リストに追加 hookObject.uninitialized.Add(corner); // 現行のplayerLoopにLateAwakeをcallするタイミングを追加 var currentPlayerLoop = PlayerLoop.GetCurrentPlayerLoop(); var currentPlayerLoopSubSystems = currentPlayerLoop.subSystemList; for (var i = 0; i < currentPlayerLoopSubSystems.Length; i++) { var system = currentPlayerLoopSubSystems[i]; if (system.type == typeof(UnityEngine.PlayerLoop.Initialization)) { var targetSystemList = system.subSystemList.ToList(); if (targetSystemList.Where(sys => sys.type == typeof(LateAwakeSystem)).Any()) { // すでにセットされているので何もしない return; } var initializer = new PlayerLoopSystem() { type = typeof(LateAwakeSystem), updateDelegate = hookObject.LateAwake }; // 先頭に導入 initializer が先頭に来るようにすると、このフレームで着火する。 targetSystemList.Insert(0, initializer); // 上書き currentPlayerLoopSubSystems[i].subSystemList = targetSystemList.ToArray(); PlayerLoop.SetPlayerLoop(currentPlayerLoop); // セット完了したので終了する return; } } }
static void Start() { var custloop = new PlayerLoopSystem() { type = typeof(UpdateHandler), updateDelegate = CustomUpdate }; var defaultPlayerLoop = PlayerLoop.GetDefaultPlayerLoop(); var updateSystemList = defaultPlayerLoop.subSystemList[4]; // Four is the default Update loop var update = updateSystemList.subSystemList; // Possibly faster than creating a List from array, appending said list and creating an array from List? Array.Resize(ref update, update.Length + 1); update[update.Length - 1] = custloop; updateSystemList.subSystemList = update; defaultPlayerLoop.subSystemList[4] = updateSystemList; PlayerLoop.SetPlayerLoop(defaultPlayerLoop); }
static void RuntimeInitializeOnLoad() { // get loop // TODO 2019 has GetCURRENTPlayerLoop which is safe to use without // breaking other custom system's custom loops. Let's use Default // for now until we upgrade to 2019 so we have the same behaviour // at all times (instead of different loop behavior on 2018/2019) PlayerLoopSystem playerLoop = PlayerLoop.GetDefaultPlayerLoop(); // 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> /// 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); }
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(); s_UnloadOrPlayModeChangeShutdownRegistered = false; DefaultWorldDestroyed?.Invoke(); #endif }
// [RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSceneLoad)] public static void Initialize() { if (Interlocked.CompareExchange(ref initialized, 1, 0) != 0) { return; } 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);
static void InsertPlayerLoopSystem() { // Append a custom system to the Early Update phase. var customSystem = new PlayerLoopSystem() { type = typeof(DeviceDriver), updateDelegate = () => DeviceDriver.Update() }; var playerLoop = PlayerLoop.GetCurrentPlayerLoop(); for (var i = 0; i < playerLoop.subSystemList.Length; i++) { ref var phase = ref playerLoop.subSystemList[i]; if (phase.type == typeof(UnityEngine.PlayerLoop.EarlyUpdate)) { phase.subSystemList = phase.subSystemList. Concat(new[] { customSystem }).ToArray(); break; } }
private static void RuntimeInitializeOnLoad() { Debug.Log("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 = PlayerLoop.GetCurrentPlayerLoop(); // add NetworkEarlyUpdate to the end of EarlyUpdate so it runs after // any Unity initializations but before the first Update/FixedUpdate AddToPlayerLoop(NetworkEarlyUpdate, typeof(NetLoop), 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(NetLoop), ref playerLoop, typeof(PreLateUpdate), AddMode.End); // set the new loop PlayerLoop.SetPlayerLoop(playerLoop); }
static void Init() { if (headlessTexture == null) { var playerSettings = Resources.Load <PlayerResolutionSettings>("PlayerResolutionSettings"); if (playerSettings == null) { headlessTexture.width = 640; headlessTexture.height = 480; Log.W("Player Settings resolution scriptable object not found, loading default of 640X480"); } else { if (playerSettings.renderTexture != null) { headlessTexture = playerSettings.renderTexture; headlessTexture.width = playerSettings.playerResolution.width; headlessTexture.height = playerSettings.playerResolution.height; } else { headlessTexture = new RenderTexture(playerSettings.playerResolution.width, playerSettings.playerResolution.height, 1); } } if (headlessTexture.Create()) { CloudGraphics.SetDefaultBackbufferSurface(headlessTexture); } else { Log.E("Failed to create a render texture for default backbuffer surface"); } } var loopSystem = GenerateCustomLoop(); PlayerLoop.SetPlayerLoop(loopSystem); }
public void OneTimeSetUp() { // set up temporary GameObject injection world PreviousGameObjectInjectionWorld = World.DefaultGameObjectInjectionWorld; PreviousPlayerLoop = PlayerLoop.GetCurrentPlayerLoop(); World.DefaultGameObjectInjectionWorld = default; DefaultWorldInitialization.DefaultLazyEditModeInitialize(); // create folder for temporary assets string folderName; do { folderName = Path.GetRandomFileName(); }while (AssetDatabase.IsValidFolder(Path.Combine("Assets", folderName))); TemporaryAssetsPath = AssetDatabase.GUIDToAssetPath(AssetDatabase.CreateFolder("Assets", folderName)); // create non-readable mesh asset NonReadableMesh = UnityMesh.Instantiate(Resources.GetBuiltinResource <UnityMesh>("New-Cylinder.fbx")); NonReadableMesh.UploadMeshData(true); Assume.That(NonReadableMesh.isReadable, Is.False, $"{NonReadableMesh} was readable."); AssetDatabase.CreateAsset(NonReadableMesh, $"{TemporaryAssetsPath}/NonReadableMesh.asset"); }
private static void EnsureSystemFetched() { if (hasFetchedSystem) { return; } defaultSystem = PlayerLoop.GetDefaultPlayerLoop(); system = CopySystem(defaultSystem); hasFetchedSystem = true; if (!TryFetchFixedUpdatePointer(system)) { Debug.LogError("Couldn't find FixedUpdate in the built-in player loop systems! This means that setting runInFixedUpdate to true in " + "InsertSystemBefore or After won't work!"); } // if the Entities package is not installed, any systems registered keeps running after we leave play mode. // This is "intended behaviour". Not joking. https://fogbugz.unity3d.com/default.asp?1089518_lub560iemcggi1c9 PlayerLoopQuitChecker.GameQuitCallback += () => { PlayerLoop.SetPlayerLoop(defaultSystem); }; }
public Task InitAsync() { IsComponentAlive = true; if (!s_UniTaskInited) { 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); s_UniTaskInited = true; } return(OnInitAsync()); }
public void AddRemoveScriptUpdate() { DefaultWorldInitialization.Initialize("Test World", true); var newWorld = new World("WorldA"); newWorld.CreateSystem <InitializationSystemGroup>(); newWorld.CreateSystem <SimulationSystemGroup>(); newWorld.CreateSystem <PresentationSystemGroup>(); Assert.IsFalse(ScriptBehaviourUpdateOrder.IsWorldInCurrentPlayerLoop(newWorld)); ScriptBehaviourUpdateOrder.AddWorldToCurrentPlayerLoop(newWorld); Assert.IsTrue(ScriptBehaviourUpdateOrder.IsWorldInCurrentPlayerLoop(newWorld)); PlayerLoop.SetPlayerLoop(PlayerLoop.GetDefaultPlayerLoop()); Assert.IsFalse(ScriptBehaviourUpdateOrder.IsWorldInCurrentPlayerLoop(newWorld)); var playerLoop = PlayerLoop.GetDefaultPlayerLoop(); ScriptBehaviourUpdateOrder.AddWorldToPlayerLoop(World.DefaultGameObjectInjectionWorld, ref playerLoop); PlayerLoop.SetPlayerLoop(playerLoop); Assert.IsTrue(ScriptBehaviourUpdateOrder.IsWorldInCurrentPlayerLoop(World.DefaultGameObjectInjectionWorld)); }
internal static void RegisterLoopSystems() { var rootPlayerLoop = PlayerLoop.GetCurrentPlayerLoop(); for (int i = 0; i < rootPlayerLoop.subSystemList.Length; i++) { ref var currentSystem = ref rootPlayerLoop.subSystemList[i]; if (currentSystem.type == typeof(Initialization)) { TryAddLoopSystem(ref currentSystem, NetworkInitialization.CreateLoopSystem(), null, LoopSystemPosition.After); } else if (currentSystem.type == typeof(EarlyUpdate)) { TryAddLoopSystem(ref currentSystem, NetworkEarlyUpdate.CreateLoopSystem(), typeof(EarlyUpdate.ScriptRunDelayedStartupFrame), LoopSystemPosition.Before); } else if (currentSystem.type == typeof(FixedUpdate)) { TryAddLoopSystem(ref currentSystem, NetworkFixedUpdate.CreateLoopSystem(), typeof(FixedUpdate.ScriptRunBehaviourFixedUpdate), LoopSystemPosition.Before); } else if (currentSystem.type == typeof(PreUpdate)) { TryAddLoopSystem(ref currentSystem, NetworkPreUpdate.CreateLoopSystem(), typeof(PreUpdate.PhysicsUpdate), LoopSystemPosition.Before); } else if (currentSystem.type == typeof(Update)) { TryAddLoopSystem(ref currentSystem, NetworkUpdate.CreateLoopSystem(), typeof(Update.ScriptRunBehaviourUpdate), LoopSystemPosition.Before); } else if (currentSystem.type == typeof(PreLateUpdate)) { TryAddLoopSystem(ref currentSystem, NetworkPreLateUpdate.CreateLoopSystem(), typeof(PreLateUpdate.ScriptRunBehaviourLateUpdate), LoopSystemPosition.Before); } else if (currentSystem.type == typeof(PostLateUpdate)) { TryAddLoopSystem(ref currentSystem, NetworkPostLateUpdate.CreateLoopSystem(), typeof(PostLateUpdate.PlayerSendFrameComplete), LoopSystemPosition.After); } }
// Use this for initialization void Start () { pLoop = GameObject.Find("Player").GetComponent<PlayerLoop>(); }