mirror of
https://github.com/yasirkula/UnityAssetUsageDetector.git
synced 2026-11-19 14:32:37 +08:00
Fixed GetScreenFittedRect not working on Unity 2022.3.62+, 6.0.49+ and 6.1.0+
This commit is contained in:
@@ -26,11 +26,20 @@ namespace AssetUsageDetectorNamespace
|
||||
|
||||
public static void Show( Rect sourcePosition, string tooltip )
|
||||
{
|
||||
// Don't lose focus to the previous window
|
||||
EditorWindow prevFocusedWindow = focusedWindow;
|
||||
|
||||
if (!mainWindow)
|
||||
{
|
||||
mainWindow = CreateInstance<SearchResultTooltip>();
|
||||
mainWindow.ShowPopup();
|
||||
}
|
||||
|
||||
Vector2 preferredSize = Style.CalcSize( new GUIContent( tooltip ) ) + Style.contentOffset + new Vector2( Style.padding.horizontal + Style.margin.horizontal, Style.padding.vertical + Style.margin.vertical );
|
||||
Rect preferredPosition;
|
||||
|
||||
Rect positionLeft = new Rect( sourcePosition.position - new Vector2( preferredSize.x, 0f ), preferredSize );
|
||||
Rect screenFittedPositionLeft = Utilities.GetScreenFittedRect( positionLeft );
|
||||
Rect screenFittedPositionLeft = Utilities.GetScreenFittedRect(positionLeft, mainWindow);
|
||||
|
||||
Vector2 positionOffset = positionLeft.position - screenFittedPositionLeft.position;
|
||||
Vector2 sizeOffset = positionLeft.size - screenFittedPositionLeft.size;
|
||||
@@ -39,7 +48,7 @@ namespace AssetUsageDetectorNamespace
|
||||
else
|
||||
{
|
||||
Rect positionRight = new Rect( sourcePosition.position + new Vector2( sourcePosition.width, 0f ), preferredSize );
|
||||
Rect screenFittedPositionRight = Utilities.GetScreenFittedRect( positionRight );
|
||||
Rect screenFittedPositionRight = Utilities.GetScreenFittedRect(positionRight, mainWindow);
|
||||
|
||||
Vector2 positionOffset2 = positionRight.position - screenFittedPositionRight.position;
|
||||
Vector2 sizeOffset2 = positionRight.size - screenFittedPositionRight.size;
|
||||
@@ -49,15 +58,6 @@ namespace AssetUsageDetectorNamespace
|
||||
preferredPosition = screenFittedPositionLeft;
|
||||
}
|
||||
|
||||
// Don't lose focus to the previous window
|
||||
EditorWindow prevFocusedWindow = focusedWindow;
|
||||
|
||||
if( !mainWindow )
|
||||
{
|
||||
mainWindow = CreateInstance<SearchResultTooltip>();
|
||||
mainWindow.ShowPopup();
|
||||
}
|
||||
|
||||
SearchResultTooltip.tooltip = tooltip;
|
||||
mainWindow.minSize = preferredPosition.size;
|
||||
mainWindow.position = preferredPosition;
|
||||
|
||||
@@ -1311,7 +1311,7 @@ namespace AssetUsageDetectorNamespace
|
||||
if( preferredHeight > 10f )
|
||||
{
|
||||
Vector2 size = position.size;
|
||||
position = Utilities.GetScreenFittedRect( new Rect( GUIUtility.GUIToScreenPoint( Event.current.mousePosition ) + new Vector2( size.x * -0.5f, 10f ), size ) );
|
||||
position = Utilities.GetScreenFittedRect(new Rect(GUIUtility.GUIToScreenPoint(Event.current.mousePosition) + new Vector2(size.x * -0.5f, 10f), size), this);
|
||||
|
||||
shouldRepositionSelf = false;
|
||||
GUIUtility.ExitGUI();
|
||||
|
||||
@@ -43,7 +43,9 @@ namespace AssetUsageDetectorNamespace
|
||||
private static readonly string reflectionNamespace = typeof( Assembly ).Namespace;
|
||||
private static readonly string nativeCollectionsNamespace = typeof( NativeArray<int> ).Namespace;
|
||||
|
||||
private static MethodInfo screenFittedRectGetter;
|
||||
private static MethodInfo screenFittedRectGetter;
|
||||
private static FieldInfo editorWindowHostViewGetter;
|
||||
private static PropertyInfo hostViewContainerWindowGetter;
|
||||
|
||||
private static readonly Func<Object, bool, bool> prefabHasAnyOverridesGetter = (Func<Object, bool, bool>) Delegate.CreateDelegate( typeof( Func<Object, bool, bool> ), typeof( PrefabUtility ).GetMethod( "HasObjectOverride", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static ) );
|
||||
|
||||
@@ -494,14 +496,25 @@ namespace AssetUsageDetectorNamespace
|
||||
GUILayout.Space( 4f );
|
||||
}
|
||||
|
||||
// Restricts the given Rect within the screen's bounds
|
||||
public static Rect GetScreenFittedRect( Rect originalRect )
|
||||
{
|
||||
if( screenFittedRectGetter == null )
|
||||
screenFittedRectGetter = typeof( EditorWindow ).Assembly.GetType( "UnityEditor.ContainerWindow" ).GetMethod( "FitRectToScreen", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static );
|
||||
/// <summary>
|
||||
/// Restricts the given Rect within the screen's bounds.
|
||||
/// </summary>
|
||||
public static Rect GetScreenFittedRect(Rect originalRect, EditorWindow editorWindow)
|
||||
{
|
||||
screenFittedRectGetter ??= typeof(EditorWindow).Assembly.GetType("UnityEditor.ContainerWindow").GetMethod("FitRectToScreen", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
|
||||
|
||||
return (Rect) screenFittedRectGetter.Invoke( null, new object[3] { originalRect, true, true } );
|
||||
}
|
||||
if (screenFittedRectGetter.GetParameters().Length == 3)
|
||||
return (Rect)screenFittedRectGetter.Invoke(null, new object[] { originalRect, true, true });
|
||||
else
|
||||
{
|
||||
// New version introduced in Unity 2022.3.62f1, Unity 6.0.49f1 and Unity 6.1.0f1.
|
||||
// Usage example: https://github.com/Unity-Technologies/UnityCsReference/blob/10f8718268a7e34844ba7d59792117c28d75a99b/Editor/Mono/EditorWindow.cs#L1264
|
||||
editorWindowHostViewGetter ??= typeof(EditorWindow).GetField("m_Parent", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);
|
||||
hostViewContainerWindowGetter ??= typeof(EditorWindow).Assembly.GetType("UnityEditor.HostView").GetProperty("window", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);
|
||||
|
||||
return (Rect)screenFittedRectGetter.Invoke(null, new object[] { originalRect, originalRect.center, true, hostViewContainerWindowGetter.GetValue(editorWindowHostViewGetter.GetValue(editorWindow), null) });
|
||||
}
|
||||
}
|
||||
|
||||
// Check if all the objects inside the list are null
|
||||
public static bool IsEmpty( this List<ObjectToSearch> objectsToSearch )
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
= Asset Usage Detector (v2.5.6) =
|
||||
= Asset Usage Detector (v2.5.7) =
|
||||
|
||||
Documentation: https://github.com/yasirkula/UnityAssetUsageDetector
|
||||
E-mail: yasirkula@gmail.com
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "com.yasirkula.assetusagedetector",
|
||||
"displayName": "Asset Usage Detector",
|
||||
"version": "2.5.6",
|
||||
"version": "2.5.7",
|
||||
"documentationUrl": "https://github.com/yasirkula/UnityAssetUsageDetector",
|
||||
"changelogUrl": "https://github.com/yasirkula/UnityAssetUsageDetector/releases",
|
||||
"licensesUrl": "https://github.com/yasirkula/UnityAssetUsageDetector/blob/master/LICENSE.txt",
|
||||
|
||||
Reference in New Issue
Block a user