From 4e283b02a555688f07ae0f4b5bd289b9a73334ba Mon Sep 17 00:00:00 2001 From: fumiko <2394425147@qq.com> Date: Mon, 6 Jan 2025 01:47:43 +0800 Subject: [PATCH] bugfix: convert `selectedBuildTargetGroup` to `NamedBuildTarget` when using unity 2021.3 or newer --- .../Editor/UIEffectProjectSettingsEditor.cs | 24 +++++++++++-------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/Packages/src/Editor/UIEffectProjectSettingsEditor.cs b/Packages/src/Editor/UIEffectProjectSettingsEditor.cs index 392518b..9e7fcdd 100644 --- a/Packages/src/Editor/UIEffectProjectSettingsEditor.cs +++ b/Packages/src/Editor/UIEffectProjectSettingsEditor.cs @@ -4,6 +4,10 @@ using Coffee.UIEffectInternal; using UnityEditorInternal; +#if UNITY_2021_3_OR_NEWER +using UnityEditor.Build; +#endif + namespace Coffee.UIEffects.Editors { [CustomEditor(typeof(UIEffectProjectSettings))] @@ -65,8 +69,8 @@ private void Awake() { // Called when the domain reloads, // So we check if the scripting define is altered manually -#if UNITY_2023_1_OR_NEWER - PlayerSettings.GetScriptingDefineSymbols(EditorUserBuildSettings.selectedBuildTargetGroup, out var defines); +#if UNITY_2021_3_OR_NEWER + PlayerSettings.GetScriptingDefineSymbols(NamedBuildTarget.FromBuildTargetGroup(EditorUserBuildSettings.selectedBuildTargetGroup), out var defines); #else PlayerSettings.GetScriptingDefineSymbolsForGroup(EditorUserBuildSettings.selectedBuildTargetGroup, out var defines); #endif @@ -87,8 +91,8 @@ public override void OnInspectorGUI() _noHdrGradient = !_noHdrGradient; if (_noHdrGradient) { -#if UNITY_2023_1_OR_NEWER - PlayerSettings.GetScriptingDefineSymbols(EditorUserBuildSettings.selectedBuildTargetGroup, out var defines); +#if UNITY_2021_3_OR_NEWER + PlayerSettings.GetScriptingDefineSymbols(NamedBuildTarget.FromBuildTargetGroup(EditorUserBuildSettings.selectedBuildTargetGroup), out var defines); #else PlayerSettings.GetScriptingDefineSymbolsForGroup(EditorUserBuildSettings.selectedBuildTargetGroup, out var defines); #endif @@ -96,16 +100,16 @@ public override void OnInspectorGUI() Array.Resize(ref defines, defines.Length + 1); defines[defines.Length - 1] = k_NoHDRGradientScriptingDefine; -#if UNITY_2023_1_OR_NEWER - PlayerSettings.SetScriptingDefineSymbols(EditorUserBuildSettings.selectedBuildTargetGroup, defines); +#if UNITY_2021_3_OR_NEWER + PlayerSettings.SetScriptingDefineSymbols(NamedBuildTarget.FromBuildTargetGroup(EditorUserBuildSettings.selectedBuildTargetGroup), defines); #else PlayerSettings.SetScriptingDefineSymbolsForGroup(EditorUserBuildSettings.selectedBuildTargetGroup, defines); #endif } else { -#if UNITY_2023_1_OR_NEWER - PlayerSettings.GetScriptingDefineSymbols(EditorUserBuildSettings.selectedBuildTargetGroup, out var defines); +#if UNITY_2021_3_OR_NEWER + PlayerSettings.GetScriptingDefineSymbols(NamedBuildTarget.FromBuildTargetGroup(EditorUserBuildSettings.selectedBuildTargetGroup), out var defines); #else PlayerSettings.GetScriptingDefineSymbolsForGroup(EditorUserBuildSettings.selectedBuildTargetGroup, out var defines); #endif @@ -113,8 +117,8 @@ public override void OnInspectorGUI() defines[Array.IndexOf(defines, k_NoHDRGradientScriptingDefine)] = defines[defines.Length - 1]; Array.Resize(ref defines, defines.Length - 1); -#if UNITY_2023_1_OR_NEWER - PlayerSettings.SetScriptingDefineSymbols(EditorUserBuildSettings.selectedBuildTargetGroup, defines); +#if UNITY_2021_3_OR_NEWER + PlayerSettings.SetScriptingDefineSymbols(NamedBuildTarget.FromBuildTargetGroup(EditorUserBuildSettings.selectedBuildTargetGroup), defines); #else PlayerSettings.SetScriptingDefineSymbolsForGroup(EditorUserBuildSettings.selectedBuildTargetGroup, defines); #endif