Advertisement
Guest User

Untitled

a guest
Jun 17th, 2019
172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.01 KB | None | 0 0
  1. public static class WorldExtensions
  2. {
  3. public static void AddWorldToPlayerLoop(this World world)
  4. {
  5. if (ScriptBehaviourUpdateOrder.CurrentPlayerLoop.subSystemList == null)
  6. {
  7. // If there were no systems running previously, exit early
  8. ScriptBehaviourUpdateOrder.UpdatePlayerLoop(world);
  9. return;
  10. }
  11.  
  12. // Take the previous systems that were running.
  13. var a = ScriptBehaviourUpdateOrder.CurrentPlayerLoop;
  14.  
  15. // Create a player loop from the given world.
  16. ScriptBehaviourUpdateOrder.UpdatePlayerLoop(world);
  17. var b = ScriptBehaviourUpdateOrder.CurrentPlayerLoop;
  18.  
  19. var result = new PlayerLoopSystem {subSystemList = new PlayerLoopSystem[a.subSystemList.Length]};
  20.  
  21. for (var i = 0; i < a.subSystemList.Length; i++)
  22. {
  23. var aSub = a.subSystemList[i].subSystemList;
  24. var bSub = b.subSystemList[i].subSystemList;
  25.  
  26. var resultSub = a.subSystemList[i];
  27. resultSub.subSystemList = new PlayerLoopSystem[aSub.Length + 1];
  28.  
  29. for (var j = 0; j < aSub.Length; j++)
  30. {
  31. resultSub.subSystemList[j] = aSub[j];
  32. }
  33.  
  34. for (var j = 0; j < bSub?.Length; j++)
  35. {
  36. // Only add the systems that are specific to the world.
  37. // Don't add other systems, they are internal to Unity (e.g. like WaitForTargetFPS).
  38. if (bSub[j].type == typeof(SimulationSystemGroup) ||
  39. bSub[j].type == typeof(PresentationSystemGroup) ||
  40. bSub[j].type == typeof(InitializationSystemGroup))
  41. {
  42. resultSub.subSystemList[aSub.Length] = bSub[j];
  43. }
  44. }
  45.  
  46. result.subSystemList[i] = resultSub;
  47. }
  48.  
  49. ScriptBehaviourUpdateOrder.SetPlayerLoop(result);
  50. }
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement