#define ENV_SET_INCLUDED_SHADERS
using UnityEngine;
using UnityEditor;
using System.Collections;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using UnityEngine.Rendering;
using VRC.SDKBase.Validation.Performance.Stats;
using Object = UnityEngine.Object;
namespace VRC.Editor
{
///
/// Setup up SDK env on editor launch
///
[InitializeOnLoad]
public class EnvConfig
{
private static readonly BuildTarget[] relevantBuildTargets =
{
BuildTarget.Android,
BuildTarget.iOS,
BuildTarget.StandaloneLinux64,
BuildTarget.StandaloneWindows, BuildTarget.StandaloneWindows64,
BuildTarget.StandaloneOSX
};
#if !VRC_CLIENT
private static readonly BuildTarget[] allowedBuildtargets = {
BuildTarget.StandaloneWindows64,
BuildTarget.Android
};
#endif
private static readonly Dictionary allowedGraphicsAPIs = new Dictionary()
{
{BuildTarget.Android, new[] {GraphicsDeviceType.OpenGLES3, /* GraphicsDeviceType.Vulkan */}},
{BuildTarget.iOS, null},
{BuildTarget.StandaloneLinux64, null},
{BuildTarget.StandaloneWindows, new[] {GraphicsDeviceType.Direct3D11}},
{BuildTarget.StandaloneWindows64, new[] {GraphicsDeviceType.Direct3D11}},
{BuildTarget.StandaloneOSX, null}
};
#if ENV_SET_INCLUDED_SHADERS && VRC_CLIENT
private static readonly string[] ensureTheseShadersAreAvailable =
{
"Hidden/CubeBlend",
"Hidden/CubeBlur",
"Hidden/CubeCopy",
"Hidden/VideoDecode",
"Legacy Shaders/Bumped Diffuse",
"Legacy Shaders/Bumped Specular",
"Legacy Shaders/Decal",
"Legacy Shaders/Diffuse Detail",
"Legacy Shaders/Diffuse Fast",
"Legacy Shaders/Diffuse",
"Legacy Shaders/Diffuse",
"Legacy Shaders/Lightmapped/Diffuse",
"Legacy Shaders/Lightmapped/Specular",
"Legacy Shaders/Lightmapped/VertexLit",
"Legacy Shaders/Parallax Diffuse",
"Legacy Shaders/Parallax Specular",
"Legacy Shaders/Reflective/Bumped Diffuse",
"Legacy Shaders/Reflective/Bumped Specular",
"Legacy Shaders/Reflective/Bumped Unlit",
"Legacy Shaders/Reflective/Bumped VertexLit",
"Legacy Shaders/Reflective/Diffuse",
"Legacy Shaders/Reflective/Parallax Diffuse",
"Legacy Shaders/Reflective/Parallax Specular",
"Legacy Shaders/Reflective/Specular",
"Legacy Shaders/Reflective/VertexLit",
"Legacy Shaders/Self-Illumin/Bumped Diffuse",
"Legacy Shaders/Self-Illumin/Bumped Specular",
"Legacy Shaders/Self-Illumin/Diffuse",
"Legacy Shaders/Self-Illumin/Parallax Diffuse",
"Legacy Shaders/Self-Illumin/Parallax Specular",
"Legacy Shaders/Self-Illumin/Specular",
"Legacy Shaders/Self-Illumin/VertexLit",
"Legacy Shaders/Specular",
"Legacy Shaders/Transparent/Bumped Diffuse",
"Legacy Shaders/Transparent/Bumped Specular",
"Legacy Shaders/Transparent/Cutout/Bumped Diffuse",
"Legacy Shaders/Transparent/Cutout/Bumped Specular",
"Legacy Shaders/Transparent/Cutout/Diffuse",
"Legacy Shaders/Transparent/Cutout/Soft Edge Unlit",
"Legacy Shaders/Transparent/Cutout/Specular",
"Legacy Shaders/Transparent/Cutout/VertexLit",
"Legacy Shaders/Transparent/Diffuse",
"Legacy Shaders/Transparent/Parallax Diffuse",
"Legacy Shaders/Transparent/Parallax Specular",
"Legacy Shaders/Transparent/Specular",
"Legacy Shaders/Transparent/VertexLit",
"Legacy Shaders/VertexLit",
"Legacy Shaders/Particles/Additive",
"Legacy Shaders/Particles/~Additive-Multiply",
"Legacy Shaders/Particles/Additive (Soft)",
"Legacy Shaders/Particles/Alpha Blended",
"Legacy Shaders/Particles/Anim Alpha Blended",
"Legacy Shaders/Particles/Multiply",
"Legacy Shaders/Particles/Multiply (Double)",
"Legacy Shaders/Particles/Alpha Blended Premultiply",
"Legacy Shaders/Particles/VertexLit Blended",
"Mobile/Particles/Additive",
"Mobile/Particles/Alpha Blended",
"Mobile/Particles/Multiply",
"Mobile/Particles/VertexLit Blended",
"Mobile/Skybox",
"Nature/Terrain/Diffuse",
"Nature/Terrain/Specular",
"Nature/Terrain/Standard",
"Particles/Additive (Soft)",
"Particles/Additive",
"Particles/Alpha Blended Premultiply",
"Particles/Alpha Blended",
"Particles/Anim Alpha Blended",
"Particles/Multiply (Double)",
"Particles/Multiply",
"Particles/VertexLit Blended",
"Particles/~Additive-Multiply",
"Skybox/Cubemap",
"Skybox/Procedural",
"Skybox/6 Sided",
"Sprites/Default",
"Sprites/Diffuse",
"UI/Default",
"VRChat/UI/Unlit/WebPanelTransparent",
"Toon/Lit",
"Toon/Lit (Double)",
"Toon/Lit Cutout",
"Toon/Lit Cutout (Double)",
"Toon/Lit Outline",
"VRChat/Mobile/Diffuse",
"Video/RealtimeEmissiveGamma",
"VRChat/PC/Toon Lit",
"VRChat/PC/Toon Lit (Double)",
"VRChat/PC/Toon Lit Cutout",
"VRChat/PC/Toon Lit Cutout (Double)",
"Unlit/Color",
"Unlit/Transparent",
"Unlit/Transparent Cutout",
"Unlit/Texture",
"MatCap/Vertex/Textured Lit",
"VRChat/Mobile/Bumped Uniform Diffuse",
"VRChat/Mobile/Bumped Uniform Specular",
"VRChat/Mobile/Toon Lit",
"VRChat/Mobile/MatCap Lit",
"VRChat/Mobile/Skybox",
"VRChat/Mobile/Lightmapped",
"VRChat/Mobile/Bumped Mapped Specular",
"VRChat/Mobile/Diffuse",
"VRChat/Mobile/Particles/Additive",
"VRChat/Mobile/Particles/Multiply",
"VRChat/Mobile/Standard Lite",
"TextMeshPro/Distance Field (Surface)",
"TextMeshPro/Mobile/Distance Field (No ZTest)",
"TextMeshPro/Distance Field Overlay",
"TextMeshPro/Sprite",
"TextMeshPro/Mobile/Distance Field - Masking",
"TextMeshPro/Mobile/Distance Field Overlay",
"TextMeshPro/Mobile/Distance Field (Surface)",
"TextMeshPro/Mobile/Distance Field",
"TextMeshPro/Distance Field",
"TextMeshPro/Bitmap Custom Atlas",
"VRChat/UI/TextMeshPro/Mobile/Distance Field",
"TextMeshPro/Mobile/Bitmap",
"TextMeshPro/Bitmap",
"TextMeshPro/Mobile/Distance Field - Masking (NoZTest)"
};
#endif
private static bool _requestConfigureSettings = true;
static EnvConfig()
{
EditorApplication.update += EditorUpdate;
}
private static void EditorUpdate()
{
if(!_requestConfigureSettings)
{
return;
}
if(ConfigureSettings())
{
_requestConfigureSettings = false;
}
}
private static void RequestConfigureSettings()
{
_requestConfigureSettings = true;
}
[UnityEditor.Callbacks.DidReloadScripts(int.MaxValue)]
private static void DidReloadScripts()
{
RequestConfigureSettings();
}
private static bool ConfigureSettings()
{
CheckForFirstInit();
if(EditorApplication.isPlayingOrWillChangePlaymode || EditorApplication.isUpdating)
{
return false;
}
ConfigurePlayerSettings();
if(!VRC.Core.ConfigManager.RemoteConfig.IsInitialized())
{
VRC.Core.API.SetOnlineMode(true, "vrchat");
VRC.Core.ConfigManager.RemoteConfig.Init();
}
ConfigureAssets();
LoadEditorResources();
return true;
}
#if !VRC_CLIENT
private static void SetDLLPlatforms(string dllName, bool active)
{
string[] assetGuids = AssetDatabase.FindAssets(dllName);
foreach(string guid in assetGuids)
{
string dllPath = AssetDatabase.GUIDToAssetPath(guid);
if(string.IsNullOrEmpty(dllPath) || dllPath.ToLower().EndsWith(".dll") == false)
{
return;
}
PluginImporter importer = AssetImporter.GetAtPath(dllPath) as PluginImporter;
if(importer == null)
{
return;
}
bool allCorrect = true;
if(importer.GetCompatibleWithAnyPlatform() != active)
{
allCorrect = false;
}
else
{
if(importer.GetCompatibleWithAnyPlatform())
{
if(importer.GetExcludeEditorFromAnyPlatform() != !active ||
importer.GetExcludeFromAnyPlatform(BuildTarget.StandaloneWindows) != !active)
{
allCorrect = false;
}
}
else
{
if(importer.GetCompatibleWithEditor() != active ||
importer.GetCompatibleWithPlatform(BuildTarget.StandaloneWindows) != active)
{
allCorrect = false;
}
}
}
if(allCorrect)
{
continue;
}
if(active)
{
importer.SetCompatibleWithAnyPlatform(true);
importer.SetExcludeEditorFromAnyPlatform(false);
importer.SetExcludeFromAnyPlatform(BuildTarget.Android, false);
importer.SetExcludeFromAnyPlatform(BuildTarget.StandaloneWindows, false);
importer.SetExcludeFromAnyPlatform(BuildTarget.StandaloneWindows64, false);
importer.SetExcludeFromAnyPlatform(BuildTarget.StandaloneLinux64, false);
}
else
{
importer.SetCompatibleWithAnyPlatform(false);
importer.SetCompatibleWithEditor(false);
importer.SetCompatibleWithPlatform(BuildTarget.Android, false);
importer.SetCompatibleWithPlatform(BuildTarget.StandaloneWindows, false);
importer.SetCompatibleWithPlatform(BuildTarget.StandaloneWindows64, false);
importer.SetCompatibleWithPlatform(BuildTarget.StandaloneLinux64, false);
}
importer.SaveAndReimport();
}
}
#endif
[MenuItem("VRChat SDK/Utilities/Force Configure Player Settings")]
public static void ConfigurePlayerSettings()
{
VRC.Core.Logger.Log("Setting required PlayerSettings...", VRC.Core.DebugLevel.All);
SetBuildTarget();
// Needed for Microsoft.CSharp namespace in DLLMaker
// Doesn't seem to work though
if(PlayerSettings.GetApiCompatibilityLevel(EditorUserBuildSettings.selectedBuildTargetGroup) != ApiCompatibilityLevel.NET_4_6)
{
PlayerSettings.SetApiCompatibilityLevel(EditorUserBuildSettings.selectedBuildTargetGroup, ApiCompatibilityLevel.NET_4_6);
}
if(!PlayerSettings.runInBackground)
{
PlayerSettings.runInBackground = true;
}
#if !VRC_CLIENT
SetDLLPlatforms("VRCCore-Standalone", false);
SetDLLPlatforms("VRCCore-Editor", true);
#endif
SetDefaultGraphicsAPIs();
SetGraphicsSettings();
SetQualitySettings();
SetAudioSettings();
SetPlayerSettings();
#if VRC_CLIENT
AssetDatabase.SaveAssets();
AssetDatabase.Refresh();
PlatformSwitcher.RefreshRequiredPackages(EditorUserBuildSettings.selectedBuildTargetGroup);
#else
// SDK
// default to steam runtime in sdk (shouldn't matter)
SetVRSDKs(EditorUserBuildSettings.selectedBuildTargetGroup, new string[] { "None", "OpenVR", "Oculus" });
VRC.Core.AnalyticsSDK.Initialize(VRC.Core.SDKClientUtilities.GetSDKVersionDate());
#endif
#if VRC_CLIENT
// VRCLog should handle disk writing
PlayerSettings.usePlayerLog = false;
foreach(LogType logType in Enum.GetValues(typeof(LogType)).Cast())
{
switch(logType)
{
case LogType.Assert:
case LogType.Exception:
{
PlayerSettings.SetStackTraceLogType(logType, StackTraceLogType.ScriptOnly);
break;
}
case LogType.Error:
case LogType.Warning:
case LogType.Log:
{
#if UNITY_EDITOR
PlayerSettings.SetStackTraceLogType(logType, StackTraceLogType.ScriptOnly);
#else
PlayerSettings.SetStackTraceLogType(logType, StackTraceLogType.None);
#endif
break;
}
default:
{
throw new ArgumentOutOfRangeException();
}
}
}
#endif
}
private static void EnableBatching(bool enable)
{
PlayerSettings[] playerSettings = Resources.FindObjectsOfTypeAll();
if(playerSettings == null)
{
return;
}
SerializedObject playerSettingsSerializedObject = new SerializedObject(playerSettings.Cast