Skip to content

Commit

Permalink
bugfix: convert selectedBuildTargetGroup to NamedBuildTarget when…
Browse files Browse the repository at this point in the history
… using unity 2021.3 or newer
  • Loading branch information
2394425147 committed Jan 5, 2025
1 parent 35a8083 commit 4e283b0
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions Packages/src/Editor/UIEffectProjectSettingsEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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))]
Expand Down Expand Up @@ -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
Expand All @@ -87,34 +91,34 @@ 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

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

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
Expand Down

0 comments on commit 4e283b0

Please sign in to comment.