Skip to content

Commit cfc9c32

Browse files
committed
fix: Resolve issue where incorrect platform was being auto-selected in the EOS Configuration window.
1 parent 14826ee commit cfc9c32

File tree

2 files changed

+45
-16
lines changed

2 files changed

+45
-16
lines changed

Assets/Plugins/Source/Editor/EditorWindows/EOSSettingsWindow.cs

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -138,15 +138,15 @@ protected override async Task AsyncSetup()
138138
int tabIndex = 0;
139139
foreach (PlatformManager.Platform platform in Enum.GetValues(typeof(PlatformManager.Platform)))
140140
{
141-
// This makes sure that the currently selected tab (upon first loading the window) is always the current platform.
142-
if (_selectedTab != -1 || platform == PlatformManager.CurrentPlatform)
141+
if (!PlatformManager.TryGetConfigType(platform, out Type configType) || null == configType)
143142
{
144-
_selectedTab = tabIndex;
143+
continue;
145144
}
146145

147-
if (!PlatformManager.TryGetConfigType(platform, out Type configType) || null == configType)
146+
// This makes sure that the currently selected tab (upon first loading the window) is always the current platform.
147+
if (_selectedTab == -1 && platform == PlatformManager.CurrentTargetedPlatform)
148148
{
149-
continue;
149+
_selectedTab = tabIndex;
150150
}
151151

152152
Type constructedType =
@@ -162,17 +162,15 @@ protected override async Task AsyncSetup()
162162
// Do not add the platform if it is not currently available.
163163
if (!editor.IsPlatformAvailable())
164164
{
165-
// We only increment the tab index if the editor has been
166-
// added to the tabs.
167-
tabIndex++;
168165
continue;
169166
}
170167
#endif
171168

169+
tabIndex++;
170+
172171
_platformConfigEditors.Add(editor);
173172

174173
tabContents.Add(new GUIContent($" {editor.GetLabelText()}", editor.GetPlatformIconTexture()));
175-
176174
}
177175

178176
// If (for some reason) a default platform was not selected, then
@@ -197,7 +195,14 @@ protected override void RenderWindow()
197195

198196
if (_platformTabs != null && _platformConfigEditors.Count != 0)
199197
{
200-
_selectedTab = GUILayout.Toolbar(_selectedTab, _platformTabs, TAB_STYLE);
198+
var newlySelectedTabIndex = GUILayout.Toolbar(_selectedTab, _platformTabs, TAB_STYLE);
199+
200+
if (newlySelectedTabIndex != _selectedTab)
201+
{
202+
_selectedTab = newlySelectedTabIndex;
203+
Debug.Log($"Selected config tab changed to {_selectedTab}.");
204+
}
205+
201206
GUILayout.Space(30);
202207

203208
_ = _platformConfigEditors[_selectedTab].RenderAsync();

com.playeveryware.eos/Runtime/Core/PlatformManager.cs

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -159,12 +159,42 @@ public static Platform CurrentPlatform
159159
}
160160
else
161161
{
162+
// Note that s_CurrentPlatform is not set in this context - making sure it's only set once.
163+
// TODO: Investigate whether this has unintended consequences - where setting the value is
164+
// expected.
162165
Debug.Log($"CurrentPlatform has already been assigned as {GetFullName(s_CurrentPlatform)}.");
163166
}
164167

165168
}
166169
}
167170

171+
/// <summary>
172+
/// Backing value for the CurrentTargetedPlatform property.
173+
/// </summary>
174+
private static Platform s_CurrentTargetedPlatform;
175+
176+
// This compile conditional is here because this property is only
177+
// meaningful in the context of the Unity Editor running.
178+
#if UNITY_EDITOR
179+
/// <summary>
180+
/// Used to indicate what platform is currently being targeted for
181+
/// compilation. Used primarily to select the appropriate platform in
182+
/// config editors.
183+
/// </summary>
184+
public static Platform CurrentTargetedPlatform
185+
{
186+
get
187+
{
188+
if (!TryGetPlatform(EditorUserBuildSettings.activeBuildTarget, out Platform targetedPlatform))
189+
{
190+
return Platform.Unknown;
191+
}
192+
193+
return targetedPlatform;
194+
}
195+
}
196+
#endif
197+
168198
/// <summary>
169199
/// To be accessible to the platform manager, the static constructors
170200
/// for each platform config need to be executed, this function ensures
@@ -204,16 +234,10 @@ static PlatformManager()
204234
// is Windows.
205235
#if EXTERNAL_TO_UNITY
206236
CurrentPlatform = Platform.Windows;
207-
#else
208-
// If the Unity Editor is currently running, then the "active"
209-
// Platform is whatever the current build target is.
210-
#if UNITY_EDITOR
211-
if (TryGetPlatform(EditorUserBuildSettings.activeBuildTarget, out Platform platform))
212237
#else
213238
// If the Unity editor is _not_ currently running, then the "active"
214239
// platform is whatever the runtime application says it is
215240
if (TryGetPlatform(Application.platform, out Platform platform))
216-
#endif
217241
{
218242
CurrentPlatform = platform;
219243
}

0 commit comments

Comments
 (0)