mirror of
https://github.com/yasirkula/UnityAssetUsageDetector.git
synced 2026-11-19 22:42:37 +08:00
Compare commits
49 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| b7b6f8815e | |||
| 40a28f5961 | |||
| b535e09ba2 | |||
| 499e4bc43e | |||
| 93c955993a | |||
| 21f8daffde | |||
| 8cc7798f17 | |||
| 45b0f6f1d9 | |||
| c599ea6273 | |||
| 7ba33e2d4e | |||
| ac294324dd | |||
| 8dc7d5508b | |||
| c9131811e2 | |||
| 133b8b1227 | |||
| 1db9dbf9b0 | |||
| a6b0f5ae92 | |||
| 8e7369e44e | |||
| 7b60eeacf7 | |||
| b8470536b9 | |||
| 1bebc8691d | |||
| 5a81e5011b | |||
| ba7539d983 | |||
| f4129574fb | |||
| 7738da9d19 | |||
| 077505a217 | |||
| 003cedd363 | |||
| 68f1b2809e | |||
| 6280305a63 | |||
| 5d04e70b7b | |||
| 541e33db89 | |||
| bc3a8069b4 | |||
| 98d1f43180 | |||
| 7d24aa4939 | |||
| c16bef45cd | |||
| 7b939a2104 | |||
| ccf3e2f733 | |||
| c6b1edfd93 | |||
| 7358b12609 | |||
| ab539adc54 | |||
| 4909b9c558 | |||
| 94381ff7d2 | |||
| 17d3b33e8e | |||
| ff193224e9 | |||
| 51abec24d7 | |||
| a29dc59a75 | |||
| 96315ec435 | |||
| 12ed06d43c | |||
| 69ce197932 | |||
| e3dc45b917 |
@@ -0,0 +1,48 @@
|
||||
# Asset Usage Detector for Unity 3D
|
||||
|
||||

|
||||
|
||||
**Available on Asset Store:** https://assetstore.unity.com/packages/tools/utilities/asset-usage-detector-112837
|
||||
|
||||
**Forum Thread:** https://forum.unity.com/threads/asset-usage-detector-find-references-to-an-asset-object-open-source.408134/
|
||||
|
||||
**Discord:** https://discord.gg/UJJt549AaV
|
||||
|
||||
**[Support the Developer ☕](https://yasirkula.itch.io/unity3d)**
|
||||
|
||||
## ABOUT
|
||||
|
||||
This editor extension helps you figure out at which places an asset or GameObject is used, i.e. lists the objects that refer to the asset. It is possible to search for references in the Assets folder (Project view) and/or in the scene(s) of your project. You can also search for references while in Play mode!
|
||||
|
||||
## INSTALLATION
|
||||
|
||||
There are 5 ways to install this plugin:
|
||||
|
||||
- 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
|
||||
- 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*:
|
||||
- `"com.yasirkula.assetusagedetector": "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:
|
||||
- `openupm add com.yasirkula.assetusagedetector`
|
||||
|
||||
## HOW TO
|
||||
|
||||
- Open **Window - Asset Usage Detector** window, configure the settings and hit **GO!**
|
||||
- or, right click an object and select **Search For References**
|
||||
- In the search results page, each row represents a reference to the searched Object(s). Rows can be traversed from left to right to see how the references are formed. If a node's label contains text inside square brackets (e.g. *\[Child object\]*), then that text describes how that node is connected to the node to its left
|
||||
|
||||
## FEATURES
|
||||
|
||||
- You can search for references of any object that extends *UnityEngine.Object*
|
||||
- Extensive search algorithm that uses *SerializedObject* and *reflection* to find references
|
||||
- Can search in multiple scenes at once
|
||||
- Can show complete paths to the references or only the most relevant parts of the paths (see the demonstration below)
|
||||
|
||||

|
||||
|
||||
## KNOWN LIMITATIONS
|
||||
|
||||
- *static* variables aren't searched
|
||||
- GUIText materials aren't searched
|
||||
- Textures in Lens Flares can't be searched
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 40 KiB |
|
Before Width: | Height: | Size: 103 KiB After Width: | Height: | Size: 103 KiB |
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 56436d3bf8363484a9696f11a535c2fb
|
||||
TextScriptImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d2008cf328f1a2e4da790e4bdd4191cd
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,15 @@
|
||||
{
|
||||
"name": "AssetUsageDetector.Editor",
|
||||
"references": [],
|
||||
"includePlatforms": [
|
||||
"Editor"
|
||||
],
|
||||
"excludePlatforms": [],
|
||||
"allowUnsafeCode": false,
|
||||
"overrideReferences": false,
|
||||
"precompiledReferences": [],
|
||||
"autoReferenced": true,
|
||||
"defineConstraints": [],
|
||||
"versionDefines": [],
|
||||
"noEngineReferences": false
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8579ab42c9ab63d4bac5fb07bd390b46
|
||||
AssemblyDefinitionImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,207 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using Object = UnityEngine.Object;
|
||||
|
||||
namespace AssetUsageDetectorNamespace
|
||||
{
|
||||
public partial class AssetUsageDetector
|
||||
{
|
||||
#region Helper Classes
|
||||
private class CacheEntry
|
||||
{
|
||||
public enum Result { Unknown = 0, No = 1, Yes = 2 };
|
||||
|
||||
public string hash;
|
||||
public string[] dependencies;
|
||||
public long[] fileSizes;
|
||||
|
||||
public bool verified;
|
||||
public Result searchResult;
|
||||
|
||||
public CacheEntry( string path )
|
||||
{
|
||||
Verify( path );
|
||||
}
|
||||
|
||||
public CacheEntry( string hash, string[] dependencies, long[] fileSizes )
|
||||
{
|
||||
this.hash = hash;
|
||||
this.dependencies = dependencies;
|
||||
this.fileSizes = fileSizes;
|
||||
}
|
||||
|
||||
public void Verify( string path )
|
||||
{
|
||||
string hash = AssetDatabase.GetAssetDependencyHash( path ).ToString();
|
||||
if( this.hash != hash )
|
||||
{
|
||||
this.hash = hash;
|
||||
Refresh( path );
|
||||
}
|
||||
|
||||
verified = true;
|
||||
}
|
||||
|
||||
public void Refresh( string path )
|
||||
{
|
||||
dependencies = AssetDatabase.GetDependencies( path, false );
|
||||
if( fileSizes == null || fileSizes.Length != dependencies.Length )
|
||||
fileSizes = new long[dependencies.Length];
|
||||
|
||||
int length = dependencies.Length;
|
||||
for( int i = 0; i < length; i++ )
|
||||
{
|
||||
if( !string.IsNullOrEmpty( dependencies[i] ) )
|
||||
{
|
||||
FileInfo assetFile = new FileInfo( dependencies[i] );
|
||||
fileSizes[i] = assetFile.Exists ? assetFile.Length : 0L;
|
||||
}
|
||||
else
|
||||
{
|
||||
// This dependency is empty which causes issues when passed to FileInfo constructor
|
||||
// Find a non-empty dependency and move it to this index
|
||||
for( int j = length - 1; j > i; j--, length-- )
|
||||
{
|
||||
if( !string.IsNullOrEmpty( dependencies[j] ) )
|
||||
{
|
||||
dependencies[i--] = dependencies[j];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
length--;
|
||||
}
|
||||
}
|
||||
|
||||
if( length != fileSizes.Length )
|
||||
{
|
||||
Array.Resize( ref dependencies, length );
|
||||
Array.Resize( ref fileSizes, length );
|
||||
}
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
// An optimization to fetch the dependencies of an asset only once (key is the path of the asset)
|
||||
private Dictionary<string, CacheEntry> assetDependencyCache;
|
||||
private CacheEntry lastRefreshedCacheEntry;
|
||||
|
||||
private string CachePath { get { return Application.dataPath + "/../Library/AssetUsageDetector.cache"; } } // Path of the cache file
|
||||
|
||||
public void SaveCache()
|
||||
{
|
||||
if( assetDependencyCache == null )
|
||||
return;
|
||||
|
||||
try
|
||||
{
|
||||
using( FileStream stream = new FileStream( CachePath, FileMode.Create ) )
|
||||
using( BinaryWriter writer = new BinaryWriter( stream ) )
|
||||
{
|
||||
writer.Write( assetDependencyCache.Count );
|
||||
|
||||
foreach( var keyValuePair in assetDependencyCache )
|
||||
{
|
||||
CacheEntry cacheEntry = keyValuePair.Value;
|
||||
string[] dependencies = cacheEntry.dependencies;
|
||||
long[] fileSizes = cacheEntry.fileSizes;
|
||||
|
||||
writer.Write( keyValuePair.Key );
|
||||
writer.Write( cacheEntry.hash );
|
||||
writer.Write( dependencies.Length );
|
||||
|
||||
for( int i = 0; i < dependencies.Length; i++ )
|
||||
{
|
||||
writer.Write( dependencies[i] );
|
||||
writer.Write( fileSizes[i] );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch( Exception e )
|
||||
{
|
||||
Debug.LogException( e );
|
||||
}
|
||||
}
|
||||
|
||||
private void LoadCache()
|
||||
{
|
||||
if( File.Exists( CachePath ) )
|
||||
{
|
||||
using( FileStream stream = new FileStream( CachePath, FileMode.Open, FileAccess.Read ) )
|
||||
using( BinaryReader reader = new BinaryReader( stream ) )
|
||||
{
|
||||
try
|
||||
{
|
||||
int cacheSize = reader.ReadInt32();
|
||||
assetDependencyCache = new Dictionary<string, CacheEntry>( cacheSize );
|
||||
|
||||
for( int i = 0; i < cacheSize; i++ )
|
||||
{
|
||||
string assetPath = reader.ReadString();
|
||||
string hash = reader.ReadString();
|
||||
|
||||
int dependenciesLength = reader.ReadInt32();
|
||||
string[] dependencies = new string[dependenciesLength];
|
||||
long[] fileSizes = new long[dependenciesLength];
|
||||
for( int j = 0; j < dependenciesLength; j++ )
|
||||
{
|
||||
dependencies[j] = reader.ReadString();
|
||||
fileSizes[j] = reader.ReadInt64();
|
||||
}
|
||||
|
||||
assetDependencyCache[assetPath] = new CacheEntry( hash, dependencies, fileSizes );
|
||||
}
|
||||
}
|
||||
catch( Exception e )
|
||||
{
|
||||
assetDependencyCache = null;
|
||||
Debug.LogWarning( "Couldn't load cache (probably cache format has changed in an update), will regenerate cache.\n" + e.ToString() );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Generate cache for all assets for the first time
|
||||
if( assetDependencyCache == null )
|
||||
{
|
||||
assetDependencyCache = new Dictionary<string, CacheEntry>( 1024 * 8 );
|
||||
|
||||
string[] allAssets = AssetDatabase.GetAllAssetPaths();
|
||||
if( allAssets.Length > 0 )
|
||||
{
|
||||
double startTime = EditorApplication.timeSinceStartup;
|
||||
|
||||
try
|
||||
{
|
||||
for( int i = 0; i < allAssets.Length; i++ )
|
||||
{
|
||||
if( i % 30 == 0 && EditorUtility.DisplayCancelableProgressBar( "Please wait...", "Generating cache for the first time (optional)", (float) i / allAssets.Length ) )
|
||||
{
|
||||
EditorUtility.ClearProgressBar();
|
||||
Debug.LogWarning( "Initial cache generation cancelled, cache will be generated on the fly as more and more assets are searched." );
|
||||
break;
|
||||
}
|
||||
|
||||
assetDependencyCache[allAssets[i]] = new CacheEntry( allAssets[i] );
|
||||
}
|
||||
|
||||
EditorUtility.ClearProgressBar();
|
||||
|
||||
Debug.Log( "Cache generated in " + ( EditorApplication.timeSinceStartup - startTime ).ToString( "F2" ) + " seconds" );
|
||||
Debug.Log( "You can always reset the cache by deleting " + Path.GetFullPath( CachePath ) );
|
||||
|
||||
SaveCache();
|
||||
}
|
||||
catch( Exception e )
|
||||
{
|
||||
EditorUtility.ClearProgressBar();
|
||||
Debug.LogException( e );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 71ea9a3fd0b82594d8130d882dbfc844
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 93aaae685d4c3db44baeb91a0296855e
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -5,8 +5,12 @@ using UnityEditor;
|
||||
using System.Collections.Generic;
|
||||
using System.Reflection;
|
||||
using Object = UnityEngine.Object;
|
||||
#if UNITY_2018_3_OR_NEWER
|
||||
using PrefabStage = UnityEditor.Experimental.SceneManagement.PrefabStage;
|
||||
using PrefabStageUtility = UnityEditor.Experimental.SceneManagement.PrefabStageUtility;
|
||||
#endif
|
||||
|
||||
namespace AssetUsageDetectorNamespace.Extras
|
||||
namespace AssetUsageDetectorNamespace
|
||||
{
|
||||
public enum Phase { Setup, Processing, Complete };
|
||||
|
||||
@@ -16,15 +20,20 @@ namespace AssetUsageDetectorNamespace.Extras
|
||||
|
||||
private const string PREFS_SEARCH_SCENES = "AUD_SceneSearch";
|
||||
private const string PREFS_SEARCH_ASSETS = "AUD_AssetsSearch";
|
||||
private const string PREFS_SEARCH_PROJECT_SETTINGS = "AUD_ProjectSettingsSearch";
|
||||
private const string PREFS_DONT_SEARCH_SOURCE_ASSETS = "AUD_AssetsExcludeSrc";
|
||||
private const string PREFS_SEARCH_DEPTH_LIMIT = "AUD_Depth";
|
||||
private const string PREFS_SEARCH_FIELDS = "AUD_Fields";
|
||||
private const string PREFS_SEARCH_PROPERTIES = "AUD_Properties";
|
||||
private const string PREFS_SEARCH_NON_SERIALIZABLES = "AUD_NonSerializables";
|
||||
private const string PREFS_LAZY_SCENE_SEARCH = "AUD_LazySceneSearch";
|
||||
private const string PREFS_PATH_DRAWING_MODE = "AUD_PathDrawing";
|
||||
private const string PREFS_SHOW_PROGRESS = "AUD_Progress";
|
||||
private const string PREFS_SHOW_TOOLTIPS = "AUD_Tooltips";
|
||||
|
||||
private static readonly GUIContent windowTitle = new GUIContent( "Asset Usage Detector" );
|
||||
private static readonly Vector2 windowMinSize = new Vector2( 325f, 220f );
|
||||
|
||||
private AssetUsageDetector core = new AssetUsageDetector();
|
||||
private SearchResult searchResult; // Overall search results
|
||||
|
||||
@@ -36,8 +45,9 @@ namespace AssetUsageDetectorNamespace.Extras
|
||||
private bool searchInScenesInBuild = true; // Scenes in build
|
||||
private bool searchInScenesInBuildTickedOnly = true; // Scenes in build (ticked only or not)
|
||||
private bool searchInAllScenes = true; // All scenes (including scenes that are not in build)
|
||||
private bool searchInAssetsFolder = true; // Assets in Project view
|
||||
private bool dontSearchInSourceAssets = false; // objectsToSearch won't be searched for internal references
|
||||
private bool searchInAssetsFolder = true; // Assets in Project window
|
||||
private bool dontSearchInSourceAssets = true; // objectsToSearch won't be searched for internal references
|
||||
private bool searchInProjectSettings = true; // Player Settings, Graphics Settings etc.
|
||||
|
||||
private List<Object> searchInAssetsSubset = new List<Object>() { null }; // If not empty, only these assets are searched for references
|
||||
private List<Object> excludedAssets = new List<Object>() { null }; // These assets won't be searched for references
|
||||
@@ -45,17 +55,14 @@ namespace AssetUsageDetectorNamespace.Extras
|
||||
|
||||
private int searchDepthLimit = 4; // Depth limit for recursively searching variables of objects
|
||||
|
||||
private bool restoreInitialSceneSetup = true; // Close the additively loaded scenes that were not part of the initial scene setup
|
||||
|
||||
private string errorMessage = string.Empty;
|
||||
|
||||
private bool lazySceneSearch = true;
|
||||
private bool searchNonSerializableVariables = true;
|
||||
private bool noAssetDatabaseChanges = false;
|
||||
private bool showProgressBar = false;
|
||||
private bool showDetailedProgressBar = true;
|
||||
|
||||
private BindingFlags fieldModifiers, propertyModifiers;
|
||||
|
||||
private SearchResultDrawParameters searchResultDrawParameters = new SearchResultDrawParameters( PathDrawingMode.ShortRelevantParts, false );
|
||||
private SearchResultDrawParameters searchResultDrawParameters = new SearchResultDrawParameters( PathDrawingMode.ShortRelevantParts, false, false );
|
||||
|
||||
private double nextPlayModeRefreshTime = 0f;
|
||||
|
||||
@@ -64,44 +71,99 @@ namespace AssetUsageDetectorNamespace.Extras
|
||||
private readonly ObjectListDrawer excludedAssetsDrawer = new ObjectListDrawer( "Don't search following asset(s):", false );
|
||||
private readonly ObjectListDrawer excludedScenesDrawer = new ObjectListDrawer( "Don't search in following scene(s):", false );
|
||||
|
||||
private readonly GUIContent showTooltipsLabel = new GUIContent( "Show tooltips", "Display nodes' contents in a tooltip when cursor hovers over them" );
|
||||
|
||||
private Vector2 scrollPosition = Vector2.zero;
|
||||
|
||||
private static AssetUsageDetectorWindow visibleWindow = null;
|
||||
private bool shouldRepositionSelf;
|
||||
private Rect windowTargetPosition;
|
||||
|
||||
private static AssetUsageDetectorWindow mainWindow = null;
|
||||
|
||||
// Add "Asset Usage Detector" menu item to the Window menu
|
||||
[MenuItem( "Window/Asset Usage Detector" )]
|
||||
private static void Init()
|
||||
[MenuItem( "Window/Asset Usage Detector/Active Window" )]
|
||||
private static void OpenActiveWindow()
|
||||
{
|
||||
AssetUsageDetectorWindow window = GetWindow<AssetUsageDetectorWindow>();
|
||||
window.titleContent = new GUIContent( "Asset Usage Detector" );
|
||||
window.minSize = new Vector2( 325f, 220f );
|
||||
if( !mainWindow )
|
||||
{
|
||||
mainWindow = GetWindow<AssetUsageDetectorWindow>();
|
||||
mainWindow.titleContent = windowTitle;
|
||||
mainWindow.minSize = windowMinSize;
|
||||
}
|
||||
|
||||
window.LoadPrefs();
|
||||
window.Show();
|
||||
mainWindow.Show();
|
||||
}
|
||||
|
||||
[MenuItem( "Window/Asset Usage Detector/New Window" )]
|
||||
private static void OpenNewWindow()
|
||||
{
|
||||
Rect? windowTargetPosition = null;
|
||||
if( mainWindow )
|
||||
{
|
||||
Rect position = mainWindow.position;
|
||||
position.position += new Vector2( 50f, 50f );
|
||||
windowTargetPosition = position;
|
||||
}
|
||||
|
||||
mainWindow = CreateInstance<AssetUsageDetectorWindow>();
|
||||
mainWindow.titleContent = windowTitle;
|
||||
mainWindow.minSize = windowMinSize;
|
||||
|
||||
if( windowTargetPosition.HasValue )
|
||||
{
|
||||
mainWindow.shouldRepositionSelf = true;
|
||||
mainWindow.windowTargetPosition = windowTargetPosition.Value;
|
||||
}
|
||||
|
||||
mainWindow.Show( true );
|
||||
}
|
||||
|
||||
// Quickly initiate search for the selected assets
|
||||
[MenuItem( "GameObject/Search for References/This Object Only", priority = 49 )]
|
||||
[MenuItem( "Assets/Search for References", priority = 1000 )]
|
||||
private static void SearchSelectedAssetReferences()
|
||||
private static void SearchSelectedAssetReferences( MenuCommand command )
|
||||
{
|
||||
ShowAndSearch( Selection.objects );
|
||||
// This happens when this button is clicked via hierarchy's right click context menu
|
||||
// and is called once for each object in the selection. We don't want that, we want
|
||||
// the function to be called only once
|
||||
if( command.context )
|
||||
{
|
||||
EditorApplication.update -= CallSearchSelectedAssetReferencesOnce;
|
||||
EditorApplication.update += CallSearchSelectedAssetReferencesOnce;
|
||||
}
|
||||
else
|
||||
ShowAndSearch( Selection.objects );
|
||||
}
|
||||
|
||||
[MenuItem( "GameObject/Search for References/Include Children", priority = 49 )]
|
||||
private static void SearchSelectedAssetReferencesWithChildren( MenuCommand command )
|
||||
{
|
||||
if( command.context )
|
||||
{
|
||||
EditorApplication.update -= CallSearchSelectedAssetReferencesWithChildrenOnce;
|
||||
EditorApplication.update += CallSearchSelectedAssetReferencesWithChildrenOnce;
|
||||
}
|
||||
else
|
||||
ShowAndSearch( Selection.objects, true );
|
||||
}
|
||||
|
||||
// Show the menu item only if there is a selection in the Editor
|
||||
[MenuItem( "GameObject/Search for References/This Object Only", validate = true )]
|
||||
[MenuItem( "GameObject/Search for References/Include Children", validate = true )]
|
||||
[MenuItem( "Assets/Search for References", validate = true )]
|
||||
private static bool SearchSelectedAssetReferencesValidate()
|
||||
private static bool SearchSelectedAssetReferencesValidate( MenuCommand command )
|
||||
{
|
||||
return Selection.objects.Length > 0;
|
||||
}
|
||||
|
||||
// Quickly show the AssetUsageDetector window and initiate a search
|
||||
public static void ShowAndSearch( IEnumerable<Object> searchObjects )
|
||||
public static void ShowAndSearch( IEnumerable<Object> searchObjects, bool? shouldSearchChildren = null )
|
||||
{
|
||||
ShowAndSearchInternal( searchObjects, null );
|
||||
ShowAndSearchInternal( searchObjects, null, shouldSearchChildren );
|
||||
}
|
||||
|
||||
// Quickly show the AssetUsageDetector window and initiate a search
|
||||
public static void ShowAndSearch( AssetUsageDetector.Parameters searchParameters )
|
||||
public static void ShowAndSearch( AssetUsageDetector.Parameters searchParameters, bool? shouldSearchChildren = null )
|
||||
{
|
||||
if( searchParameters == null )
|
||||
{
|
||||
@@ -109,66 +171,101 @@ namespace AssetUsageDetectorNamespace.Extras
|
||||
return;
|
||||
}
|
||||
|
||||
ShowAndSearchInternal( searchParameters.objectsToSearch, searchParameters );
|
||||
ShowAndSearchInternal( searchParameters.objectsToSearch, searchParameters, shouldSearchChildren );
|
||||
}
|
||||
|
||||
private static void ShowAndSearchInternal( IEnumerable<Object> searchObjects, AssetUsageDetector.Parameters searchParameters )
|
||||
private static void CallSearchSelectedAssetReferencesOnce()
|
||||
{
|
||||
if( visibleWindow != null && !visibleWindow.ReturnToSetupPhase( true ) )
|
||||
EditorApplication.update -= CallSearchSelectedAssetReferencesOnce;
|
||||
SearchSelectedAssetReferences( new MenuCommand( null ) );
|
||||
}
|
||||
|
||||
private static void CallSearchSelectedAssetReferencesWithChildrenOnce()
|
||||
{
|
||||
EditorApplication.update -= CallSearchSelectedAssetReferencesWithChildrenOnce;
|
||||
SearchSelectedAssetReferencesWithChildren( new MenuCommand( null ) );
|
||||
}
|
||||
|
||||
private static void ShowAndSearchInternal( IEnumerable<Object> searchObjects, AssetUsageDetector.Parameters searchParameters, bool? shouldSearchChildren )
|
||||
{
|
||||
if( mainWindow && !mainWindow.ReturnToSetupPhase() )
|
||||
{
|
||||
Debug.LogError( "Need to reset the previous search first!" );
|
||||
return;
|
||||
}
|
||||
|
||||
Init();
|
||||
OpenActiveWindow();
|
||||
|
||||
visibleWindow.objectsToSearch.Clear();
|
||||
mainWindow.objectsToSearch.Clear();
|
||||
if( searchObjects != null )
|
||||
{
|
||||
foreach( Object obj in searchObjects )
|
||||
visibleWindow.objectsToSearch.Add( new ObjectToSearch( obj ) );
|
||||
mainWindow.objectsToSearch.Add( new ObjectToSearch( obj, shouldSearchChildren ) );
|
||||
}
|
||||
|
||||
if( searchParameters != null )
|
||||
{
|
||||
visibleWindow.ParseSceneSearchMode( searchParameters.searchInScenes );
|
||||
visibleWindow.searchInAssetsFolder = searchParameters.searchInAssetsFolder;
|
||||
visibleWindow.dontSearchInSourceAssets = searchParameters.dontSearchInSourceAssets;
|
||||
visibleWindow.searchDepthLimit = searchParameters.searchDepthLimit;
|
||||
visibleWindow.fieldModifiers = searchParameters.fieldModifiers;
|
||||
visibleWindow.propertyModifiers = searchParameters.propertyModifiers;
|
||||
visibleWindow.searchNonSerializableVariables = searchParameters.searchNonSerializableVariables;
|
||||
visibleWindow.noAssetDatabaseChanges = searchParameters.noAssetDatabaseChanges;
|
||||
visibleWindow.showProgressBar = searchParameters.showProgressBar;
|
||||
mainWindow.ParseSceneSearchMode( searchParameters.searchInScenes );
|
||||
mainWindow.searchInAssetsFolder = searchParameters.searchInAssetsFolder;
|
||||
mainWindow.dontSearchInSourceAssets = searchParameters.dontSearchInSourceAssets;
|
||||
mainWindow.searchInProjectSettings = searchParameters.searchInProjectSettings;
|
||||
mainWindow.searchDepthLimit = searchParameters.searchDepthLimit;
|
||||
mainWindow.fieldModifiers = searchParameters.fieldModifiers;
|
||||
mainWindow.propertyModifiers = searchParameters.propertyModifiers;
|
||||
mainWindow.searchNonSerializableVariables = searchParameters.searchNonSerializableVariables;
|
||||
mainWindow.lazySceneSearch = searchParameters.lazySceneSearch;
|
||||
mainWindow.noAssetDatabaseChanges = searchParameters.noAssetDatabaseChanges;
|
||||
mainWindow.showDetailedProgressBar = searchParameters.showDetailedProgressBar;
|
||||
|
||||
visibleWindow.searchInAssetsSubset.Clear();
|
||||
mainWindow.searchInAssetsSubset.Clear();
|
||||
if( searchParameters.searchInAssetsSubset != null )
|
||||
{
|
||||
foreach( Object obj in searchParameters.searchInAssetsSubset )
|
||||
visibleWindow.searchInAssetsSubset.Add( obj );
|
||||
mainWindow.searchInAssetsSubset.Add( obj );
|
||||
}
|
||||
|
||||
visibleWindow.excludedAssets.Clear();
|
||||
mainWindow.excludedAssets.Clear();
|
||||
if( searchParameters.excludedAssetsFromSearch != null )
|
||||
{
|
||||
foreach( Object obj in searchParameters.excludedAssetsFromSearch )
|
||||
visibleWindow.excludedAssets.Add( obj );
|
||||
mainWindow.excludedAssets.Add( obj );
|
||||
}
|
||||
|
||||
visibleWindow.excludedScenes.Clear();
|
||||
mainWindow.excludedScenes.Clear();
|
||||
if( searchParameters.excludedScenesFromSearch != null )
|
||||
{
|
||||
foreach( Object obj in searchParameters.excludedScenesFromSearch )
|
||||
visibleWindow.excludedScenes.Add( obj );
|
||||
mainWindow.excludedScenes.Add( obj );
|
||||
}
|
||||
}
|
||||
|
||||
visibleWindow.InitiateSearch();
|
||||
mainWindow.InitiateSearch();
|
||||
mainWindow.Repaint();
|
||||
}
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
LoadPrefs();
|
||||
}
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
visibleWindow = this;
|
||||
mainWindow = this;
|
||||
|
||||
#if UNITY_2018_3_OR_NEWER
|
||||
PrefabStage.prefabStageClosing -= ReplacePrefabStageObjectsWithAssets;
|
||||
PrefabStage.prefabStageClosing += ReplacePrefabStageObjectsWithAssets;
|
||||
#endif
|
||||
}
|
||||
|
||||
private void OnDisable()
|
||||
{
|
||||
#if UNITY_2018_3_OR_NEWER
|
||||
PrefabStage.prefabStageClosing -= ReplacePrefabStageObjectsWithAssets;
|
||||
#endif
|
||||
|
||||
if( mainWindow == this )
|
||||
mainWindow = null;
|
||||
}
|
||||
|
||||
private void OnDestroy()
|
||||
@@ -178,13 +275,13 @@ namespace AssetUsageDetectorNamespace.Extras
|
||||
|
||||
SavePrefs();
|
||||
|
||||
if( searchResult != null && currentPhase == Phase.Complete && !EditorApplication.isPlaying && searchResult.IsSceneSetupDifferentThanCurrentSetup() )
|
||||
{
|
||||
if( EditorUtility.DisplayDialog( "Scenes", "Restore initial scene setup?", "Yes", "Leave it as is" ) )
|
||||
searchResult.RestoreInitialSceneSetup();
|
||||
}
|
||||
if( searchResult != null && currentPhase == Phase.Complete )
|
||||
searchResult.RestoreInitialSceneSetup();
|
||||
}
|
||||
|
||||
visibleWindow = null;
|
||||
private void OnFocus()
|
||||
{
|
||||
mainWindow = this;
|
||||
}
|
||||
|
||||
private void SavePrefs()
|
||||
@@ -192,13 +289,15 @@ namespace AssetUsageDetectorNamespace.Extras
|
||||
EditorPrefs.SetInt( PREFS_SEARCH_SCENES, (int) GetSceneSearchMode( false ) );
|
||||
EditorPrefs.SetBool( PREFS_SEARCH_ASSETS, searchInAssetsFolder );
|
||||
EditorPrefs.SetBool( PREFS_DONT_SEARCH_SOURCE_ASSETS, dontSearchInSourceAssets );
|
||||
EditorPrefs.SetBool( PREFS_SEARCH_PROJECT_SETTINGS, searchInProjectSettings );
|
||||
EditorPrefs.SetInt( PREFS_SEARCH_DEPTH_LIMIT, searchDepthLimit );
|
||||
EditorPrefs.SetInt( PREFS_SEARCH_FIELDS, (int) fieldModifiers );
|
||||
EditorPrefs.SetInt( PREFS_SEARCH_PROPERTIES, (int) propertyModifiers );
|
||||
EditorPrefs.SetInt( PREFS_PATH_DRAWING_MODE, (int) searchResultDrawParameters.pathDrawingMode );
|
||||
EditorPrefs.SetBool( PREFS_SEARCH_NON_SERIALIZABLES, searchNonSerializableVariables );
|
||||
EditorPrefs.SetBool( PREFS_LAZY_SCENE_SEARCH, lazySceneSearch );
|
||||
EditorPrefs.SetBool( PREFS_SHOW_TOOLTIPS, searchResultDrawParameters.showTooltips );
|
||||
EditorPrefs.SetBool( PREFS_SHOW_PROGRESS, showProgressBar );
|
||||
EditorPrefs.SetBool( PREFS_SHOW_PROGRESS, showDetailedProgressBar );
|
||||
}
|
||||
|
||||
private void LoadPrefs()
|
||||
@@ -206,7 +305,8 @@ namespace AssetUsageDetectorNamespace.Extras
|
||||
ParseSceneSearchMode( (SceneSearchMode) EditorPrefs.GetInt( PREFS_SEARCH_SCENES, (int) ( SceneSearchMode.OpenScenes | SceneSearchMode.ScenesInBuildSettingsTickedOnly | SceneSearchMode.AllScenes ) ) );
|
||||
|
||||
searchInAssetsFolder = EditorPrefs.GetBool( PREFS_SEARCH_ASSETS, true );
|
||||
dontSearchInSourceAssets = EditorPrefs.GetBool( PREFS_DONT_SEARCH_SOURCE_ASSETS, false );
|
||||
dontSearchInSourceAssets = EditorPrefs.GetBool( PREFS_DONT_SEARCH_SOURCE_ASSETS, true );
|
||||
searchInProjectSettings = EditorPrefs.GetBool( PREFS_SEARCH_PROJECT_SETTINGS, true );
|
||||
searchDepthLimit = EditorPrefs.GetInt( PREFS_SEARCH_DEPTH_LIMIT, 4 );
|
||||
|
||||
// Fetch public, protected and private non-static fields and properties from objects by default
|
||||
@@ -223,8 +323,9 @@ namespace AssetUsageDetectorNamespace.Extras
|
||||
}
|
||||
|
||||
searchNonSerializableVariables = EditorPrefs.GetBool( PREFS_SEARCH_NON_SERIALIZABLES, true );
|
||||
lazySceneSearch = EditorPrefs.GetBool( PREFS_LAZY_SCENE_SEARCH, true );
|
||||
searchResultDrawParameters.showTooltips = EditorPrefs.GetBool( PREFS_SHOW_TOOLTIPS, false );
|
||||
showProgressBar = EditorPrefs.GetBool( PREFS_SHOW_PROGRESS, false );
|
||||
showDetailedProgressBar = EditorPrefs.GetBool( PREFS_SHOW_PROGRESS, true );
|
||||
}
|
||||
|
||||
private SceneSearchMode GetSceneSearchMode( bool hideOptionsInPlayMode )
|
||||
@@ -259,6 +360,12 @@ namespace AssetUsageDetectorNamespace.Extras
|
||||
nextPlayModeRefreshTime = EditorApplication.timeSinceStartup + PLAY_MODE_REFRESH_INTERVAL; ;
|
||||
Repaint();
|
||||
}
|
||||
|
||||
if( shouldRepositionSelf )
|
||||
{
|
||||
shouldRepositionSelf = false;
|
||||
position = windowTargetPosition;
|
||||
}
|
||||
}
|
||||
|
||||
private void OnGUI()
|
||||
@@ -268,34 +375,26 @@ namespace AssetUsageDetectorNamespace.Extras
|
||||
|
||||
GUILayout.BeginVertical();
|
||||
|
||||
GUILayout.Space( 10 );
|
||||
|
||||
// Show the error message, if it is not empty
|
||||
if( errorMessage.Length > 0 )
|
||||
EditorGUILayout.HelpBox( errorMessage, MessageType.Error );
|
||||
|
||||
GUILayout.Space( 10 );
|
||||
|
||||
if( currentPhase == Phase.Processing )
|
||||
{
|
||||
// If we are stuck at this phase, then we have encountered an exception
|
||||
GUILayout.Label( ". . . Something went wrong, check console . . ." );
|
||||
|
||||
restoreInitialSceneSetup = EditorGUILayout.ToggleLeft( "Restore initial scene setup (Recommended)", restoreInitialSceneSetup );
|
||||
GUILayout.Label( ". . . Search in progress or something went wrong (check console) . . ." );
|
||||
|
||||
if( GUILayout.Button( "RETURN", Utilities.GL_HEIGHT_30 ) )
|
||||
ReturnToSetupPhase( restoreInitialSceneSetup );
|
||||
ReturnToSetupPhase();
|
||||
}
|
||||
else if( currentPhase == Phase.Setup )
|
||||
{
|
||||
if( objectsToSearchDrawer.Draw( objectsToSearch ) )
|
||||
errorMessage = string.Empty;
|
||||
objectsToSearchDrawer.Draw( objectsToSearch );
|
||||
|
||||
GUILayout.Space( 10 );
|
||||
|
||||
Color c = GUI.backgroundColor;
|
||||
GUI.backgroundColor = Color.cyan;
|
||||
GUILayout.Box( "SEARCH IN", Utilities.BoxGUIStyle, Utilities.GL_EXPAND_WIDTH );
|
||||
GUI.backgroundColor = c;
|
||||
|
||||
searchInAssetsFolder = EditorGUILayout.ToggleLeft( "Project view (Assets folder)", searchInAssetsFolder );
|
||||
searchInAssetsFolder = EditorGUILayout.ToggleLeft( "Project window (Assets folder)", searchInAssetsFolder );
|
||||
|
||||
if( searchInAssetsFolder )
|
||||
{
|
||||
@@ -306,13 +405,13 @@ namespace AssetUsageDetectorNamespace.Extras
|
||||
searchInAssetsSubsetDrawer.Draw( searchInAssetsSubset );
|
||||
excludedAssetsDrawer.Draw( excludedAssets );
|
||||
|
||||
dontSearchInSourceAssets = EditorGUILayout.ToggleLeft( "Don't search 'Asset(s)' themselves for references", dontSearchInSourceAssets );
|
||||
dontSearchInSourceAssets = EditorGUILayout.ToggleLeft( "Don't search \"Find references of\" themselves for references", dontSearchInSourceAssets );
|
||||
|
||||
GUILayout.EndVertical();
|
||||
GUILayout.EndHorizontal();
|
||||
}
|
||||
|
||||
GUILayout.Space( 10 );
|
||||
Utilities.DrawSeparatorLine();
|
||||
|
||||
if( searchInAllScenes && !EditorApplication.isPlaying )
|
||||
GUI.enabled = false;
|
||||
@@ -348,66 +447,83 @@ namespace AssetUsageDetectorNamespace.Extras
|
||||
GUILayout.EndVertical();
|
||||
GUILayout.EndHorizontal();
|
||||
|
||||
GUILayout.Space( 10 );
|
||||
Utilities.DrawSeparatorLine();
|
||||
|
||||
GUILayout.Box( "SEARCH SETTINGS", Utilities.BoxGUIStyle, Utilities.GL_EXPAND_WIDTH );
|
||||
|
||||
GUILayout.BeginHorizontal();
|
||||
|
||||
GUILayout.Label( new GUIContent( "> Search depth: " + searchDepthLimit, "Depth limit for recursively searching variables of objects" ), Utilities.GL_WIDTH_250 );
|
||||
|
||||
searchDepthLimit = (int) GUILayout.HorizontalSlider( searchDepthLimit, 0, 4 );
|
||||
|
||||
GUILayout.EndHorizontal();
|
||||
|
||||
GUILayout.Label( "> Search variables:" );
|
||||
|
||||
GUILayout.BeginHorizontal();
|
||||
|
||||
GUILayout.Space( 35 );
|
||||
|
||||
if( EditorGUILayout.ToggleLeft( "Public", ( fieldModifiers & BindingFlags.Public ) == BindingFlags.Public, Utilities.GL_WIDTH_100 ) )
|
||||
fieldModifiers |= BindingFlags.Public;
|
||||
else
|
||||
fieldModifiers &= ~BindingFlags.Public;
|
||||
|
||||
if( EditorGUILayout.ToggleLeft( "Non-public", ( fieldModifiers & BindingFlags.NonPublic ) == BindingFlags.NonPublic, Utilities.GL_WIDTH_100 ) )
|
||||
fieldModifiers |= BindingFlags.NonPublic;
|
||||
else
|
||||
fieldModifiers &= ~BindingFlags.NonPublic;
|
||||
|
||||
GUILayout.EndHorizontal();
|
||||
|
||||
GUILayout.Label( "> Search properties:" );
|
||||
|
||||
GUILayout.BeginHorizontal();
|
||||
|
||||
GUILayout.Space( 35 );
|
||||
|
||||
if( EditorGUILayout.ToggleLeft( "Public", ( propertyModifiers & BindingFlags.Public ) == BindingFlags.Public, Utilities.GL_WIDTH_100 ) )
|
||||
propertyModifiers |= BindingFlags.Public;
|
||||
else
|
||||
propertyModifiers &= ~BindingFlags.Public;
|
||||
|
||||
if( EditorGUILayout.ToggleLeft( "Non-public", ( propertyModifiers & BindingFlags.NonPublic ) == BindingFlags.NonPublic, Utilities.GL_WIDTH_100 ) )
|
||||
propertyModifiers |= BindingFlags.NonPublic;
|
||||
else
|
||||
propertyModifiers &= ~BindingFlags.NonPublic;
|
||||
|
||||
GUILayout.EndHorizontal();
|
||||
searchInProjectSettings = EditorGUILayout.ToggleLeft( "Project Settings (Player Settings, Graphics Settings etc.)", searchInProjectSettings );
|
||||
|
||||
GUILayout.Space( 10 );
|
||||
|
||||
searchNonSerializableVariables = EditorGUILayout.ToggleLeft( "Include non-serializable fields and properties in search (slower search)", searchNonSerializableVariables );
|
||||
//GUILayout.Box( "SEARCH SETTINGS", Utilities.BoxGUIStyle, Utilities.GL_EXPAND_WIDTH );
|
||||
|
||||
//GUILayout.BeginHorizontal();
|
||||
|
||||
//GUILayout.Label( new GUIContent( "> Search depth: " + searchDepthLimit, "Depth limit for recursively searching variables of objects" ), Utilities.GL_WIDTH_250 );
|
||||
|
||||
//searchDepthLimit = (int) GUILayout.HorizontalSlider( searchDepthLimit, 0, 4 );
|
||||
|
||||
//GUILayout.EndHorizontal();
|
||||
|
||||
//GUILayout.Label( "> Search variables:" );
|
||||
|
||||
//GUILayout.BeginHorizontal();
|
||||
|
||||
//GUILayout.Space( 35 );
|
||||
|
||||
//if( EditorGUILayout.ToggleLeft( "Public", ( fieldModifiers & BindingFlags.Public ) == BindingFlags.Public, Utilities.GL_WIDTH_100 ) )
|
||||
// fieldModifiers |= BindingFlags.Public;
|
||||
//else
|
||||
// fieldModifiers &= ~BindingFlags.Public;
|
||||
|
||||
//if( EditorGUILayout.ToggleLeft( "Non-public", ( fieldModifiers & BindingFlags.NonPublic ) == BindingFlags.NonPublic, Utilities.GL_WIDTH_100 ) )
|
||||
// fieldModifiers |= BindingFlags.NonPublic;
|
||||
//else
|
||||
// fieldModifiers &= ~BindingFlags.NonPublic;
|
||||
|
||||
//GUILayout.EndHorizontal();
|
||||
|
||||
//GUILayout.Label( "> Search properties:" );
|
||||
|
||||
//GUILayout.BeginHorizontal();
|
||||
|
||||
//GUILayout.Space( 35 );
|
||||
|
||||
//if( EditorGUILayout.ToggleLeft( "Public", ( propertyModifiers & BindingFlags.Public ) == BindingFlags.Public, Utilities.GL_WIDTH_100 ) )
|
||||
// propertyModifiers |= BindingFlags.Public;
|
||||
//else
|
||||
// propertyModifiers &= ~BindingFlags.Public;
|
||||
|
||||
//if( EditorGUILayout.ToggleLeft( "Non-public", ( propertyModifiers & BindingFlags.NonPublic ) == BindingFlags.NonPublic, Utilities.GL_WIDTH_100 ) )
|
||||
// propertyModifiers |= BindingFlags.NonPublic;
|
||||
//else
|
||||
// propertyModifiers &= ~BindingFlags.NonPublic;
|
||||
|
||||
//GUILayout.EndHorizontal();
|
||||
|
||||
//GUILayout.Space( 10 );
|
||||
|
||||
//searchNonSerializableVariables = EditorGUILayout.ToggleLeft( "Search non-serializable fields and properties", searchNonSerializableVariables );
|
||||
|
||||
//GUILayout.Space( 10 );
|
||||
|
||||
GUI.backgroundColor = Color.cyan;
|
||||
GUILayout.Box( "SETTINGS", Utilities.BoxGUIStyle, Utilities.GL_EXPAND_WIDTH );
|
||||
GUI.backgroundColor = c;
|
||||
|
||||
lazySceneSearch = EditorGUILayout.ToggleLeft( "Lazy scene search: scenes are searched in detail only when they are manually refreshed (faster search)", lazySceneSearch );
|
||||
noAssetDatabaseChanges = EditorGUILayout.ToggleLeft( "I haven't modified any assets/scenes since the last search (faster search)", noAssetDatabaseChanges );
|
||||
showProgressBar = EditorGUILayout.ToggleLeft( "Show progress bar (slower search)", showProgressBar );
|
||||
showDetailedProgressBar = EditorGUILayout.ToggleLeft( "Update search progress bar more often (slower search)", showDetailedProgressBar );
|
||||
|
||||
GUILayout.Space( 10 );
|
||||
|
||||
// Don't let the user press the GO button without any valid search location
|
||||
if( !searchInAllScenes && !searchInOpenScenes && !searchInScenesInBuild && !searchInAssetsFolder )
|
||||
if( !searchInAllScenes && !searchInOpenScenes && !searchInScenesInBuild && !searchInAssetsFolder && !searchInProjectSettings )
|
||||
GUI.enabled = false;
|
||||
|
||||
if( GUILayout.Button( "GO!", Utilities.GL_HEIGHT_30 ) )
|
||||
{
|
||||
InitiateSearch();
|
||||
GUIUtility.ExitGUI();
|
||||
}
|
||||
}
|
||||
else if( currentPhase == Phase.Complete )
|
||||
{
|
||||
@@ -419,10 +535,8 @@ namespace AssetUsageDetectorNamespace.Extras
|
||||
GUILayout.Space( 10 );
|
||||
GUI.enabled = true;
|
||||
|
||||
restoreInitialSceneSetup = EditorGUILayout.ToggleLeft( "Restore initial scene setup after search is reset (Recommended)", restoreInitialSceneSetup );
|
||||
|
||||
if( GUILayout.Button( "Reset Search", Utilities.GL_HEIGHT_30 ) )
|
||||
ReturnToSetupPhase( restoreInitialSceneSetup );
|
||||
ReturnToSetupPhase();
|
||||
|
||||
if( searchResult == null )
|
||||
{
|
||||
@@ -432,42 +546,46 @@ namespace AssetUsageDetectorNamespace.Extras
|
||||
else if( !searchResult.SearchCompletedSuccessfully )
|
||||
EditorGUILayout.HelpBox( "ERROR: search was interrupted, check the logs for more info", MessageType.Error );
|
||||
|
||||
Color c = GUI.color;
|
||||
GUI.color = Color.green;
|
||||
Color c = GUI.backgroundColor;
|
||||
GUI.backgroundColor = Color.green;
|
||||
GUILayout.Box( "Don't forget to save scene(s) if you made any changes!", Utilities.BoxGUIStyle, Utilities.GL_EXPAND_WIDTH );
|
||||
GUI.color = c;
|
||||
|
||||
GUILayout.Space( 10 );
|
||||
GUI.backgroundColor = c;
|
||||
|
||||
if( searchResult.NumberOfGroups == 0 )
|
||||
GUILayout.Box( "No results found...", Utilities.BoxGUIStyle, Utilities.GL_EXPAND_WIDTH );
|
||||
{
|
||||
GUILayout.Space( 10 );
|
||||
GUILayout.Box( "No references found...", Utilities.BoxGUIStyle, Utilities.GL_EXPAND_WIDTH );
|
||||
}
|
||||
else
|
||||
{
|
||||
GUILayout.BeginHorizontal();
|
||||
//GUILayout.Space( 10 );
|
||||
//GUILayout.BeginHorizontal();
|
||||
|
||||
// Select all the references after filtering them (select only the GameObject's)
|
||||
if( GUILayout.Button( "Select All\n(GameObject-wise)", Utilities.GL_HEIGHT_35 ) )
|
||||
{
|
||||
GameObject[] objects = searchResult.SelectAllAsGameObjects();
|
||||
if( objects != null && objects.Length > 0 )
|
||||
Selection.objects = objects;
|
||||
}
|
||||
//// Select all the references after filtering them (select only the GameObject's)
|
||||
//if( GUILayout.Button( "Select All\n(GameObject-wise)", Utilities.GL_HEIGHT_35 ) )
|
||||
//{
|
||||
// GameObject[] objects = searchResult.SelectAllAsGameObjects();
|
||||
// if( objects != null && objects.Length > 0 )
|
||||
// Selection.objects = objects;
|
||||
//}
|
||||
|
||||
// Select all the references without filtering them
|
||||
if( GUILayout.Button( "Select All\n(Object-wise)", Utilities.GL_HEIGHT_35 ) )
|
||||
{
|
||||
Object[] objects = searchResult.SelectAllAsObjects();
|
||||
if( objects != null && objects.Length > 0 )
|
||||
Selection.objects = objects;
|
||||
}
|
||||
//// Select all the references without filtering them
|
||||
//if( GUILayout.Button( "Select All\n(Object-wise)", Utilities.GL_HEIGHT_35 ) )
|
||||
//{
|
||||
// Object[] objects = searchResult.SelectAllAsObjects();
|
||||
// if( objects != null && objects.Length > 0 )
|
||||
// Selection.objects = objects;
|
||||
//}
|
||||
|
||||
GUILayout.EndHorizontal();
|
||||
//GUILayout.EndHorizontal();
|
||||
|
||||
GUILayout.Space( 10 );
|
||||
//GUILayout.Space( 10 );
|
||||
|
||||
searchResultDrawParameters.showTooltips = EditorGUILayout.ToggleLeft( "Show tooltips", searchResultDrawParameters.showTooltips );
|
||||
searchResultDrawParameters.showTooltips = EditorGUILayout.ToggleLeft( showTooltipsLabel, searchResultDrawParameters.showTooltips );
|
||||
noAssetDatabaseChanges = EditorGUILayout.ToggleLeft( "I haven't modified any assets/scenes since the last search (faster Refresh)", noAssetDatabaseChanges );
|
||||
searchResultDrawParameters.noAssetDatabaseChanges = noAssetDatabaseChanges;
|
||||
|
||||
GUILayout.Space( 10 );
|
||||
Utilities.DrawSeparatorLine();
|
||||
|
||||
GUILayout.Label( "Path drawing mode:" );
|
||||
|
||||
@@ -475,7 +593,7 @@ namespace AssetUsageDetectorNamespace.Extras
|
||||
|
||||
GUILayout.Space( 35 );
|
||||
|
||||
if( EditorGUILayout.ToggleLeft( "Full: Draw the complete paths to the references (can be slow with too many references)", searchResultDrawParameters.pathDrawingMode == PathDrawingMode.Full ) )
|
||||
if( EditorGUILayout.ToggleLeft( "Full: Draw the complete paths to the references", searchResultDrawParameters.pathDrawingMode == PathDrawingMode.Full ) )
|
||||
searchResultDrawParameters.pathDrawingMode = PathDrawingMode.Full;
|
||||
|
||||
GUILayout.EndHorizontal();
|
||||
@@ -484,7 +602,7 @@ namespace AssetUsageDetectorNamespace.Extras
|
||||
|
||||
GUILayout.Space( 35 );
|
||||
|
||||
if( EditorGUILayout.ToggleLeft( "Shorter: Draw only the most relevant unique parts of the complete paths that start with a UnityEngine.Object", searchResultDrawParameters.pathDrawingMode == PathDrawingMode.ShortRelevantParts ) )
|
||||
if( EditorGUILayout.ToggleLeft( "Shorter: Draw only the most relevant parts (that start with a UnityEngine.Object) of the complete paths", searchResultDrawParameters.pathDrawingMode == PathDrawingMode.ShortRelevantParts ) )
|
||||
searchResultDrawParameters.pathDrawingMode = PathDrawingMode.ShortRelevantParts;
|
||||
|
||||
GUILayout.EndHorizontal();
|
||||
@@ -493,7 +611,7 @@ namespace AssetUsageDetectorNamespace.Extras
|
||||
|
||||
GUILayout.Space( 35 );
|
||||
|
||||
if( EditorGUILayout.ToggleLeft( "Shortest: Draw only the last two nodes of complete paths that are unique", searchResultDrawParameters.pathDrawingMode == PathDrawingMode.Shortest ) )
|
||||
if( EditorGUILayout.ToggleLeft( "Shortest: Draw only the last two nodes of the complete paths", searchResultDrawParameters.pathDrawingMode == PathDrawingMode.Shortest ) )
|
||||
searchResultDrawParameters.pathDrawingMode = PathDrawingMode.Shortest;
|
||||
|
||||
GUILayout.EndHorizontal();
|
||||
@@ -511,50 +629,83 @@ namespace AssetUsageDetectorNamespace.Extras
|
||||
|
||||
private void InitiateSearch()
|
||||
{
|
||||
if( objectsToSearch.IsEmpty() )
|
||||
errorMessage = "ADD AN ASSET TO THE LIST FIRST!";
|
||||
else if( !EditorApplication.isPlaying && !Utilities.AreScenesSaved() )
|
||||
currentPhase = Phase.Processing;
|
||||
|
||||
SavePrefs();
|
||||
|
||||
#if UNITY_2018_3_OR_NEWER
|
||||
ReplacePrefabStageObjectsWithAssets( PrefabStageUtility.GetCurrentPrefabStage() );
|
||||
#endif
|
||||
|
||||
// Start searching
|
||||
searchResult = core.Run( new AssetUsageDetector.Parameters()
|
||||
{
|
||||
// Don't start the search if at least one scene is currently dirty (not saved)
|
||||
errorMessage = "SAVE OPEN SCENES FIRST!";
|
||||
}
|
||||
else
|
||||
{
|
||||
errorMessage = string.Empty;
|
||||
currentPhase = Phase.Processing;
|
||||
objectsToSearch = !objectsToSearch.IsEmpty() ? new ObjectToSearchEnumerator( objectsToSearch ).ToArray() : null,
|
||||
searchInScenes = GetSceneSearchMode( true ),
|
||||
searchInAssetsFolder = searchInAssetsFolder,
|
||||
searchInAssetsSubset = !searchInAssetsSubset.IsEmpty() ? searchInAssetsSubset.ToArray() : null,
|
||||
excludedAssetsFromSearch = !excludedAssets.IsEmpty() ? excludedAssets.ToArray() : null,
|
||||
dontSearchInSourceAssets = dontSearchInSourceAssets,
|
||||
excludedScenesFromSearch = !excludedScenes.IsEmpty() ? excludedScenes.ToArray() : null,
|
||||
searchInProjectSettings = searchInProjectSettings,
|
||||
//fieldModifiers = fieldModifiers,
|
||||
//propertyModifiers = propertyModifiers,
|
||||
//searchDepthLimit = searchDepthLimit,
|
||||
//searchNonSerializableVariables = searchNonSerializableVariables,
|
||||
lazySceneSearch = lazySceneSearch,
|
||||
noAssetDatabaseChanges = noAssetDatabaseChanges,
|
||||
showDetailedProgressBar = showDetailedProgressBar
|
||||
} );
|
||||
|
||||
SavePrefs();
|
||||
|
||||
// Start searching
|
||||
searchResult = core.Run( new AssetUsageDetector.Parameters()
|
||||
{
|
||||
objectsToSearch = !objectsToSearch.IsEmpty() ? new ObjectToSearchEnumerator( objectsToSearch ) : null,
|
||||
searchInScenes = GetSceneSearchMode( true ),
|
||||
searchInAssetsFolder = searchInAssetsFolder,
|
||||
searchInAssetsSubset = !searchInAssetsSubset.IsEmpty() ? searchInAssetsSubset : null,
|
||||
excludedAssetsFromSearch = !excludedAssets.IsEmpty() ? excludedAssets : null,
|
||||
dontSearchInSourceAssets = dontSearchInSourceAssets,
|
||||
excludedScenesFromSearch = !excludedScenes.IsEmpty() ? excludedScenes : null,
|
||||
fieldModifiers = fieldModifiers,
|
||||
propertyModifiers = propertyModifiers,
|
||||
searchDepthLimit = searchDepthLimit,
|
||||
searchNonSerializableVariables = searchNonSerializableVariables,
|
||||
noAssetDatabaseChanges = noAssetDatabaseChanges,
|
||||
showProgressBar = showProgressBar
|
||||
} );
|
||||
|
||||
currentPhase = Phase.Complete;
|
||||
}
|
||||
currentPhase = Phase.Complete;
|
||||
}
|
||||
|
||||
private bool ReturnToSetupPhase( bool restoreInitialSceneSetup )
|
||||
#if UNITY_2018_3_OR_NEWER
|
||||
// Try replacing searched objects who are part of currently open prefab stage with their corresponding prefab assets
|
||||
public void ReplacePrefabStageObjectsWithAssets( PrefabStage prefabStage )
|
||||
{
|
||||
if( searchResult != null && restoreInitialSceneSetup && !EditorApplication.isPlaying && !searchResult.RestoreInitialSceneSetup() )
|
||||
if( prefabStage == null || !prefabStage.stageHandle.IsValid() )
|
||||
return;
|
||||
|
||||
#if UNITY_2020_1_OR_NEWER
|
||||
GameObject prefabAsset = AssetDatabase.LoadAssetAtPath<GameObject>( prefabStage.assetPath );
|
||||
#else
|
||||
GameObject prefabAsset = AssetDatabase.LoadAssetAtPath<GameObject>( prefabStage.prefabAssetPath );
|
||||
#endif
|
||||
if( prefabAsset == null || prefabAsset.Equals( null ) )
|
||||
return;
|
||||
|
||||
for( int i = 0; i < objectsToSearch.Count; i++ )
|
||||
{
|
||||
Object obj = objectsToSearch[i].obj;
|
||||
if( obj != null && !obj.Equals( null ) && obj is GameObject && prefabStage.IsPartOfPrefabContents( (GameObject) obj ) )
|
||||
{
|
||||
GameObject prefabStageObjectSource = ( (GameObject) obj ).FollowSymmetricHierarchy( prefabStage.prefabContentsRoot, prefabAsset );
|
||||
if( prefabStageObjectSource != null )
|
||||
objectsToSearch[i].obj = prefabStageObjectSource;
|
||||
|
||||
List<ObjectToSearch.SubAsset> subAssets = objectsToSearch[i].subAssets;
|
||||
for( int j = 0; j < subAssets.Count; j++ )
|
||||
{
|
||||
obj = subAssets[j].subAsset;
|
||||
if( obj != null && !obj.Equals( null ) && obj is GameObject && prefabStage.IsPartOfPrefabContents( (GameObject) obj ) )
|
||||
{
|
||||
prefabStageObjectSource = ( (GameObject) obj ).FollowSymmetricHierarchy( prefabStage.prefabContentsRoot, prefabAsset );
|
||||
if( prefabStageObjectSource != null )
|
||||
subAssets[j].subAsset = prefabStageObjectSource;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
private bool ReturnToSetupPhase()
|
||||
{
|
||||
if( searchResult != null && !EditorApplication.isPlaying && !searchResult.RestoreInitialSceneSetup() )
|
||||
return false;
|
||||
|
||||
searchResult = null;
|
||||
|
||||
errorMessage = string.Empty;
|
||||
currentPhase = Phase.Setup;
|
||||
|
||||
return true;
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace AssetUsageDetectorNamespace.Extras
|
||||
namespace AssetUsageDetectorNamespace
|
||||
{
|
||||
public class EmptyEnumerator<T> : IEnumerable<T>, IEnumerator<T>
|
||||
{
|
||||
@@ -112,5 +112,19 @@ namespace AssetUsageDetectorNamespace.Extras
|
||||
{
|
||||
return GetEnumerator();
|
||||
}
|
||||
|
||||
public Object[] ToArray()
|
||||
{
|
||||
int count = 0;
|
||||
foreach( Object obj in this )
|
||||
count++;
|
||||
|
||||
Object[] result = new Object[count];
|
||||
int index = 0;
|
||||
foreach( Object obj in this )
|
||||
result[index++] = obj;
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,7 +2,7 @@
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace AssetUsageDetectorNamespace.Extras
|
||||
namespace AssetUsageDetectorNamespace
|
||||
{
|
||||
public abstract class ListDrawer<T>
|
||||
{
|
||||
@@ -46,8 +46,22 @@ namespace AssetUsageDetectorNamespace.Extras
|
||||
{
|
||||
if( draggedObjects[i] != null && !draggedObjects[i].Equals( null ) )
|
||||
{
|
||||
bool replacedNullElement = false;
|
||||
for( int j = 0; j < list.Count; j++ )
|
||||
{
|
||||
if( IsElementNull( list[j] ) )
|
||||
{
|
||||
list[j] = CreateElement( draggedObjects[i] );
|
||||
|
||||
replacedNullElement = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if( !replacedNullElement )
|
||||
list.Add( CreateElement( draggedObjects[i] ) );
|
||||
|
||||
hasChanged = true;
|
||||
list.Add( CreateElement( draggedObjects[i] ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -72,12 +86,18 @@ namespace AssetUsageDetectorNamespace.Extras
|
||||
Object prevObject = GetObjectFromElement( element );
|
||||
Object newObject = EditorGUILayout.ObjectField( "", prevObject, typeof( Object ), acceptSceneObjects );
|
||||
|
||||
if( GUI.changed && prevObject != newObject )
|
||||
if( GUI.changed )
|
||||
{
|
||||
hasChanged = true;
|
||||
SetObjectOfElement( list, i, newObject );
|
||||
}
|
||||
|
||||
if( guiEnabled && newObject && ev.type == EventType.ContextClick && GUILayoutUtility.GetLastRect().Contains( ev.mousePosition ) )
|
||||
{
|
||||
OnElementRightClicked( list, i, newObject );
|
||||
ev.Use();
|
||||
}
|
||||
|
||||
if( guiEnabled )
|
||||
{
|
||||
if( GUILayout.Button( "+", Utilities.GL_WIDTH_25 ) )
|
||||
@@ -107,6 +127,8 @@ namespace AssetUsageDetectorNamespace.Extras
|
||||
protected abstract T CreateElement( Object source );
|
||||
protected abstract Object GetObjectFromElement( T element );
|
||||
protected abstract void SetObjectOfElement( List<T> list, int index, Object value );
|
||||
protected abstract void OnElementRightClicked( List<T> list, int index, Object value );
|
||||
protected abstract bool IsElementNull( T element );
|
||||
protected abstract void PostElementDrawer( T element );
|
||||
}
|
||||
|
||||
@@ -131,6 +153,15 @@ namespace AssetUsageDetectorNamespace.Extras
|
||||
list[index] = value;
|
||||
}
|
||||
|
||||
protected override void OnElementRightClicked( List<Object> list, int index, Object value )
|
||||
{
|
||||
}
|
||||
|
||||
protected override bool IsElementNull( Object element )
|
||||
{
|
||||
return element == null || element.Equals( null );
|
||||
}
|
||||
|
||||
protected override void PostElementDrawer( Object element )
|
||||
{
|
||||
}
|
||||
@@ -138,7 +169,7 @@ namespace AssetUsageDetectorNamespace.Extras
|
||||
|
||||
public class ObjectToSearchListDrawer : ListDrawer<ObjectToSearch>
|
||||
{
|
||||
public ObjectToSearchListDrawer() : base( "Asset(s):", true )
|
||||
public ObjectToSearchListDrawer() : base( "Find references of:", true )
|
||||
{
|
||||
}
|
||||
|
||||
@@ -158,6 +189,18 @@ namespace AssetUsageDetectorNamespace.Extras
|
||||
list[index].RefreshSubAssets();
|
||||
}
|
||||
|
||||
protected override void OnElementRightClicked( List<ObjectToSearch> list, int index, Object value )
|
||||
{
|
||||
GenericMenu contextMenu = new GenericMenu();
|
||||
contextMenu.AddItem( new GUIContent( "Refresh" ), false, () => SetObjectOfElement( list, index, value ) );
|
||||
contextMenu.ShowAsContext();
|
||||
}
|
||||
|
||||
protected override bool IsElementNull( ObjectToSearch element )
|
||||
{
|
||||
return element == null || element.obj == null || element.obj.Equals( null );
|
||||
}
|
||||
|
||||
protected override void PostElementDrawer( ObjectToSearch element )
|
||||
{
|
||||
List<ObjectToSearch.SubAsset> subAssetsToSearch = element.subAssets;
|
||||
|
||||
@@ -4,7 +4,7 @@ using UnityEditor;
|
||||
using UnityEngine;
|
||||
using Object = UnityEngine.Object;
|
||||
|
||||
namespace AssetUsageDetectorNamespace.Extras
|
||||
namespace AssetUsageDetectorNamespace
|
||||
{
|
||||
[Serializable]
|
||||
public class ObjectToSearch
|
||||
@@ -29,13 +29,13 @@ namespace AssetUsageDetectorNamespace.Extras
|
||||
private static MonoScript[] monoScriptsInProject;
|
||||
private static HashSet<Object> currentSubAssets;
|
||||
|
||||
public ObjectToSearch( Object obj )
|
||||
public ObjectToSearch( Object obj, bool? shouldSearchChildren = null )
|
||||
{
|
||||
this.obj = obj;
|
||||
RefreshSubAssets();
|
||||
RefreshSubAssets( shouldSearchChildren );
|
||||
}
|
||||
|
||||
public void RefreshSubAssets()
|
||||
public void RefreshSubAssets( bool? shouldSearchChildren = null )
|
||||
{
|
||||
if( subAssets == null )
|
||||
subAssets = new List<SubAsset>();
|
||||
@@ -47,83 +47,104 @@ namespace AssetUsageDetectorNamespace.Extras
|
||||
else
|
||||
currentSubAssets.Clear();
|
||||
|
||||
AddSubAssets( obj, false );
|
||||
AddSubAssets( obj, false, shouldSearchChildren );
|
||||
currentSubAssets.Clear();
|
||||
}
|
||||
|
||||
private void AddSubAssets( Object target, bool includeTarget )
|
||||
private void AddSubAssets( Object target, bool includeTarget, bool? shouldSearchChildren )
|
||||
{
|
||||
if( target == null || target.Equals( null ) )
|
||||
return;
|
||||
|
||||
if( !target.IsAsset() || !AssetDatabase.IsMainAsset( target ) || target is SceneAsset )
|
||||
return;
|
||||
|
||||
if( includeTarget )
|
||||
if( !target.IsAsset() )
|
||||
{
|
||||
if( !currentSubAssets.Contains( target ) )
|
||||
GameObject go = target as GameObject;
|
||||
if( !go || !go.scene.IsValid() )
|
||||
return;
|
||||
|
||||
// If this is a scene object, add its child objects to the sub-assets list
|
||||
// but don't include them in the search by default
|
||||
Transform goTransform = go.transform;
|
||||
Transform[] children = go.GetComponentsInChildren<Transform>( true );
|
||||
for( int i = 0; i < children.Length; i++ )
|
||||
{
|
||||
subAssets.Add( new SubAsset( target, true ) );
|
||||
currentSubAssets.Add( target );
|
||||
if( ReferenceEquals( children[i], goTransform ) )
|
||||
continue;
|
||||
|
||||
subAssets.Add( new SubAsset( children[i].gameObject, shouldSearchChildren ?? false ) );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// If asset is a directory, add all of its contents as sub-assets recursively
|
||||
if( target.IsFolder() )
|
||||
{
|
||||
foreach( string filePath in Utilities.EnumerateFolderContents( target ) )
|
||||
AddSubAssets( AssetDatabase.LoadAssetAtPath<Object>( filePath ), true );
|
||||
|
||||
if( !AssetDatabase.IsMainAsset( target ) || target is SceneAsset )
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Find sub-asset(s) of the asset (if any)
|
||||
Object[] assets = AssetDatabase.LoadAllAssetsAtPath( AssetDatabase.GetAssetPath( target ) );
|
||||
for( int i = 0; i < assets.Length; i++ )
|
||||
{
|
||||
Object asset = assets[i];
|
||||
if( asset == null || asset.Equals( null ) || asset is Component )
|
||||
continue;
|
||||
|
||||
if( currentSubAssets.Contains( asset ) )
|
||||
continue;
|
||||
|
||||
if( asset != target )
|
||||
if( includeTarget )
|
||||
{
|
||||
subAssets.Add( new SubAsset( asset, true ) );
|
||||
currentSubAssets.Add( asset );
|
||||
if( !currentSubAssets.Contains( target ) )
|
||||
{
|
||||
subAssets.Add( new SubAsset( target, shouldSearchChildren ?? true ) );
|
||||
currentSubAssets.Add( target );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// If asset is a directory, add all of its contents as sub-assets recursively
|
||||
if( target.IsFolder() )
|
||||
{
|
||||
foreach( string filePath in Utilities.EnumerateFolderContents( target ) )
|
||||
AddSubAssets( AssetDatabase.LoadAssetAtPath<Object>( filePath ), true, shouldSearchChildren );
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// MonoScripts are a special case such that other MonoScript objects
|
||||
// that extend this MonoScript are also considered a sub-asset
|
||||
if( asset is MonoScript )
|
||||
// Find sub-asset(s) of the asset (if any)
|
||||
Object[] assets = AssetDatabase.LoadAllAssetsAtPath( AssetDatabase.GetAssetPath( target ) );
|
||||
for( int i = 0; i < assets.Length; i++ )
|
||||
{
|
||||
Type monoScriptType = ( (MonoScript) asset ).GetClass();
|
||||
if( monoScriptType == null || ( !monoScriptType.IsInterface && !typeof( Component ).IsAssignableFrom( monoScriptType ) ) )
|
||||
Object asset = assets[i];
|
||||
if( asset == null || asset.Equals( null ) || asset is Component )
|
||||
continue;
|
||||
|
||||
// Find all MonoScript objects in the project
|
||||
if( monoScriptsInProject == null )
|
||||
if( currentSubAssets.Contains( asset ) )
|
||||
continue;
|
||||
|
||||
if( asset != target )
|
||||
{
|
||||
string[] monoScriptGuids = AssetDatabase.FindAssets( "t:MonoScript" );
|
||||
monoScriptsInProject = new MonoScript[monoScriptGuids.Length];
|
||||
for( int k = 0; k < monoScriptGuids.Length; k++ )
|
||||
monoScriptsInProject[k] = AssetDatabase.LoadAssetAtPath<MonoScript>( AssetDatabase.GUIDToAssetPath( monoScriptGuids[k] ) );
|
||||
subAssets.Add( new SubAsset( asset, shouldSearchChildren ?? true ) );
|
||||
currentSubAssets.Add( asset );
|
||||
}
|
||||
|
||||
// Add any MonoScript objects that extend this MonoScript as a sub-asset
|
||||
for( int j = 0; j < monoScriptsInProject.Length; j++ )
|
||||
// MonoScripts are a special case such that other MonoScript objects
|
||||
// that extend this MonoScript are also considered a sub-asset
|
||||
if( asset is MonoScript )
|
||||
{
|
||||
Type otherMonoScriptType = monoScriptsInProject[j].GetClass();
|
||||
if( otherMonoScriptType == null || monoScriptType == otherMonoScriptType || !monoScriptType.IsAssignableFrom( otherMonoScriptType ) )
|
||||
Type monoScriptType = ( (MonoScript) asset ).GetClass();
|
||||
if( monoScriptType == null || ( !monoScriptType.IsInterface && !typeof( Component ).IsAssignableFrom( monoScriptType ) ) )
|
||||
continue;
|
||||
|
||||
if( !currentSubAssets.Contains( monoScriptsInProject[j] ) )
|
||||
// Find all MonoScript objects in the project
|
||||
if( monoScriptsInProject == null )
|
||||
{
|
||||
subAssets.Add( new SubAsset( monoScriptsInProject[j], true ) );
|
||||
currentSubAssets.Add( monoScriptsInProject[j] );
|
||||
string[] monoScriptGuids = AssetDatabase.FindAssets( "t:MonoScript" );
|
||||
monoScriptsInProject = new MonoScript[monoScriptGuids.Length];
|
||||
for( int k = 0; k < monoScriptGuids.Length; k++ )
|
||||
monoScriptsInProject[k] = AssetDatabase.LoadAssetAtPath<MonoScript>( AssetDatabase.GUIDToAssetPath( monoScriptGuids[k] ) );
|
||||
}
|
||||
|
||||
// Add any MonoScript objects that extend this MonoScript as a sub-asset
|
||||
for( int j = 0; j < monoScriptsInProject.Length; j++ )
|
||||
{
|
||||
Type otherMonoScriptType = monoScriptsInProject[j].GetClass();
|
||||
if( otherMonoScriptType == null || monoScriptType == otherMonoScriptType || !monoScriptType.IsAssignableFrom( otherMonoScriptType ) )
|
||||
continue;
|
||||
|
||||
if( !currentSubAssets.Contains( monoScriptsInProject[j] ) )
|
||||
{
|
||||
subAssets.Add( new SubAsset( monoScriptsInProject[j], shouldSearchChildren ?? true ) );
|
||||
currentSubAssets.Add( monoScriptsInProject[j] );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,42 +1,70 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
#if UNITY_2018_1_OR_NEWER
|
||||
using Unity.Collections;
|
||||
#endif
|
||||
using UnityEditor;
|
||||
using UnityEditor.SceneManagement;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
using Object = UnityEngine.Object;
|
||||
#if UNITY_2018_3_OR_NEWER
|
||||
using PrefabStage = UnityEditor.Experimental.SceneManagement.PrefabStage;
|
||||
using PrefabStageUtility = UnityEditor.Experimental.SceneManagement.PrefabStageUtility;
|
||||
#endif
|
||||
|
||||
namespace AssetUsageDetectorNamespace.Extras
|
||||
namespace AssetUsageDetectorNamespace
|
||||
{
|
||||
public static class Utilities
|
||||
{
|
||||
// A set of commonly used Unity types
|
||||
private static readonly HashSet<Type> primitiveUnityTypes = new HashSet<Type>() {
|
||||
typeof( string ), typeof( Vector4 ), typeof( Vector3 ), typeof( Vector2 ), typeof( Rect ),
|
||||
typeof( Quaternion ), typeof( Color ), typeof( Color32 ), typeof( LayerMask ),
|
||||
typeof( Matrix4x4 ), typeof( AnimationCurve ), typeof( Gradient ), typeof( RectOffset ),
|
||||
typeof( bool[] ), typeof( byte[] ), typeof( sbyte[] ), typeof( char[] ), typeof( decimal[] ),
|
||||
typeof( double[] ), typeof( float[] ), typeof( int[] ), typeof( uint[] ), typeof( long[] ),
|
||||
typeof( ulong[] ), typeof( short[] ), typeof( ushort[] ), typeof( string[] ),
|
||||
typeof( Vector4[] ), typeof( Vector3[] ), typeof( Vector2[] ), typeof( Rect[] ),
|
||||
typeof( Quaternion[] ), typeof( Color[] ), typeof( Color32[] ), typeof( LayerMask[] ),
|
||||
typeof( Matrix4x4[] ), typeof( AnimationCurve[] ), typeof( Gradient[] ), typeof( RectOffset[] ),
|
||||
typeof( List<bool> ), typeof( List<byte> ), typeof( List<sbyte> ), typeof( List<char> ), typeof( List<decimal> ),
|
||||
typeof( List<double> ), typeof( List<float> ), typeof( List<int> ), typeof( List<uint> ), typeof( List<long> ),
|
||||
typeof( List<ulong> ), typeof( List<short> ), typeof( List<ushort> ), typeof( List<string> ),
|
||||
typeof( List<Vector4> ), typeof( List<Vector3> ), typeof( List<Vector2> ), typeof( List<Rect> ),
|
||||
typeof( List<Quaternion> ), typeof( List<Color> ), typeof( List<Color32> ), typeof( List<LayerMask> ),
|
||||
typeof( List<Matrix4x4> ), typeof( List<AnimationCurve> ), typeof( List<Gradient> ), typeof( List<RectOffset> )
|
||||
private static readonly HashSet<Type> primitiveUnityTypes = new HashSet<Type>()
|
||||
{
|
||||
typeof( string ), typeof( Vector4 ), typeof( Vector3 ), typeof( Vector2 ), typeof( Rect ),
|
||||
typeof( Quaternion ), typeof( Color ), typeof( Color32 ), typeof( LayerMask ), typeof( Bounds ),
|
||||
typeof( Matrix4x4 ), typeof( AnimationCurve ), typeof( Gradient ), typeof( RectOffset ),
|
||||
typeof( bool[] ), typeof( byte[] ), typeof( sbyte[] ), typeof( char[] ), typeof( decimal[] ),
|
||||
typeof( double[] ), typeof( float[] ), typeof( int[] ), typeof( uint[] ), typeof( long[] ),
|
||||
typeof( ulong[] ), typeof( short[] ), typeof( ushort[] ), typeof( string[] ),
|
||||
typeof( Vector4[] ), typeof( Vector3[] ), typeof( Vector2[] ), typeof( Rect[] ),
|
||||
typeof( Quaternion[] ), typeof( Color[] ), typeof( Color32[] ), typeof( LayerMask[] ), typeof( Bounds[] ),
|
||||
typeof( Matrix4x4[] ), typeof( AnimationCurve[] ), typeof( Gradient[] ), typeof( RectOffset[] ),
|
||||
typeof( List<bool> ), typeof( List<byte> ), typeof( List<sbyte> ), typeof( List<char> ), typeof( List<decimal> ),
|
||||
typeof( List<double> ), typeof( List<float> ), typeof( List<int> ), typeof( List<uint> ), typeof( List<long> ),
|
||||
typeof( List<ulong> ), typeof( List<short> ), typeof( List<ushort> ), typeof( List<string> ),
|
||||
typeof( List<Vector4> ), typeof( List<Vector3> ), typeof( List<Vector2> ), typeof( List<Rect> ),
|
||||
typeof( List<Quaternion> ), typeof( List<Color> ), typeof( List<Color32> ), typeof( List<LayerMask> ), typeof( List<Bounds> ),
|
||||
typeof( List<Matrix4x4> ), typeof( List<AnimationCurve> ), typeof( List<Gradient> ), typeof( List<RectOffset> ),
|
||||
#if UNITY_2017_2_OR_NEWER
|
||||
typeof( Vector3Int ), typeof( Vector2Int ), typeof( RectInt ), typeof( BoundsInt ),
|
||||
typeof( Vector3Int[] ), typeof( Vector2Int[] ), typeof( RectInt[] ), typeof( BoundsInt[] ),
|
||||
typeof( List<Vector3Int> ), typeof( List<Vector2Int> ), typeof( List<RectInt> ), typeof( List<BoundsInt> )
|
||||
#endif
|
||||
};
|
||||
|
||||
private static readonly string reflectionNamespace = typeof( Assembly ).Namespace;
|
||||
#if UNITY_2018_1_OR_NEWER
|
||||
private static readonly string nativeCollectionsNamespace = typeof( NativeArray<int> ).Namespace;
|
||||
#endif
|
||||
|
||||
private static readonly HashSet<string> folderContentsSet = new HashSet<string>();
|
||||
|
||||
private static readonly StringBuilder stringBuilder = new StringBuilder( 10 );
|
||||
|
||||
#if UNITY_2018_3_OR_NEWER
|
||||
private static int previousPingedPrefabInstanceId;
|
||||
private static double previousPingedPrefabPingTime;
|
||||
#endif
|
||||
|
||||
public static readonly GUILayoutOption GL_EXPAND_WIDTH = GUILayout.ExpandWidth( true );
|
||||
public static readonly GUILayoutOption GL_EXPAND_HEIGHT = GUILayout.ExpandHeight( true );
|
||||
public static readonly GUILayoutOption GL_WIDTH_25 = GUILayout.Width( 25 );
|
||||
public static readonly GUILayoutOption GL_WIDTH_100 = GUILayout.Width( 100 );
|
||||
public static readonly GUILayoutOption GL_WIDTH_250 = GUILayout.Width( 250 );
|
||||
public static readonly GUILayoutOption GL_HEIGHT_0 = GUILayout.Height( 0 );
|
||||
public static readonly GUILayoutOption GL_HEIGHT_2 = GUILayout.Height( 2 );
|
||||
public static readonly GUILayoutOption GL_HEIGHT_30 = GUILayout.Height( 30 );
|
||||
public static readonly GUILayoutOption GL_HEIGHT_35 = GUILayout.Height( 35 );
|
||||
public static readonly GUILayoutOption GL_HEIGHT_40 = GUILayout.Height( 40 );
|
||||
@@ -53,6 +81,18 @@ namespace AssetUsageDetectorNamespace.Extras
|
||||
alignment = TextAnchor.MiddleCenter,
|
||||
font = EditorStyles.label.font
|
||||
};
|
||||
|
||||
Color textColor = GUI.skin.button.normal.textColor;
|
||||
m_boxGUIStyle.normal.textColor = textColor;
|
||||
m_boxGUIStyle.hover.textColor = textColor;
|
||||
m_boxGUIStyle.focused.textColor = textColor;
|
||||
m_boxGUIStyle.active.textColor = textColor;
|
||||
|
||||
#if !UNITY_2019_1_OR_NEWER || UNITY_2019_3_OR_NEWER
|
||||
// On 2019.1 and 2019.2 versions, GUI.skin.button.fontSize returns 0 on some devices
|
||||
// https://forum.unity.com/threads/asset-usage-detector-find-references-to-an-asset-object-open-source.408134/page-3#post-7285954
|
||||
m_boxGUIStyle.fontSize = ( m_boxGUIStyle.fontSize + GUI.skin.button.fontSize ) / 2;
|
||||
#endif
|
||||
}
|
||||
|
||||
return m_boxGUIStyle;
|
||||
@@ -79,12 +119,13 @@ namespace AssetUsageDetectorNamespace.Extras
|
||||
normalState = m_tooltipGUIStyle.normal;
|
||||
|
||||
normalState.background = null;
|
||||
normalState.scaledBackgrounds = new Texture2D[0];
|
||||
normalState.textColor = Color.black;
|
||||
}
|
||||
|
||||
if( normalState.background == null || normalState.background.Equals( null ) )
|
||||
{
|
||||
Texture2D backgroundTexture = new Texture2D( 1, 1 );
|
||||
Texture2D backgroundTexture = new Texture2D( 1, 1 ) { hideFlags = HideFlags.HideAndDontSave };
|
||||
backgroundTexture.SetPixel( 0, 0, new Color( 0.88f, 0.88f, 0.88f, 0.85f ) );
|
||||
backgroundTexture.Apply();
|
||||
|
||||
@@ -142,9 +183,9 @@ namespace AssetUsageDetectorNamespace.Extras
|
||||
|
||||
Event e = Event.current;
|
||||
|
||||
// If CTRL key is pressed, do a multi-select;
|
||||
// If CTRL or Shift keys are pressed, do a multi-select;
|
||||
// otherwise select only the clicked object and ping it in editor
|
||||
if( !e.control )
|
||||
if( !e.control && !e.shift )
|
||||
Selection.activeObject = obj.PingInEditor();
|
||||
else
|
||||
{
|
||||
@@ -210,24 +251,35 @@ namespace AssetUsageDetectorNamespace.Extras
|
||||
if( prefabAssetType == PrefabAssetType.Regular || prefabAssetType == PrefabAssetType.Variant )
|
||||
{
|
||||
string assetPath = AssetDatabase.GetAssetPath( objTR.gameObject );
|
||||
var openPrefabStage = UnityEditor.Experimental.SceneManagement.PrefabStageUtility.GetCurrentPrefabStage();
|
||||
if( openPrefabStage != null && openPrefabStage.stageHandle.IsValid() && assetPath == openPrefabStage.prefabAssetPath )
|
||||
PrefabStage openPrefabStage = PrefabStageUtility.GetCurrentPrefabStage();
|
||||
|
||||
// Try to open the prefab stage of pinged prefabs if they are double clicked
|
||||
if( previousPingedPrefabInstanceId == objTR.GetInstanceID() && EditorApplication.timeSinceStartup - previousPingedPrefabPingTime <= 0.3f &&
|
||||
#if UNITY_2020_1_OR_NEWER
|
||||
( openPrefabStage == null || !openPrefabStage.stageHandle.IsValid() || assetPath != openPrefabStage.assetPath ) )
|
||||
#else
|
||||
( openPrefabStage == null || !openPrefabStage.stageHandle.IsValid() || assetPath != openPrefabStage.prefabAssetPath ) )
|
||||
#endif
|
||||
{
|
||||
// Ping the object in prefab stage
|
||||
Transform targetParent = objTR;
|
||||
Transform selectedObject = ( (GameObject) obj ).transform;
|
||||
objTR = openPrefabStage.prefabContentsRoot.transform;
|
||||
while( targetParent != selectedObject )
|
||||
AssetDatabase.OpenAsset( objTR.gameObject );
|
||||
openPrefabStage = PrefabStageUtility.GetCurrentPrefabStage();
|
||||
}
|
||||
|
||||
previousPingedPrefabInstanceId = objTR.GetInstanceID();
|
||||
previousPingedPrefabPingTime = EditorApplication.timeSinceStartup;
|
||||
|
||||
#if UNITY_2020_1_OR_NEWER
|
||||
if( openPrefabStage != null && openPrefabStage.stageHandle.IsValid() && assetPath == openPrefabStage.assetPath )
|
||||
#else
|
||||
if( openPrefabStage != null && openPrefabStage.stageHandle.IsValid() && assetPath == openPrefabStage.prefabAssetPath )
|
||||
#endif
|
||||
{
|
||||
GameObject prefabStageGO = FollowSymmetricHierarchy( (GameObject) obj, ( (GameObject) obj ).transform.root.gameObject, openPrefabStage.prefabContentsRoot );
|
||||
if( prefabStageGO != null )
|
||||
{
|
||||
Transform temp = selectedObject;
|
||||
while( temp.parent != targetParent )
|
||||
temp = temp.parent;
|
||||
|
||||
objTR = objTR.GetChild( temp.GetSiblingIndex() );
|
||||
targetParent = temp;
|
||||
objTR = prefabStageGO.transform;
|
||||
selection = objTR.gameObject;
|
||||
}
|
||||
|
||||
selection = objTR.gameObject;
|
||||
}
|
||||
#if UNITY_2019_1_OR_NEWER
|
||||
else if( obj != objTR.gameObject )
|
||||
@@ -253,12 +305,54 @@ namespace AssetUsageDetectorNamespace.Extras
|
||||
return selection;
|
||||
}
|
||||
|
||||
// We are passing "go"s root Transform to thisRoot parameter. If we use go.transform.root instead, when we are in prefab mode on
|
||||
// newer Unity versions, it points to the preview scene at the root of the prefab stage instead of pointing to the actual root of "go"
|
||||
public static GameObject FollowSymmetricHierarchy( this GameObject go, GameObject thisRoot, GameObject symmetricRoot )
|
||||
{
|
||||
Transform target = go.transform;
|
||||
Transform root1 = thisRoot.transform;
|
||||
Transform root2 = symmetricRoot.transform;
|
||||
while( root1 != target )
|
||||
{
|
||||
Transform temp = target;
|
||||
while( temp.parent != root1 )
|
||||
temp = temp.parent;
|
||||
|
||||
Transform newRoot2;
|
||||
int siblingIndex = temp.GetSiblingIndex();
|
||||
if( siblingIndex < root2.childCount )
|
||||
{
|
||||
newRoot2 = root2.GetChild( siblingIndex );
|
||||
if( newRoot2.name != temp.name )
|
||||
newRoot2 = root2.Find( temp.name );
|
||||
}
|
||||
else
|
||||
newRoot2 = root2.Find( temp.name );
|
||||
|
||||
if( newRoot2 == null )
|
||||
return null;
|
||||
|
||||
root2 = newRoot2;
|
||||
root1 = temp;
|
||||
}
|
||||
|
||||
return root2.gameObject;
|
||||
}
|
||||
|
||||
// Check if the field is serializable
|
||||
public static bool IsSerializable( this FieldInfo fieldInfo )
|
||||
{
|
||||
// see Serialization Rules: https://docs.unity3d.com/Manual/script-Serialization.html
|
||||
if( fieldInfo.IsInitOnly || ( ( !fieldInfo.IsPublic || fieldInfo.IsNotSerialized ) &&
|
||||
!Attribute.IsDefined( fieldInfo, typeof( SerializeField ) ) ) )
|
||||
// See Serialization Rules: https://docs.unity3d.com/Manual/script-Serialization.html
|
||||
if( fieldInfo.IsInitOnly )
|
||||
return false;
|
||||
|
||||
#if UNITY_2019_3_OR_NEWER
|
||||
// SerializeReference makes even System.Object fields serializable
|
||||
if( Attribute.IsDefined( fieldInfo, typeof( SerializeReference ) ) )
|
||||
return true;
|
||||
#endif
|
||||
|
||||
if( ( !fieldInfo.IsPublic || fieldInfo.IsNotSerialized ) && !Attribute.IsDefined( fieldInfo, typeof( SerializeField ) ) )
|
||||
return false;
|
||||
|
||||
return IsTypeSerializable( fieldInfo.FieldType );
|
||||
@@ -289,6 +383,16 @@ namespace AssetUsageDetectorNamespace.Extras
|
||||
}
|
||||
else if( type.IsGenericType )
|
||||
{
|
||||
// Generic types are allowed on 2020.1 and later
|
||||
#if UNITY_2020_1_OR_NEWER
|
||||
if( type.GetGenericTypeDefinition() == typeof( List<> ) )
|
||||
{
|
||||
type = type.GetGenericArguments()[0];
|
||||
|
||||
if( typeof( Object ).IsAssignableFrom( type ) )
|
||||
return true;
|
||||
}
|
||||
#else
|
||||
if( type.GetGenericTypeDefinition() != typeof( List<> ) )
|
||||
return false;
|
||||
|
||||
@@ -296,25 +400,38 @@ namespace AssetUsageDetectorNamespace.Extras
|
||||
|
||||
if( typeof( Object ).IsAssignableFrom( type ) )
|
||||
return true;
|
||||
#endif
|
||||
}
|
||||
|
||||
#if !UNITY_2020_1_OR_NEWER
|
||||
if( type.IsGenericType )
|
||||
return false;
|
||||
#endif
|
||||
|
||||
return Attribute.IsDefined( type, typeof( SerializableAttribute ), false );
|
||||
}
|
||||
|
||||
// Check if the type is a common Unity type (let's call them primitives)
|
||||
public static bool IsPrimitiveUnityType( this Type type )
|
||||
// Check if instances of this type should be searched for references
|
||||
public static bool IsIgnoredUnityType( this Type type )
|
||||
{
|
||||
return type.IsPrimitive || primitiveUnityTypes.Contains( type ) || type.IsEnum;
|
||||
}
|
||||
if( type.IsPrimitive || primitiveUnityTypes.Contains( type ) || type.IsEnum )
|
||||
return true;
|
||||
|
||||
// Check if property has override keyword
|
||||
public static bool IsOverridden( this PropertyInfo propertyInfo )
|
||||
{
|
||||
MethodInfo mi = propertyInfo.GetGetMethod( true );
|
||||
return mi.GetBaseDefinition().DeclaringType != mi.DeclaringType;
|
||||
#if UNITY_2018_1_OR_NEWER
|
||||
// Searching NativeArrays for reference can throw InvalidOperationException if the collection is disposed
|
||||
if( type.Namespace == nativeCollectionsNamespace )
|
||||
return true;
|
||||
#endif
|
||||
|
||||
// Searching assembly variables for reference throws InvalidCastException on .NET 4.0 runtime
|
||||
if( typeof( Type ).IsAssignableFrom( type ) || type.Namespace == reflectionNamespace )
|
||||
return true;
|
||||
|
||||
// Searching pointers or ref variables for reference throws ArgumentException
|
||||
if( type.IsPointer || type.IsByRef )
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// Get <get> function for a field
|
||||
@@ -339,22 +456,25 @@ namespace AssetUsageDetectorNamespace.Extras
|
||||
// Get <get> function for a property
|
||||
public static VariableGetVal CreateGetter( this PropertyInfo propertyInfo )
|
||||
{
|
||||
// Ignore indexer properties
|
||||
if( propertyInfo.GetIndexParameters().Length > 0 )
|
||||
return null;
|
||||
|
||||
// Can't use PropertyWrapper (which uses CreateDelegate) for property getters of structs
|
||||
if( propertyInfo.DeclaringType.IsValueType )
|
||||
return propertyInfo.CanRead ? ( ( obj ) => propertyInfo.GetValue( obj, null ) ) : (VariableGetVal) null;
|
||||
|
||||
MethodInfo mi = propertyInfo.GetGetMethod( true );
|
||||
if( mi != null )
|
||||
{
|
||||
Type GenType = typeof( PropertyWrapper<,> ).MakeGenericType( propertyInfo.DeclaringType, propertyInfo.PropertyType );
|
||||
return ( (IPropertyAccessor) Activator.CreateInstance( GenType, mi ) ).GetValue;
|
||||
return !propertyInfo.CanRead ? (VariableGetVal) null : ( obj ) =>
|
||||
{
|
||||
try
|
||||
{
|
||||
return propertyInfo.GetValue( obj, null );
|
||||
}
|
||||
catch
|
||||
{
|
||||
// Property getters may return various kinds of exceptions if their backing fields are not initialized (yet)
|
||||
return null;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
return null;
|
||||
Type GenType = typeof( PropertyWrapper<,> ).MakeGenericType( propertyInfo.DeclaringType, propertyInfo.PropertyType );
|
||||
return ( (IPropertyAccessor) Activator.CreateInstance( GenType, propertyInfo.GetGetMethod( true ) ) ).GetValue;
|
||||
}
|
||||
|
||||
// Check if all open scenes are saved (not dirty)
|
||||
@@ -370,6 +490,34 @@ namespace AssetUsageDetectorNamespace.Extras
|
||||
return true;
|
||||
}
|
||||
|
||||
// Returns file extension in lowercase (period not included)
|
||||
public static string GetFileExtension( string path )
|
||||
{
|
||||
int extensionIndex = path.LastIndexOf( '.' );
|
||||
if( extensionIndex < 0 || extensionIndex >= path.Length - 1 )
|
||||
return "";
|
||||
|
||||
stringBuilder.Length = 0;
|
||||
for( extensionIndex++; extensionIndex < path.Length; extensionIndex++ )
|
||||
{
|
||||
char ch = path[extensionIndex];
|
||||
if( ch >= 65 && ch <= 90 ) // A-Z
|
||||
ch += (char) 32; // Converted to a-z
|
||||
|
||||
stringBuilder.Append( ch );
|
||||
}
|
||||
|
||||
return stringBuilder.ToString();
|
||||
}
|
||||
|
||||
// Draw horizontal line inside OnGUI
|
||||
public static void DrawSeparatorLine()
|
||||
{
|
||||
GUILayout.Space( 4 );
|
||||
GUILayout.Box( "", GL_HEIGHT_2, GL_EXPAND_WIDTH );
|
||||
GUILayout.Space( 4 );
|
||||
}
|
||||
|
||||
// Check if all the objects inside the list are null
|
||||
public static bool IsEmpty( this List<ObjectToSearch> objectsToSearch )
|
||||
{
|
||||
@@ -418,6 +566,35 @@ namespace AssetUsageDetectorNamespace.Extras
|
||||
return true;
|
||||
}
|
||||
|
||||
// Returns true is str starts with prefix
|
||||
public static bool StartsWithFast( this string str, string prefix )
|
||||
{
|
||||
int aLen = str.Length;
|
||||
int bLen = prefix.Length;
|
||||
int ap = 0; int bp = 0;
|
||||
while( ap < aLen && bp < bLen && str[ap] == prefix[bp] )
|
||||
{
|
||||
ap++;
|
||||
bp++;
|
||||
}
|
||||
|
||||
return bp == bLen;
|
||||
}
|
||||
|
||||
// Returns true is str ends with postfix
|
||||
public static bool EndsWithFast( this string str, string postfix )
|
||||
{
|
||||
int ap = str.Length - 1;
|
||||
int bp = postfix.Length - 1;
|
||||
while( ap >= 0 && bp >= 0 && str[ap] == postfix[bp] )
|
||||
{
|
||||
ap--;
|
||||
bp--;
|
||||
}
|
||||
|
||||
return bp < 0;
|
||||
}
|
||||
|
||||
public static bool ContainsFast<T>( this List<T> list, T element )
|
||||
{
|
||||
if( !( element is ValueType ) )
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
using System;
|
||||
using System.Reflection;
|
||||
using UnityEngine;
|
||||
|
||||
namespace AssetUsageDetectorNamespace.Extras
|
||||
namespace AssetUsageDetectorNamespace
|
||||
{
|
||||
// Delegate to get the value of a variable (either field or property)
|
||||
public delegate object VariableGetVal( object obj );
|
||||
@@ -32,7 +33,15 @@ namespace AssetUsageDetectorNamespace.Extras
|
||||
|
||||
public object Get( object obj )
|
||||
{
|
||||
return getter( obj );
|
||||
try
|
||||
{
|
||||
return getter( obj );
|
||||
}
|
||||
catch( Exception e )
|
||||
{
|
||||
Debug.LogException( e );
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -60,8 +69,7 @@ namespace AssetUsageDetectorNamespace.Extras
|
||||
}
|
||||
catch
|
||||
{
|
||||
// Property getters may return various kinds of exceptions
|
||||
// if their backing fields are not initialized (yet)
|
||||
// Property getters may return various kinds of exceptions if their backing fields are not initialized (yet)
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,13 +3,12 @@
|
||||
Online documentation available at: https://github.com/yasirkula/UnityAssetUsageDetector
|
||||
E-mail: yasirkula@gmail.com
|
||||
|
||||
1. ABOUT
|
||||
### ABOUT
|
||||
This tool helps you find usages of the selected asset(s) and/or Object(s) in your Unity project, i.e. lists the objects that refer to them.
|
||||
|
||||
2. HOW TO
|
||||
Open "Window-Asset Usage Detector" window, configure the settings and hit GO! You can also use the "Assets-Search For References" shortcut to find the selected object(s)' references.
|
||||
### HOW TO
|
||||
Open "Window-Asset Usage Detector" window, configure the settings and hit GO! You can also right click an object and select "Search For References".
|
||||
|
||||
3. KNOWN LIMITATIONS
|
||||
- static variables are not searched
|
||||
- GUIText materials are not searched
|
||||
- Textures in Lens Flare's can not be searched
|
||||
In the search results page, each row represents a reference to the searched Object(s). Rows can be traversed from left to right to see how the
|
||||
references are formed. If a node's label contains text inside square brackets (e.g. [Child object]), then that text describes how that node is
|
||||
connected to the node to its left.
|
||||
@@ -1,34 +0,0 @@
|
||||
# Asset Usage Detector for Unity 3D
|
||||
|
||||

|
||||
|
||||
**Available on Asset Store:** https://www.assetstore.unity3d.com/en/#!/content/112837
|
||||
|
||||
**Forum Thread:** https://forum.unity.com/threads/asset-usage-detector-find-references-to-an-asset-object-open-source.408134/
|
||||
|
||||
### A. ABOUT
|
||||
|
||||
This editor extension helps you figure out at which places an asset or GameObject is used, i.e. lists the objects that refer to the asset. It is possible to search for references in the Assets folder (Project view) and/or in the scene(s) of your project. You can also search for references while in Play mode!
|
||||
|
||||
### B. HOW TO USE
|
||||
|
||||
- Import [AssetUsageDetector.unitypackage](https://github.com/yasirkula/UnityAssetUsageDetector/releases) to your project
|
||||
- Open **Window - Asset Usage Detector** window, configure the settings and hit **GO!**
|
||||
- or, use the **Assets - Search For References** shortcut to find the selected object(s)' references
|
||||
|
||||
**NOTE:** If your project uses an older version of AssetUsageDetector, delete the older version before updating the plugin.
|
||||
|
||||
### C. FEATURES
|
||||
|
||||
- You can search for references of any object that extends *UnityEngine.Object*
|
||||
- Seaches every corner of your project with its *reflection* based search algorithm (even non-Unity objects, structs and data types like dictionaries are searched)
|
||||
- Can search in multiple scenes at once
|
||||
- Can show complete paths to the references or only the most relevant parts of the paths (see the demonstration below)
|
||||
|
||||

|
||||
|
||||
### D. KNOWN LIMITATIONS
|
||||
|
||||
- *static* variables are not searched
|
||||
- GUIText materials are not searched
|
||||
- Textures in Lens Flare's can not be searched
|
||||
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"name": "com.yasirkula.assetusagedetector",
|
||||
"displayName": "Asset Usage Detector",
|
||||
"version": "2.0.0",
|
||||
"documentationUrl": "https://github.com/yasirkula/UnityAssetUsageDetector",
|
||||
"changelogUrl": "https://github.com/yasirkula/UnityAssetUsageDetector/releases",
|
||||
"licensesUrl": "https://github.com/yasirkula/UnityAssetUsageDetector/blob/master/LICENSE.txt",
|
||||
"description": "This editor extension helps you figure out at which places an asset or GameObject is used, i.e. lists the objects that refer to the asset. It is possible to search for references in the Assets folder (Project view) and/or in the scene(s) of your project. You can also search for references while in Play mode!"
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ce102123c0ff0a6429f8d5f930e77d96
|
||||
PackageManifestImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 51 KiB |
Reference in New Issue
Block a user