Skip to content

Commit

Permalink
Fix open GameView on another window when using Focus and Gizmos attri…
Browse files Browse the repository at this point in the history
…butes
  • Loading branch information
nowsprinting committed Nov 1, 2023
1 parent 3799762 commit 98ef199
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
9 changes: 9 additions & 0 deletions RuntimeInternals/GameViewControlHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ public static class GameViewControlHelper
public static void Focus()
{
#if UNITY_EDITOR
#if UNITY_2022_2_OR_NEWER
PlayModeWindow.SetViewType(PlayModeWindow.PlayModeViewTypes.GameView);
#endif
GameViewWrapper.GetWindow();
#endif
}
Expand All @@ -33,6 +36,9 @@ public static bool GetGizmos()
{
var gizmos = false;
#if UNITY_EDITOR
#if UNITY_2022_2_OR_NEWER
PlayModeWindow.SetViewType(PlayModeWindow.PlayModeViewTypes.GameView);
#endif
var gameViewWrapper = GameViewWrapper.GetWindow(false);
if (gameViewWrapper != null)
{
Expand All @@ -49,6 +55,9 @@ public static bool GetGizmos()
public static void SetGizmos(bool show)
{
#if UNITY_EDITOR
#if UNITY_2022_2_OR_NEWER
PlayModeWindow.SetViewType(PlayModeWindow.PlayModeViewTypes.GameView);
#endif
var gameViewWrapper = GameViewWrapper.GetWindow(false);
if (gameViewWrapper != null)
{
Expand Down
21 changes: 17 additions & 4 deletions Tests/Runtime/Attributes/FocusGameViewAttributeTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,14 @@ namespace TestHelper.Attributes
[UnityPlatform(RuntimePlatform.OSXEditor, RuntimePlatform.WindowsEditor, RuntimePlatform.LinuxEditor)]
public class FocusGameViewAttributeTest
{
private const string GameView = "UnityEditor.GameView";
private const string SimulatorWindow = "UnityEditor.DeviceSimulation.SimulatorWindow";

[Test]
[IgnoreBatchMode("Open GameView in batchmode but can not get window.")]
[FocusGameView]
public void Attach_GameViewHasFocus()
{
const string GameView = "UnityEditor.GameView";
const string SimulatorWindow = "UnityEditor.DeviceSimulation.SimulatorWindow";
#if UNITY_EDITOR
var focusedWindow = EditorWindow.focusedWindow;
Assert.That(focusedWindow, Is.Not.Null);
Expand All @@ -39,16 +40,28 @@ public void Attach_KeepBatchmode()
}

[Test]
[IgnoreBatchMode("Open GameView in batchmode but can not get window.")]
[FocusGameView]
public async Task AttachToAsyncTest_Normally()
public async Task AttachToAsyncTest_GameViewHasFocus()
{
#if UNITY_EDITOR
var focusedWindow = EditorWindow.focusedWindow;
Assert.That(focusedWindow, Is.Not.Null);
Assert.That(focusedWindow.GetType().FullName, Is.EqualTo(GameView).Or.EqualTo(SimulatorWindow));
#endif
await Task.Yield();
}

[UnityTest]
[IgnoreBatchMode("Open GameView in batchmode but can not get window.")]
[FocusGameView]
public IEnumerator AttachToUnityTest_Normally()
public IEnumerator AttachToUnityTest_GameViewHasFocus()
{
#if UNITY_EDITOR
var focusedWindow = EditorWindow.focusedWindow;
Assert.That(focusedWindow, Is.Not.Null);
Assert.That(focusedWindow.GetType().FullName, Is.EqualTo(GameView).Or.EqualTo(SimulatorWindow));
#endif
yield return null;
}
}
Expand Down

0 comments on commit 98ef199

Please sign in to comment.