-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #36 from nowsprinting/chore/isolate_internals
Isolate internal implementation not depending on test-framework codes
- Loading branch information
Showing
40 changed files
with
478 additions
and
150 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
// Copyright (c) 2023 Koji Hasegawa. | ||
// This software is released under the MIT License. | ||
|
||
using System.Reflection; | ||
using System.Runtime.CompilerServices; | ||
|
||
[assembly: AssemblyTitle("Internal implementation for the TestHelper package")] | ||
[assembly: AssemblyDescription( | ||
@"This assembly can be used from the runtime code because it does not depend on test-framework. | ||
This assembly is named ""Internal"", however, the included classes are public.")] | ||
|
||
[assembly: InternalsVisibleTo("TestHelper.RuntimeInternals.Tests")] |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
// Copyright (c) 2023 Koji Hasegawa. | ||
// This software is released under the MIT License. | ||
|
||
using System; | ||
using System.Reflection; | ||
using TestHelper.RuntimeInternals.Wrappers.UnityEditor; | ||
using UnityEditor; | ||
using UnityEngine; | ||
|
||
namespace TestHelper.RuntimeInternals | ||
{ | ||
/// <summary> | ||
/// <c>GameView</c> control helper. | ||
/// This class can be used from the runtime code because it does not depend on test-framework. | ||
/// </summary> | ||
public static class GameViewControlHelper | ||
{ | ||
private static Type s_gameView; | ||
|
||
/// <summary> | ||
/// Focus <c>GameView</c> or <c>SimulatorWindow</c>. | ||
/// </summary> | ||
public static void Focus() | ||
{ | ||
#if UNITY_EDITOR | ||
if (s_gameView == null) | ||
{ | ||
var assembly = Assembly.Load("UnityEditor.dll"); | ||
var viewClass = Application.isBatchMode ? "UnityEditor.GameView" : "UnityEditor.PlayModeView"; | ||
// Note: Freezes when getting SimulatorWindow in batchmode | ||
|
||
s_gameView = assembly.GetType(viewClass); | ||
} | ||
|
||
EditorWindow.GetWindow(s_gameView, false, null, true); | ||
#endif | ||
} | ||
|
||
/// <summary> | ||
/// Set <c>GameView</c> resolution. | ||
/// </summary> | ||
/// <param name="width">GameView width [px]</param> | ||
/// <param name="height">GameView height [px]</param> | ||
/// <param name="name">GameViewSize name</param> | ||
public static void SetResolution(uint width, uint height, string name) | ||
{ | ||
#if UNITY_2022_2_OR_NEWER | ||
SetResolutionUsingPlayModeWindow(width, height, name); | ||
#else | ||
SetResolutionUsingReflection(width, height, name); | ||
#endif | ||
} | ||
|
||
// ReSharper disable once UnusedMember.Local | ||
private static void SetResolutionUsingPlayModeWindow(uint width, uint height, string name) | ||
{ | ||
#if UNITY_EDITOR && UNITY_2022_2_OR_NEWER | ||
PlayModeWindow.SetViewType(PlayModeWindow.PlayModeViewTypes.GameView); | ||
PlayModeWindow.SetCustomRenderingResolution(width, height, name); | ||
#endif | ||
} | ||
|
||
// ReSharper disable once UnusedMember.Local | ||
private static void SetResolutionUsingReflection(uint width, uint height, string name) | ||
{ | ||
#if UNITY_EDITOR | ||
var gameViewSizes = GameViewSizesWrapper.CreateInstance(); | ||
if (gameViewSizes == null) | ||
{ | ||
Debug.LogError("GameViewSizes instance creation failed."); | ||
return; | ||
} | ||
|
||
var gameViewSizeGroup = gameViewSizes.CurrentGroup(); | ||
if (gameViewSizeGroup == null) | ||
{ | ||
Debug.LogError("GameViewSizeGroup instance creation failed."); | ||
return; | ||
} | ||
|
||
var gameViewSize = GameViewSizeWrapper.CreateInstance((int)width, (int)height, name); | ||
if (gameViewSize == null) | ||
{ | ||
Debug.LogError("GameViewSize instance creation failed."); | ||
return; | ||
} | ||
|
||
var index = gameViewSizeGroup.IndexOf(gameViewSize); | ||
if (index == -1) | ||
{ | ||
gameViewSizeGroup.AddCustomSize(gameViewSize); | ||
index = gameViewSizeGroup.IndexOf(gameViewSize); | ||
} | ||
|
||
var gameView = GameViewWrapper.GetWindow(); | ||
if (gameView == null) | ||
{ | ||
Debug.LogError("GameView instance creation failed."); | ||
return; | ||
} | ||
|
||
gameView.SelectedSizeIndex(index); | ||
#endif | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.