update CCK to 3.10, fixing unity 2021 crash :)

This commit is contained in:
Crispy 2024-08-03 22:24:42 +02:00
parent 48a978fa2a
commit d11e0fb3a9
492 changed files with 2165204 additions and 437687 deletions

View file

@ -1,7 +1,6 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using UnityEditor;
using UnityEditor.Build.Content;
using UnityEngine;
using UnityEngine.XR;
@ -12,79 +11,24 @@ public class CCK_Init
{
static CCK_Init()
{
void SetTag(SerializedProperty tags, string name, int index)
{
SerializedProperty sp = null;
try
{
sp = tags.GetArrayElementAtIndex(index);
}
catch{}
const string cckSymbol = "CVR_CCK_EXISTS";
BuildTargetGroup selectedTargetGroup = EditorUserBuildSettings.selectedBuildTargetGroup;
string defines = PlayerSettings.GetScriptingDefineSymbolsForGroup(selectedTargetGroup);
if (sp != null) sp.stringValue = name;
}
void SetLayer(SerializedProperty layers, string name, int index)
{
SerializedProperty sp = null;
try
{
sp = layers.GetArrayElementAtIndex(index);
}
catch{}
if (sp != null) sp.stringValue = name;
}
string cckSymbol = "CVR_CCK_EXISTS";
string defines = PlayerSettings.GetScriptingDefineSymbolsForGroup(EditorUserBuildSettings.selectedBuildTargetGroup);
if (!defines.Contains(cckSymbol))
{
PlayerSettings.SetScriptingDefineSymbolsForGroup(EditorUserBuildSettings.selectedBuildTargetGroup, (defines + ";" + cckSymbol));
PlayerSettings.SetScriptingDefineSymbolsForGroup(selectedTargetGroup, defines + ";" + cckSymbol);
Debug.Log("[CCK:Init] Added CVR_CCK_EXISTS Scripting Symbol.");
}
if (LayerMask.LayerToName(10) != "PlayerNetwork" || LayerMask.LayerToName(15) != "CVRReserved4" || LayerMask.LayerToName(17) != "CVRPickup")
bool shouldRecreateTagManager = LayerMask.LayerToName(10) != "PlayerNetwork"
|| LayerMask.LayerToName(15) != "CVRReserved3"
|| LayerMask.LayerToName(6) != "PassPlayer";
if (shouldRecreateTagManager)
{
Debug.Log("[CCK:Init] TagManager asset has to be recreated. Now recreating.");
SerializedObject tagManager = new SerializedObject(AssetDatabase.LoadAllAssetsAtPath("ProjectSettings/TagManager.asset")[0]);
SerializedProperty tagProperty = tagManager.FindProperty("tags");
var tagList = new (int, string)[]
{
(0, "CCKEditorUI_Uploader"),
(1, "CCKSerializable"),
(2, "CCKLambda"),
(3, "CCKNetwork_System"),
(4, "CCKNetwork_Routine"),
(5, "ThisIsGarbage")
};
foreach (var tag in tagList) SetTag(tagProperty, tag.Item2, tag.Item1);
SerializedProperty layerProperty = tagManager.FindProperty("layers");
var layerList = new (int, string)[]
{
(8, "PlayerLocal"),
(9, "PlayerClone"),
(10, "PlayerNetwork"),
(11, "MirrorReflection"),
(12, "CVRReserved1"),
(13, "CVRReserved2"),
(14, "CVRReserved3"),
(15, "CVRReserved4"),
(16, "PostProcessing"),
(17, "CVRPickup"),
(18, "CVRInteractable")
};
foreach (var layer in layerList) SetLayer(layerProperty, layer.Item2, layer.Item1);
tagManager.ApplyModifiedProperties();
ResetTagManager();
}
#if UNITY_2021_1_OR_NEWER
@ -94,31 +38,81 @@ public class CCK_Init
#endif
{
Debug.Log("[CCK:Init] XR and render settings have to be changed. Now changing.");
#if PLATFORM_ANDROID
#if PLATFORM_ANDROID
if (EditorUserBuildSettings.activeBuildTarget != BuildTarget.Android)
EditorUserBuildSettings.SwitchActiveBuildTarget(BuildTargetGroup.Standalone, BuildTarget.Android);
#else
EditorUserBuildSettings.SwitchActiveBuildTarget(BuildTargetGroup.Android, BuildTarget.Android);
#else
if (EditorUserBuildSettings.activeBuildTarget != BuildTarget.StandaloneWindows64)
EditorUserBuildSettings.SwitchActiveBuildTarget(BuildTargetGroup.Standalone, BuildTarget.StandaloneWindows64);
#endif
PlayerSettings.colorSpace = UnityEngine.ColorSpace.Linear;
PlayerSettings.apiCompatibilityLevel = ApiCompatibilityLevel.NET_4_6;
#endif
#if UNITY_2021_1_OR_NEWER
PlayerSettings.colorSpace = ColorSpace.Linear;
PlayerSettings.apiCompatibilityLevel = ApiCompatibilityLevel.NET_4_6;
PlayerSettings.legacyClampBlendShapeWeights = true;
#if UNITY_2021_1_OR_NEWER
PlayerSettings.virtualRealitySupported = true;
PlayerSettings.stereoRenderingPath = StereoRenderingPath.Instancing;
XRSettings.enabled = false;
#else
#else
PlayerSettings.virtualRealitySupported = true;
PlayerSettings.SetVirtualRealitySDKs(BuildTargetGroup.Standalone, new string[] { "None", "Oculus", "OpenVR", "MockHMD" });
PlayerSettings.SetVirtualRealitySDKs(BuildTargetGroup.Standalone, new[] { "None", "Oculus", "OpenVR", "MockHMD" });
PlayerSettings.stereoRenderingPath = StereoRenderingPath.SinglePass;
#endif
#endif
}
if (LayerMask.LayerToName(10) == "PlayerNetwork" && LayerMask.LayerToName(17) == "CVRPickup" && LayerMask.LayerToName(15) == "CVRReserved4" && PlayerSettings.virtualRealitySupported )
{
if (!shouldRecreateTagManager && PlayerSettings.virtualRealitySupported)
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;
}
}
tagManager.ApplyModifiedProperties();
}
}