mirror of
https://github.com/yasirkula/UnityAssetUsageDetector.git
synced 2026-11-20 23:12:38 +08:00
Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 790a508dcd | |||
| d6a03aa8f2 | |||
| 177db66fbd |
+2
-2
@@ -21,8 +21,8 @@ There are 5 ways to install this plugin:
|
|||||||
- import [AssetUsageDetector.unitypackage](https://github.com/yasirkula/UnityAssetUsageDetector/releases) via *Assets-Import Package*
|
- import [AssetUsageDetector.unitypackage](https://github.com/yasirkula/UnityAssetUsageDetector/releases) via *Assets-Import Package*
|
||||||
- clone/[download](https://github.com/yasirkula/UnityAssetUsageDetector/archive/master.zip) this repository and move the *Plugins* folder to your Unity project's *Assets* folder
|
- clone/[download](https://github.com/yasirkula/UnityAssetUsageDetector/archive/master.zip) this repository and move the *Plugins* folder to your Unity project's *Assets* folder
|
||||||
- import it from [Asset Store](https://assetstore.unity.com/packages/tools/utilities/asset-usage-detector-112837)
|
- import it from [Asset Store](https://assetstore.unity.com/packages/tools/utilities/asset-usage-detector-112837)
|
||||||
- *(via Package Manager)* add the following line to *Packages/manifest.json*:
|
- *(via Package Manager)* click the + button and install the package from the following git URL:
|
||||||
- `"com.yasirkula.assetusagedetector": "https://github.com/yasirkula/UnityAssetUsageDetector.git",`
|
- `https://github.com/yasirkula/UnityAssetUsageDetector.git`
|
||||||
- *(via [OpenUPM](https://openupm.com))* after installing [openupm-cli](https://github.com/openupm/openupm-cli), run the following command:
|
- *(via [OpenUPM](https://openupm.com))* after installing [openupm-cli](https://github.com/openupm/openupm-cli), run the following command:
|
||||||
- `openupm add com.yasirkula.assetusagedetector`
|
- `openupm add com.yasirkula.assetusagedetector`
|
||||||
|
|
||||||
|
|||||||
@@ -26,11 +26,20 @@ namespace AssetUsageDetectorNamespace
|
|||||||
|
|
||||||
public static void Show( Rect sourcePosition, string tooltip )
|
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 );
|
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 preferredPosition;
|
||||||
|
|
||||||
Rect positionLeft = new Rect( sourcePosition.position - new Vector2( preferredSize.x, 0f ), preferredSize );
|
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 positionOffset = positionLeft.position - screenFittedPositionLeft.position;
|
||||||
Vector2 sizeOffset = positionLeft.size - screenFittedPositionLeft.size;
|
Vector2 sizeOffset = positionLeft.size - screenFittedPositionLeft.size;
|
||||||
@@ -39,7 +48,7 @@ namespace AssetUsageDetectorNamespace
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
Rect positionRight = new Rect( sourcePosition.position + new Vector2( sourcePosition.width, 0f ), preferredSize );
|
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 positionOffset2 = positionRight.position - screenFittedPositionRight.position;
|
||||||
Vector2 sizeOffset2 = positionRight.size - screenFittedPositionRight.size;
|
Vector2 sizeOffset2 = positionRight.size - screenFittedPositionRight.size;
|
||||||
@@ -49,15 +58,6 @@ namespace AssetUsageDetectorNamespace
|
|||||||
preferredPosition = screenFittedPositionLeft;
|
preferredPosition = screenFittedPositionLeft;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Don't lose focus to the previous window
|
|
||||||
EditorWindow prevFocusedWindow = focusedWindow;
|
|
||||||
|
|
||||||
if( !mainWindow )
|
|
||||||
{
|
|
||||||
mainWindow = CreateInstance<SearchResultTooltip>();
|
|
||||||
mainWindow.ShowPopup();
|
|
||||||
}
|
|
||||||
|
|
||||||
SearchResultTooltip.tooltip = tooltip;
|
SearchResultTooltip.tooltip = tooltip;
|
||||||
mainWindow.minSize = preferredPosition.size;
|
mainWindow.minSize = preferredPosition.size;
|
||||||
mainWindow.position = preferredPosition;
|
mainWindow.position = preferredPosition;
|
||||||
|
|||||||
@@ -1311,7 +1311,7 @@ namespace AssetUsageDetectorNamespace
|
|||||||
if( preferredHeight > 10f )
|
if( preferredHeight > 10f )
|
||||||
{
|
{
|
||||||
Vector2 size = position.size;
|
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;
|
shouldRepositionSelf = false;
|
||||||
GUIUtility.ExitGUI();
|
GUIUtility.ExitGUI();
|
||||||
|
|||||||
@@ -43,7 +43,9 @@ namespace AssetUsageDetectorNamespace
|
|||||||
private static readonly string reflectionNamespace = typeof( Assembly ).Namespace;
|
private static readonly string reflectionNamespace = typeof( Assembly ).Namespace;
|
||||||
private static readonly string nativeCollectionsNamespace = typeof( NativeArray<int> ).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 ) );
|
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 );
|
GUILayout.Space( 4f );
|
||||||
}
|
}
|
||||||
|
|
||||||
// Restricts the given Rect within the screen's bounds
|
/// <summary>
|
||||||
public static Rect GetScreenFittedRect( Rect originalRect )
|
/// Restricts the given Rect within the screen's bounds.
|
||||||
{
|
/// </summary>
|
||||||
if( screenFittedRectGetter == null )
|
public static Rect GetScreenFittedRect(Rect originalRect, EditorWindow editorWindow)
|
||||||
screenFittedRectGetter = typeof( EditorWindow ).Assembly.GetType( "UnityEditor.ContainerWindow" ).GetMethod( "FitRectToScreen", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static );
|
{
|
||||||
|
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
|
// Check if all the objects inside the list are null
|
||||||
public static bool IsEmpty( this List<ObjectToSearch> objectsToSearch )
|
public static bool IsEmpty( this List<ObjectToSearch> objectsToSearch )
|
||||||
|
|||||||
@@ -9,14 +9,14 @@ namespace AssetUsageDetectorNamespace
|
|||||||
public delegate object VariableGetVal( object obj );
|
public delegate object VariableGetVal( object obj );
|
||||||
|
|
||||||
// Custom struct to hold a variable, its important properties and its getter function
|
// Custom struct to hold a variable, its important properties and its getter function
|
||||||
public struct VariableGetterHolder
|
public readonly struct VariableGetterHolder
|
||||||
{
|
{
|
||||||
public readonly MemberInfo variable;
|
public readonly MemberInfo variable;
|
||||||
public readonly bool isSerializable;
|
public readonly bool isSerializable;
|
||||||
private readonly VariableGetVal getter;
|
private readonly VariableGetVal getter;
|
||||||
|
|
||||||
public string Name { get { return variable.Name; } }
|
public readonly string Name { get { return variable.Name; } }
|
||||||
public bool IsProperty { get { return variable is PropertyInfo; } }
|
public readonly bool IsProperty { get { return variable is PropertyInfo; } }
|
||||||
|
|
||||||
public VariableGetterHolder( FieldInfo fieldInfo, VariableGetVal getter, bool isSerializable )
|
public VariableGetterHolder( FieldInfo fieldInfo, VariableGetVal getter, bool isSerializable )
|
||||||
{
|
{
|
||||||
@@ -32,7 +32,7 @@ namespace AssetUsageDetectorNamespace
|
|||||||
this.getter = getter;
|
this.getter = getter;
|
||||||
}
|
}
|
||||||
|
|
||||||
public object Get( object obj )
|
public readonly object Get( object obj )
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
= Asset Usage Detector (v2.5.6) =
|
= Asset Usage Detector (v2.5.7) =
|
||||||
|
|
||||||
Documentation: https://github.com/yasirkula/UnityAssetUsageDetector
|
Documentation: https://github.com/yasirkula/UnityAssetUsageDetector
|
||||||
E-mail: yasirkula@gmail.com
|
E-mail: yasirkula@gmail.com
|
||||||
+1
-1
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "com.yasirkula.assetusagedetector",
|
"name": "com.yasirkula.assetusagedetector",
|
||||||
"displayName": "Asset Usage Detector",
|
"displayName": "Asset Usage Detector",
|
||||||
"version": "2.5.6",
|
"version": "2.5.7",
|
||||||
"documentationUrl": "https://github.com/yasirkula/UnityAssetUsageDetector",
|
"documentationUrl": "https://github.com/yasirkula/UnityAssetUsageDetector",
|
||||||
"changelogUrl": "https://github.com/yasirkula/UnityAssetUsageDetector/releases",
|
"changelogUrl": "https://github.com/yasirkula/UnityAssetUsageDetector/releases",
|
||||||
"licensesUrl": "https://github.com/yasirkula/UnityAssetUsageDetector/blob/master/LICENSE.txt",
|
"licensesUrl": "https://github.com/yasirkula/UnityAssetUsageDetector/blob/master/LICENSE.txt",
|
||||||
|
|||||||
Reference in New Issue
Block a user