Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static class WorldExtensions
- {
- public static void AddWorldToPlayerLoop(this World world)
- {
- if (ScriptBehaviourUpdateOrder.CurrentPlayerLoop.subSystemList == null)
- {
- // If there were no systems running previously, exit early
- ScriptBehaviourUpdateOrder.UpdatePlayerLoop(world);
- return;
- }
- // Take the previous systems that were running.
- var a = ScriptBehaviourUpdateOrder.CurrentPlayerLoop;
- // Create a player loop from the given world.
- ScriptBehaviourUpdateOrder.UpdatePlayerLoop(world);
- var b = ScriptBehaviourUpdateOrder.CurrentPlayerLoop;
- var result = new PlayerLoopSystem {subSystemList = new PlayerLoopSystem[a.subSystemList.Length]};
- for (var i = 0; i < a.subSystemList.Length; i++)
- {
- var aSub = a.subSystemList[i].subSystemList;
- var bSub = b.subSystemList[i].subSystemList;
- var resultSub = a.subSystemList[i];
- resultSub.subSystemList = new PlayerLoopSystem[aSub.Length + 1];
- for (var j = 0; j < aSub.Length; j++)
- {
- resultSub.subSystemList[j] = aSub[j];
- }
- for (var j = 0; j < bSub?.Length; j++)
- {
- // Only add the systems that are specific to the world.
- // Don't add other systems, they are internal to Unity (e.g. like WaitForTargetFPS).
- if (bSub[j].type == typeof(SimulationSystemGroup) ||
- bSub[j].type == typeof(PresentationSystemGroup) ||
- bSub[j].type == typeof(InitializationSystemGroup))
- {
- resultSub.subSystemList[aSub.Length] = bSub[j];
- }
- }
- result.subSystemList[i] = resultSub;
- }
- ScriptBehaviourUpdateOrder.SetPlayerLoop(result);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement