cvr-props/Assets/ABI.CCK/Scripts/Editor/CCK_Init.cs

118 lines
4.9 KiB
C#
Raw Normal View History

using System.IO;
2023-01-22 16:38:23 +01:00
using UnityEditor;
using UnityEditor.Build.Content;
2023-01-22 16:38:23 +01:00
using UnityEngine;
2023-07-30 01:20:46 +02:00
using UnityEngine.XR;
2023-01-22 16:38:23 +01:00
#pragma warning disable
[InitializeOnLoad]
public class CCK_Init
{
static CCK_Init()
{
const string cckSymbol = "CVR_CCK_EXISTS";
BuildTargetGroup selectedTargetGroup = EditorUserBuildSettings.selectedBuildTargetGroup;
string defines = PlayerSettings.GetScriptingDefineSymbolsForGroup(selectedTargetGroup);
2023-01-22 16:38:23 +01:00
if (!defines.Contains(cckSymbol))
{
PlayerSettings.SetScriptingDefineSymbolsForGroup(selectedTargetGroup, defines + ";" + cckSymbol);
2023-01-22 16:38:23 +01:00
Debug.Log("[CCK:Init] Added CVR_CCK_EXISTS Scripting Symbol.");
}
bool shouldRecreateTagManager = LayerMask.LayerToName(10) != "PlayerNetwork"
|| LayerMask.LayerToName(15) != "CVRReserved3"
|| LayerMask.LayerToName(6) != "PassPlayer";
if (shouldRecreateTagManager)
2023-01-22 16:38:23 +01:00
{
Debug.Log("[CCK:Init] TagManager asset has to be recreated. Now recreating.");
ResetTagManager();
2023-01-22 16:38:23 +01:00
}
2023-07-30 01:20:46 +02:00
#if UNITY_2021_1_OR_NEWER
if (true)
#else
2023-01-22 16:38:23 +01:00
if (!PlayerSettings.virtualRealitySupported)
2023-07-30 01:20:46 +02:00
#endif
2023-01-22 16:38:23 +01:00
{
Debug.Log("[CCK:Init] XR and render settings have to be changed. Now changing.");
#if PLATFORM_ANDROID
2023-07-30 01:20:46 +02:00
if (EditorUserBuildSettings.activeBuildTarget != BuildTarget.Android)
EditorUserBuildSettings.SwitchActiveBuildTarget(BuildTargetGroup.Android, BuildTarget.Android);
#else
2023-07-30 01:20:46 +02:00
if (EditorUserBuildSettings.activeBuildTarget != BuildTarget.StandaloneWindows64)
EditorUserBuildSettings.SwitchActiveBuildTarget(BuildTargetGroup.Standalone, BuildTarget.StandaloneWindows64);
#endif
2023-01-22 16:38:23 +01:00
PlayerSettings.colorSpace = ColorSpace.Linear;
PlayerSettings.apiCompatibilityLevel = ApiCompatibilityLevel.NET_4_6;
PlayerSettings.legacyClampBlendShapeWeights = true;
#if UNITY_2021_1_OR_NEWER
2023-07-30 01:20:46 +02:00
PlayerSettings.virtualRealitySupported = true;
PlayerSettings.stereoRenderingPath = StereoRenderingPath.Instancing;
XRSettings.enabled = false;
#else
2023-01-22 16:38:23 +01:00
PlayerSettings.virtualRealitySupported = true;
PlayerSettings.SetVirtualRealitySDKs(BuildTargetGroup.Standalone, new[] { "None", "Oculus", "OpenVR", "MockHMD" });
2023-01-22 16:38:23 +01:00
PlayerSettings.stereoRenderingPath = StereoRenderingPath.SinglePass;
#endif
2023-01-22 16:38:23 +01:00
}
if (!shouldRecreateTagManager && PlayerSettings.virtualRealitySupported)
2023-01-22 16:38:23 +01:00
Debug.Log("[CCK:Init] Verified TagManager and ProjectSettings. No need to readjust.");
}
public static void ResetTagManager(bool forceReset = false)
{
SerializedObject tagManager = new (AssetDatabase.LoadAllAssetsAtPath("ProjectSettings/TagManager.asset")[0]);
SerializedProperty layerProperty = tagManager.FindProperty("layers");
var layerList = new (int Index, string Name)[]
{
// game layers, can be force renamed
(6, "PassPlayer"), (7, "BlockPlayer"),
(8, "PlayerLocal"), (9, "PlayerClone"), (10, "PlayerNetwork"),
(11, "MirrorReflection"), (12, "Camera Only"),
(13, "CVRReserved1"), (14, "CVRReserved2"), (15, "CVRReserved3"),
// User Content world layers, do not normally force rename
(16, "CVRContent1 (can be renamed)"), (17, "CVRContent2 (can be renamed)"),
(18, "CVRContent3 (can be renamed)"), (19, "CVRContent4 (can be renamed)"),
(20, "CVRContent5 (can be renamed)"), (21, "CVRContent6 (can be renamed)"),
(22, "CVRContent7 (can be renamed)"), (23, "CVRContent8 (can be renamed)"),
(24, "CVRContent9 (can be renamed)"), (25, "CVRContent10 (can be renamed)"),
(26, "CVRContent11 (can be renamed)"), (27, "CVRContent12 (can be renamed)"),
(28, "CVRContent13 (can be renamed)"), (29, "CVRContent14 (can be renamed)"),
(30, "CVRContent15 (can be renamed)"), (31, "CVRContent16 (can be renamed)")
};
foreach (var (Index, Name) in layerList)
{
SerializedProperty sp = layerProperty.GetArrayElementAtIndex(Index);
if (sp == null) continue;
// always rename
if (Index >= 6 && Index <= 15)
{
sp.stringValue = Name;
}
// only rename if legacy or forced
else if (forceReset ||
sp.stringValue == "" ||
sp.stringValue == "PostProcessing" || // :)
sp.stringValue == "CVRPickup" ||
sp.stringValue == "CVRInteractable" ||
sp.stringValue.StartsWith("RCC_"))
{
sp.stringValue = Name;
}
2023-01-22 16:38:23 +01:00
}
tagManager.ApplyModifiedProperties();
2023-01-22 16:38:23 +01:00
}
}