-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix support for Unity 2022.1 or earlier
- Loading branch information
1 parent
db1758c
commit 759b262
Showing
23 changed files
with
651 additions
and
21 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
// Copyright (c) 2023 Koji Hasegawa. | ||
// This software is released under the MIT License. | ||
|
||
using System.Runtime.CompilerServices; | ||
|
||
[assembly: InternalsVisibleTo("TestHelper.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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
106 changes: 106 additions & 0 deletions
106
Runtime/Wrappers/UnityEditor/GameViewSizeGroupWrapper.cs
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. | ||
|
||
#if UNITY_EDITOR | ||
using System; | ||
using System.Reflection; | ||
using UnityEngine; | ||
|
||
namespace TestHelper.Wrappers.UnityEditor | ||
{ | ||
/// <summary> | ||
/// Wrapper for <c>UnityEditor.GameViewSizeGroup</c>. | ||
/// </summary> | ||
public class GameViewSizeGroupWrapper | ||
{ | ||
private static readonly Assembly s_editorAssembly = Assembly.Load("UnityEditor.dll"); | ||
private static readonly Type s_gameViewSizeGroup = s_editorAssembly.GetType("UnityEditor.GameViewSizeGroup"); | ||
private static readonly MethodInfo s_getTotalCount = s_gameViewSizeGroup.GetMethod("GetTotalCount"); | ||
private static readonly MethodInfo s_getGameViewSize = s_gameViewSizeGroup.GetMethod("GetGameViewSize"); | ||
private static readonly MethodInfo s_addCustomSize = s_gameViewSizeGroup.GetMethod("AddCustomSize"); | ||
private static readonly MethodInfo s_removeCustomSize = s_gameViewSizeGroup.GetMethod("RemoveCustomSize"); | ||
|
||
private readonly object _instance; | ||
|
||
private GameViewSizeGroupWrapper(object gameViewSizeGroup) | ||
{ | ||
_instance = gameViewSizeGroup; | ||
} | ||
|
||
public static GameViewSizeGroupWrapper CreateInstance(object gameViewSizeGroup) | ||
{ | ||
if (s_gameViewSizeGroup == null) | ||
{ | ||
Debug.LogError("GameViewSizeGroup type not found."); | ||
return null; | ||
// Note: Do not use Exception (and Assert). Because freezes async tests on UTF v1.3.4, See UUM-25085. | ||
} | ||
|
||
if (s_getTotalCount == null) | ||
{ | ||
Debug.LogError("GetTotalCount method not found."); | ||
return null; | ||
} | ||
|
||
if (s_getGameViewSize == null) | ||
{ | ||
Debug.LogError("GetGameViewSize method not found."); | ||
return null; | ||
} | ||
|
||
if (s_addCustomSize == null) | ||
{ | ||
Debug.LogError("AddCustomSize method not found."); | ||
return null; | ||
} | ||
|
||
if (s_removeCustomSize == null) | ||
{ | ||
Debug.LogError("RemoveCustomSize method not found."); | ||
return null; | ||
} | ||
|
||
return new GameViewSizeGroupWrapper(gameViewSizeGroup); | ||
} | ||
|
||
public int GetTotalCount() | ||
{ | ||
var res = s_getTotalCount.Invoke(_instance, null); | ||
return (int)res; | ||
} | ||
|
||
public GameViewSizeWrapper GetGameViewSize(int index) | ||
{ | ||
var res = s_getGameViewSize.Invoke(_instance, new object[] { index }); | ||
return new GameViewSizeWrapper(res); | ||
} | ||
|
||
public void AddCustomSize(GameViewSizeWrapper size) | ||
{ | ||
s_addCustomSize.Invoke(_instance, new object[] { size.GetInnerInstance() }); | ||
} | ||
|
||
public void RemoveCustomSize(int index) | ||
{ | ||
s_removeCustomSize.Invoke(_instance, new object[] { index }); | ||
} | ||
|
||
/// <summary> | ||
/// Found same type, width, and height. | ||
/// </summary> | ||
public int IndexOf(GameViewSizeWrapper size) | ||
{ | ||
for (var i = 0; i < GetTotalCount(); i++) | ||
{ | ||
var gameViewSize = GetGameViewSize(i); | ||
if (gameViewSize.Equals(size)) | ||
{ | ||
return i; | ||
} | ||
} | ||
|
||
return -1; | ||
} | ||
} | ||
} | ||
#endif |
3 changes: 3 additions & 0 deletions
3
Runtime/Wrappers/UnityEditor/GameViewSizeGroupWrapper.cs.meta
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,141 @@ | ||
// Copyright (c) 2023 Koji Hasegawa. | ||
// This software is released under the MIT License. | ||
|
||
#if UNITY_EDITOR | ||
using System; | ||
using System.Reflection; | ||
using UnityEngine; | ||
|
||
namespace TestHelper.Wrappers.UnityEditor | ||
{ | ||
/// <summary> | ||
/// Wrapper for <c>UnityEditor.GameViewSize</c>. | ||
/// </summary> | ||
public class GameViewSizeWrapper | ||
{ | ||
private static readonly Assembly s_editorAssembly = Assembly.Load("UnityEditor.dll"); | ||
|
||
private static readonly Type s_gameViewSize = s_editorAssembly.GetType("UnityEditor.GameViewSize"); | ||
|
||
private static readonly FieldInfo s_gameViewSizeGameViewSizeType = | ||
s_gameViewSize.GetField("m_SizeType", BindingFlags.NonPublic | BindingFlags.Instance); | ||
|
||
private static readonly FieldInfo s_gameViewSizeWidth = | ||
s_gameViewSize.GetField("m_Width", BindingFlags.NonPublic | BindingFlags.Instance); | ||
|
||
private static readonly FieldInfo s_gameViewSizeHeight = | ||
s_gameViewSize.GetField("m_Height", BindingFlags.NonPublic | BindingFlags.Instance); | ||
|
||
private static readonly Type s_gameViewSizeType = s_editorAssembly.GetType("UnityEditor.GameViewSizeType"); | ||
private static readonly object s_typeFixedResolution = Enum.Parse(s_gameViewSizeType, "FixedResolution"); | ||
|
||
private static readonly ConstructorInfo s_gameViewSizeConstructor = s_gameViewSize.GetConstructor(new[] | ||
{ | ||
s_gameViewSizeType, typeof(int), typeof(int), typeof(string) | ||
}); | ||
|
||
private readonly object _instance; | ||
private readonly int _width; | ||
private readonly int _height; | ||
|
||
internal GameViewSizeWrapper(object instance) | ||
{ | ||
_instance = instance; | ||
if (_instance == null) | ||
{ | ||
return; | ||
} | ||
|
||
_width = (int)s_gameViewSizeWidth.GetValue(_instance); | ||
_height = (int)s_gameViewSizeHeight.GetValue(_instance); | ||
} | ||
|
||
internal object GetInnerInstance() | ||
{ | ||
return _instance; | ||
} | ||
|
||
public static GameViewSizeWrapper CreateInstance(int width, int height, string baseText) | ||
{ | ||
if (s_gameViewSize == null) | ||
{ | ||
Debug.LogError("GameViewSize type not found."); | ||
return null; | ||
// Note: Do not use Exception (and Assert). Because freezes async tests on UTF v1.3.4, See UUM-25085. | ||
} | ||
|
||
if (s_gameViewSizeGameViewSizeType == null) | ||
{ | ||
Debug.LogError("GameViewSize.m_SizeType field not found."); | ||
return null; | ||
} | ||
|
||
if (s_gameViewSizeWidth == null) | ||
{ | ||
Debug.LogError("GameViewSize.m_Width field not found."); | ||
return null; | ||
} | ||
|
||
if (s_gameViewSizeHeight == null) | ||
{ | ||
Debug.LogError("GameViewSize.m_Height field not found."); | ||
return null; | ||
} | ||
|
||
if (s_typeFixedResolution == null) | ||
{ | ||
Debug.LogError("GameViewSizeType.FixedResolution not found."); | ||
return null; | ||
} | ||
|
||
if (s_gameViewSizeConstructor == null) | ||
{ | ||
Debug.LogError("GameViewSize constructor not found."); | ||
return null; | ||
} | ||
|
||
var instance = s_gameViewSizeConstructor.Invoke(new[] { s_typeFixedResolution, width, height, baseText }); | ||
if (instance == null) | ||
{ | ||
Debug.LogError("GameViewSize instance creation failed."); | ||
return null; | ||
} | ||
|
||
return new GameViewSizeWrapper(instance); | ||
} | ||
|
||
public string DisplayText() | ||
{ | ||
var displayTextProperty = s_gameViewSize.GetProperty("displayText"); | ||
if (displayTextProperty == null) | ||
{ | ||
throw new NullReferenceException("GameViewSize.displayText property not found."); | ||
} | ||
|
||
var displayText = displayTextProperty.GetValue(_instance); | ||
return displayText as string; | ||
} | ||
|
||
/// <summary> | ||
/// Same type, width, and height. | ||
/// </summary> | ||
public bool Equals(GameViewSizeWrapper other) | ||
{ | ||
if (other?.GetInnerInstance() == null) | ||
{ | ||
return false; | ||
} | ||
|
||
var otherType = s_gameViewSizeGameViewSizeType.GetValue(other.GetInnerInstance()); | ||
if (!otherType.Equals(s_typeFixedResolution)) | ||
{ | ||
return false; | ||
} | ||
|
||
var otherWidth = (int)s_gameViewSizeWidth.GetValue(other.GetInnerInstance()); | ||
var otherHeight = (int)s_gameViewSizeHeight.GetValue(other.GetInnerInstance()); | ||
return otherWidth == _width && otherHeight == _height; | ||
} | ||
} | ||
} | ||
#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.