multiple xr toolkit package
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

EnvConfig.cs 26KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687
  1. #define ENV_SET_INCLUDED_SHADERS
  2. using UnityEngine;
  3. using UnityEditor;
  4. using System.Collections;
  5. using System;
  6. using System.Linq;
  7. using UnityEngine.Rendering;
  8. using VRCSDK2.Validation.Performance.Stats;
  9. /// <summary>
  10. /// Setup up SDK env on editor launch
  11. /// </summary>
  12. [InitializeOnLoad]
  13. public class EnvConfig
  14. {
  15. static BuildTarget[] relevantBuildTargets = new BuildTarget[] {
  16. BuildTarget.Android, BuildTarget.iOS,
  17. BuildTarget.StandaloneLinux, BuildTarget.StandaloneLinux64, BuildTarget.StandaloneLinuxUniversal,
  18. BuildTarget.StandaloneWindows, BuildTarget.StandaloneWindows64,
  19. BuildTarget.StandaloneOSX
  20. };
  21. #if !VRC_CLIENT
  22. static BuildTarget[] allowedBuildtargets = new BuildTarget[]
  23. {
  24. BuildTarget.StandaloneWindows64,
  25. BuildTarget.Android
  26. };
  27. #endif
  28. static System.Collections.Generic.Dictionary<BuildTarget, UnityEngine.Rendering.GraphicsDeviceType[]> allowedGraphicsAPIs = new System.Collections.Generic.Dictionary<BuildTarget, UnityEngine.Rendering.GraphicsDeviceType[]>()
  29. {
  30. { BuildTarget.Android, new [] { GraphicsDeviceType.OpenGLES3, /* GraphicsDeviceType.Vulkan */ }},
  31. { BuildTarget.iOS, null },
  32. { BuildTarget.StandaloneLinux, null },
  33. { BuildTarget.StandaloneLinux64, null },
  34. { BuildTarget.StandaloneLinuxUniversal, null },
  35. { BuildTarget.StandaloneWindows, new UnityEngine.Rendering.GraphicsDeviceType[] { UnityEngine.Rendering.GraphicsDeviceType.Direct3D11 } },
  36. { BuildTarget.StandaloneWindows64, new UnityEngine.Rendering.GraphicsDeviceType[] { UnityEngine.Rendering.GraphicsDeviceType.Direct3D11 } },
  37. { BuildTarget.StandaloneOSX, null }
  38. };
  39. static string[] ensureTheseShadersAreAvailable = new string[]
  40. {
  41. #if VRC_CLIENT
  42. "Hidden/CubeBlend",
  43. "Hidden/CubeBlur",
  44. "Hidden/CubeCopy",
  45. "Hidden/VideoDecode",
  46. "Legacy Shaders/Bumped Diffuse",
  47. "Legacy Shaders/Bumped Specular",
  48. "Legacy Shaders/Decal",
  49. "Legacy Shaders/Diffuse Detail",
  50. "Legacy Shaders/Diffuse Fast",
  51. "Legacy Shaders/Diffuse",
  52. "Legacy Shaders/Diffuse",
  53. "Legacy Shaders/Lightmapped/Diffuse",
  54. "Legacy Shaders/Lightmapped/Specular",
  55. "Legacy Shaders/Lightmapped/VertexLit",
  56. "Legacy Shaders/Parallax Diffuse",
  57. "Legacy Shaders/Parallax Specular",
  58. "Legacy Shaders/Reflective/Bumped Diffuse",
  59. "Legacy Shaders/Reflective/Bumped Specular",
  60. "Legacy Shaders/Reflective/Bumped Unlit",
  61. "Legacy Shaders/Reflective/Bumped VertexLit",
  62. "Legacy Shaders/Reflective/Diffuse",
  63. "Legacy Shaders/Reflective/Parallax Diffuse",
  64. "Legacy Shaders/Reflective/Parallax Specular",
  65. "Legacy Shaders/Reflective/Specular",
  66. "Legacy Shaders/Reflective/VertexLit",
  67. "Legacy Shaders/Self-Illumin/Bumped Diffuse",
  68. "Legacy Shaders/Self-Illumin/Bumped Specular",
  69. "Legacy Shaders/Self-Illumin/Diffuse",
  70. "Legacy Shaders/Self-Illumin/Parallax Diffuse",
  71. "Legacy Shaders/Self-Illumin/Parallax Specular",
  72. "Legacy Shaders/Self-Illumin/Specular",
  73. "Legacy Shaders/Self-Illumin/VertexLit",
  74. "Legacy Shaders/Specular",
  75. "Legacy Shaders/Transparent/Bumped Diffuse",
  76. "Legacy Shaders/Transparent/Bumped Specular",
  77. "Legacy Shaders/Transparent/Cutout/Bumped Diffuse",
  78. "Legacy Shaders/Transparent/Cutout/Bumped Specular",
  79. "Legacy Shaders/Transparent/Cutout/Diffuse",
  80. "Legacy Shaders/Transparent/Cutout/Soft Edge Unlit",
  81. "Legacy Shaders/Transparent/Cutout/Specular",
  82. "Legacy Shaders/Transparent/Cutout/VertexLit",
  83. "Legacy Shaders/Transparent/Diffuse",
  84. "Legacy Shaders/Transparent/Parallax Diffuse",
  85. "Legacy Shaders/Transparent/Parallax Specular",
  86. "Legacy Shaders/Transparent/Specular",
  87. "Legacy Shaders/Transparent/VertexLit",
  88. "Legacy Shaders/VertexLit",
  89. "Mobile/Particles/Additive",
  90. "Mobile/Particles/Alpha Blended",
  91. "Mobile/Particles/Multiply",
  92. "Mobile/Particles/VertexLit Blended",
  93. "Mobile/Skybox",
  94. "Nature/Terrain/Diffuse",
  95. "Nature/Terrain/Specular",
  96. "Nature/Terrain/Standard",
  97. "Particles/Additive (Soft)",
  98. "Particles/Additive",
  99. "Particles/Alpha Blended Premultiply",
  100. "Particles/Alpha Blended",
  101. "Particles/Anim Alpha Blended",
  102. "Particles/Multiply (Double)",
  103. "Particles/Multiply",
  104. "Particles/VertexLit Blended",
  105. "Particles/~Additive-Multiply",
  106. "Skybox/Cubemap",
  107. "Skybox/Procedural",
  108. "Skybox/6 Sided",
  109. "Sprites/Default",
  110. "Sprites/Diffuse",
  111. "UI/Default",
  112. "VRChat/UI/Unlit/WebPanelTransparent",
  113. "Toon/Lit",
  114. "Toon/Lit (Double)",
  115. "Toon/Lit Cutout",
  116. "Toon/Lit Cutout (Double)",
  117. "Toon/Lit Outline",
  118. "VRChat/Mobile/Diffuse",
  119. "VRChat/Mobile/Bumped Uniform Diffuse",
  120. "VRChat/Mobile/Bumped Uniform Specular",
  121. "VRChat/Mobile/Toon Lit",
  122. "VRChat/Mobile/MatCap Lit",
  123. "VRChat/Mobile/Skybox",
  124. "VRChat/Mobile/Lightmapped",
  125. "VRChat/PC/Toon Lit",
  126. "VRChat/PC/Toon Lit (Double)",
  127. "VRChat/PC/Toon Lit Cutout",
  128. "VRChat/PC/Toon Lit Cutout (Double)",
  129. "Unlit/Color",
  130. "Unlit/Transparent",
  131. "Unlit/Transparent Cutout",
  132. "Unlit/Texture",
  133. "MatCap/Vertex/Textured Lit",
  134. #endif
  135. };
  136. private static bool _requestConfigureSettings = true;
  137. static EnvConfig()
  138. {
  139. EditorApplication.update += EditorUpdate;
  140. }
  141. static void EditorUpdate()
  142. {
  143. if (_requestConfigureSettings)
  144. {
  145. if (ConfigureSettings())
  146. {
  147. _requestConfigureSettings = false;
  148. }
  149. }
  150. }
  151. public static void RequestConfigureSettings()
  152. {
  153. _requestConfigureSettings = true;
  154. }
  155. [UnityEditor.Callbacks.DidReloadScripts(int.MaxValue)]
  156. static void DidReloadScripts()
  157. {
  158. RequestConfigureSettings();
  159. }
  160. public static bool ConfigureSettings()
  161. {
  162. CustomDLLMaker.CreateDirectories();
  163. if (CheckForFirstInit())
  164. VRC.AssetExporter.CleanupTmpFiles();
  165. if (EditorApplication.isPlayingOrWillChangePlaymode || EditorApplication.isUpdating)
  166. return false;
  167. ConfigurePlayerSettings();
  168. if (!VRC.Core.RemoteConfig.IsInitialized())
  169. {
  170. VRC.Core.API.SetOnlineMode(true, "vrchat");
  171. VRC.Core.RemoteConfig.Init();
  172. }
  173. LoadEditorResources();
  174. return true;
  175. }
  176. static void SetDLLPlatforms(string dllName, bool active)
  177. {
  178. string[] assetGuids = AssetDatabase.FindAssets(dllName);
  179. foreach (string guid in assetGuids)
  180. {
  181. string dllPath = AssetDatabase.GUIDToAssetPath(guid);
  182. if (string.IsNullOrEmpty(dllPath) || dllPath.ToLower().EndsWith(".dll") == false)
  183. return;
  184. PluginImporter importer = AssetImporter.GetAtPath(dllPath) as PluginImporter;
  185. bool allCorrect = true;
  186. if (importer.GetCompatibleWithAnyPlatform() != active)
  187. {
  188. allCorrect = false;
  189. }
  190. else
  191. {
  192. if (importer.GetCompatibleWithAnyPlatform())
  193. {
  194. if (importer.GetExcludeEditorFromAnyPlatform() != !active ||
  195. importer.GetExcludeFromAnyPlatform(BuildTarget.StandaloneWindows) != !active)
  196. {
  197. allCorrect = false;
  198. }
  199. }
  200. else
  201. {
  202. if (importer.GetCompatibleWithEditor() != active ||
  203. importer.GetCompatibleWithPlatform(BuildTarget.StandaloneWindows) != active)
  204. {
  205. allCorrect = false;
  206. }
  207. }
  208. }
  209. if (allCorrect == false)
  210. {
  211. if (active)
  212. {
  213. importer.SetCompatibleWithAnyPlatform(true);
  214. importer.SetExcludeEditorFromAnyPlatform(false);
  215. importer.SetExcludeFromAnyPlatform(BuildTarget.Android, false);
  216. importer.SetExcludeFromAnyPlatform(BuildTarget.StandaloneWindows, false);
  217. importer.SetExcludeFromAnyPlatform(BuildTarget.StandaloneWindows64, false);
  218. importer.SetExcludeFromAnyPlatform(BuildTarget.StandaloneLinux, false);
  219. importer.SetExcludeFromAnyPlatform(BuildTarget.StandaloneLinux64, false);
  220. importer.SetExcludeFromAnyPlatform(BuildTarget.StandaloneOSX, false);
  221. }
  222. else
  223. {
  224. importer.SetCompatibleWithAnyPlatform(false);
  225. importer.SetCompatibleWithEditor(false);
  226. importer.SetCompatibleWithPlatform(BuildTarget.Android, false);
  227. importer.SetCompatibleWithPlatform(BuildTarget.StandaloneWindows, false);
  228. importer.SetCompatibleWithPlatform(BuildTarget.StandaloneWindows64, false);
  229. importer.SetCompatibleWithPlatform(BuildTarget.StandaloneLinux, false);
  230. importer.SetCompatibleWithPlatform(BuildTarget.StandaloneLinux64, false);
  231. importer.SetCompatibleWithPlatform(BuildTarget.StandaloneOSX, false);
  232. }
  233. importer.SaveAndReimport();
  234. }
  235. }
  236. }
  237. [MenuItem("VRChat SDK/Utilities/Force Configure Player Settings")]
  238. public static void ConfigurePlayerSettings()
  239. {
  240. Debug.Log("Setting required PlayerSettings...");
  241. SetBuildTarget();
  242. // Needed for Microsoft.CSharp namespace in DLLMaker
  243. // Doesn't seem to work though
  244. if (PlayerSettings.GetApiCompatibilityLevel(EditorUserBuildSettings.selectedBuildTargetGroup) != ApiCompatibilityLevel.NET_2_0)
  245. PlayerSettings.SetApiCompatibilityLevel(EditorUserBuildSettings.selectedBuildTargetGroup, ApiCompatibilityLevel.NET_2_0);
  246. if (!PlayerSettings.runInBackground)
  247. PlayerSettings.runInBackground = true;
  248. #if !VRC_CLIENT
  249. SetDLLPlatforms("VRCCore-Standalone", false);
  250. SetDLLPlatforms("VRCCore-Editor", true);
  251. #endif
  252. SetDefaultGraphicsAPIs();
  253. SetGraphicsSettings();
  254. SetAudioSettings();
  255. SetPlayerSettings();
  256. #if VRC_CLIENT
  257. AssetDatabase.SaveAssets();
  258. AssetDatabase.Refresh();
  259. #else
  260. // SDK
  261. // default to steam runtime in sdk (shouldn't matter)
  262. SetVRSDKs(EditorUserBuildSettings.selectedBuildTargetGroup, new string[] { "None", "OpenVR", "Oculus" });
  263. VRC.Core.AnalyticsSDK.Initialize(VRC.Core.SDKClientUtilities.GetSDKVersionDate());
  264. #endif
  265. // VRCLog should handle disk writing
  266. PlayerSettings.usePlayerLog = false;
  267. if (EditorUserBuildSettings.selectedBuildTargetGroup != BuildTargetGroup.Standalone)
  268. {
  269. foreach (var logType in Enum.GetValues(typeof(LogType)).Cast<LogType>())
  270. PlayerSettings.SetStackTraceLogType(logType, StackTraceLogType.None);
  271. }
  272. else
  273. {
  274. foreach (var logType in Enum.GetValues(typeof(LogType)).Cast<LogType>())
  275. PlayerSettings.SetStackTraceLogType(logType, StackTraceLogType.ScriptOnly);
  276. }
  277. }
  278. static void EnableBatching(bool enable)
  279. {
  280. PlayerSettings[] playerSettings = Resources.FindObjectsOfTypeAll<PlayerSettings>();
  281. if (playerSettings == null)
  282. return;
  283. SerializedObject playerSettingsSerializedObject = new SerializedObject(playerSettings);
  284. SerializedProperty batchingSettings = playerSettingsSerializedObject.FindProperty("m_BuildTargetBatching");
  285. if (batchingSettings == null)
  286. return;
  287. for (int i = 0; i < batchingSettings.arraySize; i++)
  288. {
  289. SerializedProperty batchingArrayValue = batchingSettings.GetArrayElementAtIndex(i);
  290. if (batchingArrayValue == null)
  291. continue;
  292. IEnumerator batchingEnumerator = batchingArrayValue.GetEnumerator();
  293. if (batchingEnumerator == null)
  294. continue;
  295. while (batchingEnumerator.MoveNext())
  296. {
  297. SerializedProperty property = (SerializedProperty)batchingEnumerator.Current;
  298. if (property != null && property.name == "m_BuildTarget")
  299. {
  300. // only change setting on "Standalone" entry
  301. if (property.stringValue != "Standalone")
  302. break;
  303. }
  304. if (property != null && property.name == "m_StaticBatching")
  305. {
  306. property.boolValue = enable;
  307. }
  308. if (property != null && property.name == "m_DynamicBatching")
  309. {
  310. property.boolValue = enable;
  311. }
  312. }
  313. }
  314. playerSettingsSerializedObject.ApplyModifiedProperties();
  315. }
  316. public static void SetVRSDKs(BuildTargetGroup buildTargetGroup, string[] sdkNames)
  317. {
  318. Debug.Log("Setting virtual reality SDKs in PlayerSettings: ");
  319. if (sdkNames != null)
  320. {
  321. foreach (string s in sdkNames)
  322. Debug.Log("- " + s);
  323. }
  324. PlayerSettings[] playerSettings = Resources.FindObjectsOfTypeAll<PlayerSettings>();
  325. if (playerSettings == null)
  326. return;
  327. SerializedObject playerSettingsSerializedObject = new SerializedObject(playerSettings);
  328. SerializedProperty settingsGroup = playerSettingsSerializedObject.FindProperty("m_BuildTargetVRSettings");
  329. if (settingsGroup == null)
  330. return;
  331. for (int i = 0; i < settingsGroup.arraySize; i++)
  332. {
  333. SerializedProperty settingVal = settingsGroup.GetArrayElementAtIndex(i);
  334. if (settingVal == null)
  335. continue;
  336. IEnumerator enumerator = settingVal.GetEnumerator();
  337. if (enumerator == null)
  338. continue;
  339. while (enumerator.MoveNext())
  340. {
  341. SerializedProperty property = (SerializedProperty)enumerator.Current;
  342. if (property != null && property.name == "m_BuildTarget")
  343. {
  344. if (property.stringValue != buildTargetGroup.ToString())
  345. break;
  346. }
  347. if (property != null && property.name == "m_Devices")
  348. {
  349. bool overwrite = true;
  350. if (property.arraySize == sdkNames.Length)
  351. {
  352. overwrite = false;
  353. for (int e = 0; e < sdkNames.Length; ++e)
  354. {
  355. if (property.GetArrayElementAtIndex(e).stringValue != sdkNames[e])
  356. overwrite = true;
  357. }
  358. }
  359. if (overwrite)
  360. {
  361. property.ClearArray();
  362. property.arraySize = (sdkNames != null) ? sdkNames.Length : 0;
  363. for (int j = 0; j < property.arraySize; j++)
  364. {
  365. property.GetArrayElementAtIndex(j).stringValue = sdkNames[j];
  366. }
  367. }
  368. }
  369. }
  370. }
  371. playerSettingsSerializedObject.ApplyModifiedProperties();
  372. }
  373. static void RefreshClientVRSDKs()
  374. {
  375. #if VRC_CLIENT
  376. #if VRC_VR_STEAM
  377. SetVRSDKs( BuildTargetGroup.Standalone, new string[] { "None", "OpenVR", "Oculus" });
  378. #else
  379. SetVRSDKs(BuildTargetGroup.Standalone, new string[] { "None", "Oculus", "OpenVR" });
  380. #endif
  381. #endif // VRC_CLIENT
  382. }
  383. public static bool CheckForFirstInit()
  384. {
  385. bool firstLaunch = UnityEditor.SessionState.GetBool("EnvConfigFirstLaunch", true);
  386. if (firstLaunch)
  387. UnityEditor.SessionState.SetBool("EnvConfigFirstLaunch", false);
  388. return firstLaunch;
  389. }
  390. static void SetDefaultGraphicsAPIs()
  391. {
  392. Debug.Log("Setting Graphics APIs");
  393. foreach (BuildTarget target in relevantBuildTargets)
  394. {
  395. var apis = allowedGraphicsAPIs[target];
  396. if (apis == null)
  397. SetGraphicsAPIs(target, true);
  398. else
  399. SetGraphicsAPIs(target, false, apis);
  400. }
  401. }
  402. static void SetGraphicsAPIs(BuildTarget platform, bool auto, UnityEngine.Rendering.GraphicsDeviceType[] allowedTypes = null)
  403. {
  404. try
  405. {
  406. if (auto != PlayerSettings.GetUseDefaultGraphicsAPIs(platform))
  407. PlayerSettings.SetUseDefaultGraphicsAPIs(platform, auto);
  408. }
  409. catch { }
  410. try
  411. {
  412. UnityEngine.Rendering.GraphicsDeviceType[] graphicsAPIs = PlayerSettings.GetGraphicsAPIs(platform);
  413. if (((allowedTypes == null || allowedTypes.Length == 0) && (graphicsAPIs != null || graphicsAPIs.Length != 0))
  414. || !allowedTypes.SequenceEqual(graphicsAPIs))
  415. PlayerSettings.SetGraphicsAPIs(platform, allowedTypes);
  416. }
  417. catch { }
  418. }
  419. static void SetGraphicsSettings()
  420. {
  421. Debug.Log("Setting Graphics Settings");
  422. const string GraphicsSettingsAssetPath = "ProjectSettings/GraphicsSettings.asset";
  423. SerializedObject graphicsManager = new SerializedObject(UnityEditor.AssetDatabase.LoadAllAssetsAtPath(GraphicsSettingsAssetPath)[0]);
  424. SerializedProperty deferred = graphicsManager.FindProperty("m_Deferred.m_Mode");
  425. deferred.enumValueIndex = 1;
  426. SerializedProperty deferredReflections = graphicsManager.FindProperty("m_DeferredReflections.m_Mode");
  427. deferredReflections.enumValueIndex = 1;
  428. SerializedProperty screenSpaceShadows = graphicsManager.FindProperty("m_ScreenSpaceShadows.m_Mode");
  429. screenSpaceShadows.enumValueIndex = 1;
  430. SerializedProperty legacyDeferred = graphicsManager.FindProperty("m_LegacyDeferred.m_Mode");
  431. legacyDeferred.enumValueIndex = 1;
  432. SerializedProperty depthNormals = graphicsManager.FindProperty("m_DepthNormals.m_Mode");
  433. depthNormals.enumValueIndex = 1;
  434. SerializedProperty motionVectors = graphicsManager.FindProperty("m_MotionVectors.m_Mode");
  435. motionVectors.enumValueIndex = 1;
  436. SerializedProperty lightHalo = graphicsManager.FindProperty("m_LightHalo.m_Mode");
  437. lightHalo.enumValueIndex = 1;
  438. SerializedProperty lensFlare = graphicsManager.FindProperty("m_LensFlare.m_Mode");
  439. lensFlare.enumValueIndex = 1;
  440. #if ENV_SET_INCLUDED_SHADERS && VRC_CLIENT
  441. SerializedProperty alwaysIncluded = graphicsManager.FindProperty("m_AlwaysIncludedShaders");
  442. alwaysIncluded.arraySize = 0; // clear GraphicsSettings->Always Included Shaders - these cause a +5s app startup time increase on Quest.
  443. // include Shader objects as resources instead
  444. #if ENV_SEARCH_FOR_SHADERS
  445. Resources.LoadAll("", typeof(Shader));
  446. System.Collections.Generic.List<Shader> foundShaders = Resources.FindObjectsOfTypeAll<Shader>()
  447. .Where(s => { string name = s.name.ToLower(); return 0 == (s.hideFlags & HideFlags.DontSave); })
  448. .GroupBy(s => s.name)
  449. .Select(g => g.First())
  450. .ToList();
  451. #else
  452. System.Collections.Generic.List<Shader> foundShaders = new System.Collections.Generic.List<Shader>();
  453. #endif
  454. for (int shaderIdx = 0; shaderIdx < ensureTheseShadersAreAvailable.Length; ++shaderIdx)
  455. {
  456. if (foundShaders.Any(s => s.name == ensureTheseShadersAreAvailable[shaderIdx]))
  457. continue;
  458. Shader namedShader = Shader.Find(ensureTheseShadersAreAvailable[shaderIdx]);
  459. if (namedShader != null)
  460. foundShaders.Add(namedShader);
  461. }
  462. foundShaders.Sort((s1, s2) => s1.name.CompareTo(s2.name));
  463. // populate Resources list of "always included shaders"
  464. ShaderAssetList alwaysIncludedShaders = AssetDatabase.LoadAssetAtPath<ShaderAssetList>("Assets/Resources/AlwaysIncludedShaders.asset");
  465. alwaysIncludedShaders.Shaders = new Shader[foundShaders.Count];
  466. for (int shaderIdx = 0; shaderIdx < foundShaders.Count; ++shaderIdx)
  467. alwaysIncludedShaders.Shaders[shaderIdx] = foundShaders[shaderIdx];
  468. #endif
  469. SerializedProperty preloaded = graphicsManager.FindProperty("m_PreloadedShaders");
  470. preloaded.ClearArray();
  471. preloaded.arraySize = 0;
  472. SerializedProperty spritesDefaultMaterial = graphicsManager.FindProperty("m_SpritesDefaultMaterial");
  473. spritesDefaultMaterial.objectReferenceValue = Shader.Find("Sprites/Default");
  474. SerializedProperty renderPipeline = graphicsManager.FindProperty("m_CustomRenderPipeline");
  475. renderPipeline.objectReferenceValue = null;
  476. SerializedProperty transparencySortMode = graphicsManager.FindProperty("m_TransparencySortMode");
  477. transparencySortMode.enumValueIndex = 0;
  478. SerializedProperty transparencySortAxis = graphicsManager.FindProperty("m_TransparencySortAxis");
  479. transparencySortAxis.vector3Value = Vector3.forward;
  480. SerializedProperty defaultRenderingPath = graphicsManager.FindProperty("m_DefaultRenderingPath");
  481. defaultRenderingPath.intValue = 1;
  482. SerializedProperty defaultMobileRenderingPath = graphicsManager.FindProperty("m_DefaultMobileRenderingPath");
  483. defaultMobileRenderingPath.intValue = 1;
  484. SerializedProperty tierSettings = graphicsManager.FindProperty("m_TierSettings");
  485. tierSettings.ClearArray();
  486. tierSettings.arraySize = 0;
  487. #if ENV_SET_LIGHTMAP
  488. SerializedProperty lightmapStripping = graphicsManager.FindProperty("m_LightmapStripping");
  489. lightmapStripping.enumValueIndex = 1;
  490. SerializedProperty instancingStripping = graphicsManager.FindProperty("m_InstancingStripping");
  491. instancingStripping.enumValueIndex = 2;
  492. SerializedProperty lightmapKeepPlain = graphicsManager.FindProperty("m_LightmapKeepPlain");
  493. lightmapKeepPlain.boolValue = true;
  494. SerializedProperty lightmapKeepDirCombined = graphicsManager.FindProperty("m_LightmapKeepDirCombined");
  495. lightmapKeepDirCombined.boolValue = true;
  496. SerializedProperty lightmapKeepDynamicPlain = graphicsManager.FindProperty("m_LightmapKeepDynamicPlain");
  497. lightmapKeepDynamicPlain.boolValue = true;
  498. SerializedProperty lightmapKeepDynamicDirCombined = graphicsManager.FindProperty("m_LightmapKeepDynamicDirCombined");
  499. lightmapKeepDynamicDirCombined.boolValue = true;
  500. SerializedProperty lightmapKeepShadowMask = graphicsManager.FindProperty("m_LightmapKeepShadowMask");
  501. lightmapKeepShadowMask.boolValue = true;
  502. SerializedProperty lightmapKeepSubtractive = graphicsManager.FindProperty("m_LightmapKeepSubtractive");
  503. lightmapKeepSubtractive.boolValue = true;
  504. #endif
  505. #if ENV_SET_FOG
  506. SerializedProperty fogStripping = graphicsManager.FindProperty("m_FogStripping");
  507. fogStripping.enumValueIndex = 1;
  508. SerializedProperty fogKeepLinear = graphicsManager.FindProperty("m_FogKeepLinear");
  509. fogKeepLinear.boolValue = true;
  510. SerializedProperty fogKeepExp = graphicsManager.FindProperty("m_FogKeepExp");
  511. fogKeepExp.boolValue = true;
  512. SerializedProperty fogKeepExp2 = graphicsManager.FindProperty("m_FogKeepExp2");
  513. fogKeepExp2.boolValue = true;
  514. #endif
  515. SerializedProperty albedoSwatchInfos = graphicsManager.FindProperty("m_AlbedoSwatchInfos");
  516. albedoSwatchInfos.ClearArray();
  517. albedoSwatchInfos.arraySize = 0;
  518. SerializedProperty lightsUseLinearIntensity = graphicsManager.FindProperty("m_LightsUseLinearIntensity");
  519. lightsUseLinearIntensity.boolValue = true;
  520. SerializedProperty lightsUseColorTemperature = graphicsManager.FindProperty("m_LightsUseColorTemperature");
  521. lightsUseColorTemperature.boolValue = true;
  522. graphicsManager.ApplyModifiedProperties();
  523. }
  524. static void SetAudioSettings()
  525. {
  526. var config = AudioSettings.GetConfiguration();
  527. config.dspBufferSize = 0; // use default
  528. config.speakerMode = AudioSpeakerMode.Stereo; // use default
  529. config.sampleRate = 0; // use default
  530. if (EditorUserBuildSettings.selectedBuildTargetGroup == BuildTargetGroup.Android)
  531. {
  532. config.numRealVoices = 24;
  533. config.numVirtualVoices = 24;
  534. }
  535. else
  536. {
  537. config.numRealVoices = 32;
  538. config.numVirtualVoices = 63;
  539. }
  540. AudioSettings.Reset(config);
  541. }
  542. static void SetPlayerSettings()
  543. {
  544. // asset bundles MUST be built with settings that are compatible with VRC client
  545. #if VRC_OVERRIDE_COLORSPACE_GAMMA
  546. PlayerSettings.colorSpace = ColorSpace.Gamma;
  547. #else
  548. PlayerSettings.colorSpace = ColorSpace.Linear;
  549. #endif
  550. #if !VRC_CLIENT // In client rely on platform-switcher
  551. PlayerSettings.virtualRealitySupported = true;
  552. #endif
  553. PlayerSettings.graphicsJobs = false; // else we get occasional crashing
  554. PlayerSettings.gpuSkinning = true;
  555. PlayerSettings.stereoRenderingPath = StereoRenderingPath.SinglePass;
  556. EnableBatching(true);
  557. }
  558. static void SetBuildTarget()
  559. {
  560. #if !VRC_CLIENT
  561. Debug.Log("Setting build target");
  562. BuildTarget target = UnityEditor.EditorUserBuildSettings.activeBuildTarget;
  563. if (!allowedBuildtargets.Contains(target))
  564. {
  565. Debug.LogError("Target not supported, switching to one that is.");
  566. target = allowedBuildtargets[0];
  567. #pragma warning disable CS0618 // Type or member is obsolete
  568. EditorUserBuildSettings.SwitchActiveBuildTarget(target);
  569. #pragma warning restore CS0618 // Type or member is obsolete
  570. }
  571. #endif
  572. }
  573. private static void LoadEditorResources()
  574. {
  575. AvatarPerformanceStats.Initialize();
  576. }
  577. }