PlayerLauncherContextSettings.cs 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. using System;
  2. using System.IO;
  3. using UnityEditor.TestTools.TestRunner.Api;
  4. using UnityEngine;
  5. namespace UnityEditor.TestTools.TestRunner
  6. {
  7. internal class PlayerLauncherContextSettings : IDisposable
  8. {
  9. private ITestRunSettings m_OverloadSettings;
  10. private EditorBuildSettingsScene[] m_EditorBuildSettings;
  11. #pragma warning disable 618
  12. private ResolutionDialogSetting m_DisplayResolutionDialog;
  13. #pragma warning restore 618
  14. private bool m_RunInBackground;
  15. private FullScreenMode m_FullScreenMode;
  16. private bool m_ResizableWindow;
  17. private bool m_ShowUnitySplashScreen;
  18. private string m_OldproductName;
  19. private string m_OldAotOptions;
  20. #pragma warning disable 618
  21. private Lightmapping.GIWorkflowMode m_OldLightmapping;
  22. #pragma warning restore 618
  23. private bool m_explicitNullChecks;
  24. private bool m_Disposed;
  25. public PlayerLauncherContextSettings(ITestRunSettings overloadSettings)
  26. {
  27. m_OverloadSettings = overloadSettings;
  28. SetupProjectParameters();
  29. if (overloadSettings != null)
  30. {
  31. overloadSettings.Apply();
  32. }
  33. }
  34. public void Dispose()
  35. {
  36. if (!m_Disposed)
  37. {
  38. CleanupProjectParameters();
  39. if (m_OverloadSettings != null)
  40. {
  41. m_OverloadSettings.Dispose();
  42. }
  43. m_Disposed = true;
  44. }
  45. }
  46. private void SetupProjectParameters()
  47. {
  48. EditorApplication.LockReloadAssemblies();
  49. m_EditorBuildSettings = EditorBuildSettings.scenes;
  50. #pragma warning disable 618
  51. m_DisplayResolutionDialog = PlayerSettings.displayResolutionDialog;
  52. PlayerSettings.displayResolutionDialog = ResolutionDialogSetting.Disabled;
  53. #pragma warning restore 618
  54. m_RunInBackground = PlayerSettings.runInBackground;
  55. PlayerSettings.runInBackground = true;
  56. m_FullScreenMode = PlayerSettings.fullScreenMode;
  57. PlayerSettings.fullScreenMode = FullScreenMode.Windowed;
  58. m_OldAotOptions = PlayerSettings.aotOptions;
  59. PlayerSettings.aotOptions = "nimt-trampolines=1024";
  60. m_ResizableWindow = PlayerSettings.resizableWindow;
  61. PlayerSettings.resizableWindow = true;
  62. m_ShowUnitySplashScreen = PlayerSettings.SplashScreen.show;
  63. PlayerSettings.SplashScreen.show = false;
  64. m_OldproductName = PlayerSettings.productName;
  65. PlayerSettings.productName = string.Join("_", Application.productName.Split(Path.GetInvalidFileNameChars()));
  66. #pragma warning disable 618
  67. m_OldLightmapping = Lightmapping.giWorkflowMode;
  68. Lightmapping.giWorkflowMode = Lightmapping.GIWorkflowMode.OnDemand;
  69. #pragma warning restore 618
  70. m_explicitNullChecks = EditorUserBuildSettings.explicitNullChecks;
  71. EditorUserBuildSettings.explicitNullChecks = true;
  72. }
  73. private void CleanupProjectParameters()
  74. {
  75. EditorBuildSettings.scenes = m_EditorBuildSettings;
  76. PlayerSettings.fullScreenMode = m_FullScreenMode;
  77. PlayerSettings.runInBackground = m_RunInBackground;
  78. #pragma warning disable 618
  79. PlayerSettings.displayResolutionDialog = m_DisplayResolutionDialog;
  80. #pragma warning restore 618
  81. PlayerSettings.resizableWindow = m_ResizableWindow;
  82. PlayerSettings.SplashScreen.show = m_ShowUnitySplashScreen;
  83. PlayerSettings.productName = m_OldproductName;
  84. PlayerSettings.aotOptions = m_OldAotOptions;
  85. #pragma warning disable 618
  86. Lightmapping.giWorkflowMode = m_OldLightmapping;
  87. #pragma warning restore 618
  88. EditorUserBuildSettings.explicitNullChecks = m_explicitNullChecks;
  89. EditorApplication.UnlockReloadAssemblies();
  90. }
  91. }
  92. }