mirror of
https://github.com/yasirkula/UnityAssetUsageDetector.git
synced 2026-11-20 23:12:38 +08:00
Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| a29dc59a75 | |||
| 96315ec435 | |||
| 12ed06d43c | |||
| 69ce197932 | |||
| e3dc45b917 |
@@ -12,6 +12,7 @@ using System.Reflection;
|
|||||||
using System;
|
using System;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using UnityEngine.UI;
|
using UnityEngine.UI;
|
||||||
|
using System.Text;
|
||||||
#if UNITY_2017_1_OR_NEWER
|
#if UNITY_2017_1_OR_NEWER
|
||||||
using UnityEngine.U2D;
|
using UnityEngine.U2D;
|
||||||
#if UNITY_2018_2_OR_NEWER
|
#if UNITY_2018_2_OR_NEWER
|
||||||
@@ -33,40 +34,27 @@ namespace AssetUsageDetectorNamespace
|
|||||||
public class AssetUsageDetector
|
public class AssetUsageDetector
|
||||||
{
|
{
|
||||||
#region Helper Classes
|
#region Helper Classes
|
||||||
|
[Serializable]
|
||||||
public class Parameters
|
public class Parameters
|
||||||
{
|
{
|
||||||
public IEnumerable<Object> objectsToSearch;
|
public Object[] objectsToSearch = null;
|
||||||
|
|
||||||
public SceneSearchMode searchInScenes;
|
public SceneSearchMode searchInScenes = SceneSearchMode.AllScenes;
|
||||||
public bool searchInAssetsFolder;
|
public Object[] searchInScenesSubset = null;
|
||||||
public IEnumerable<Object> searchInAssetsSubset;
|
public bool searchInAssetsFolder = true;
|
||||||
public IEnumerable<Object> excludedAssetsFromSearch;
|
public Object[] searchInAssetsSubset = null;
|
||||||
public bool dontSearchInSourceAssets;
|
public Object[] excludedAssetsFromSearch = null;
|
||||||
public IEnumerable<Object> excludedScenesFromSearch;
|
public bool dontSearchInSourceAssets = true;
|
||||||
|
public Object[] excludedScenesFromSearch = null;
|
||||||
|
|
||||||
public int searchDepthLimit;
|
public int searchDepthLimit = 4;
|
||||||
public BindingFlags fieldModifiers, propertyModifiers;
|
public BindingFlags fieldModifiers = BindingFlags.Public | BindingFlags.NonPublic;
|
||||||
|
public BindingFlags propertyModifiers = BindingFlags.Public | BindingFlags.NonPublic;
|
||||||
|
public bool searchNonSerializableVariables = true;
|
||||||
|
|
||||||
public bool searchNonSerializableVariables;
|
public bool lazySceneSearch = false;
|
||||||
public bool noAssetDatabaseChanges;
|
public bool noAssetDatabaseChanges = false;
|
||||||
public bool showProgressBar;
|
public bool showDetailedProgressBar = false;
|
||||||
|
|
||||||
public Parameters()
|
|
||||||
{
|
|
||||||
objectsToSearch = null;
|
|
||||||
searchInScenes = SceneSearchMode.AllScenes;
|
|
||||||
searchInAssetsFolder = true;
|
|
||||||
searchInAssetsSubset = null;
|
|
||||||
excludedAssetsFromSearch = null;
|
|
||||||
dontSearchInSourceAssets = false;
|
|
||||||
excludedScenesFromSearch = null;
|
|
||||||
searchDepthLimit = 4;
|
|
||||||
fieldModifiers = BindingFlags.Public | BindingFlags.NonPublic;
|
|
||||||
propertyModifiers = BindingFlags.Public | BindingFlags.NonPublic;
|
|
||||||
searchNonSerializableVariables = true;
|
|
||||||
noAssetDatabaseChanges = false;
|
|
||||||
showProgressBar = false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private class CacheEntry
|
private class CacheEntry
|
||||||
@@ -111,28 +99,44 @@ namespace AssetUsageDetectorNamespace
|
|||||||
fileSizes = new long[dependencies.Length];
|
fileSizes = new long[dependencies.Length];
|
||||||
|
|
||||||
for( int i = 0; i < dependencies.Length; i++ )
|
for( int i = 0; i < dependencies.Length; i++ )
|
||||||
fileSizes[i] = new FileInfo( dependencies[i] ).Length;
|
{
|
||||||
|
FileInfo assetFile = new FileInfo( dependencies[i] );
|
||||||
|
fileSizes[i] = assetFile.Exists ? assetFile.Length : 0L;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
private HashSet<Object> objectsToSearchSet; // A set that contains the searched asset(s) and their sub-assets (if any)
|
// A set that contains the searched asset(s) and their sub-assets (if any)
|
||||||
|
private readonly HashSet<Object> objectsToSearchSet = new HashSet<Object>();
|
||||||
|
|
||||||
private HashSet<Object> sceneObjectsToSearchSet; // Scene object(s) in objectsToSearchSet
|
// Scene object(s) in objectsToSearchSet
|
||||||
private HashSet<string> sceneObjectsToSearchScenesSet; // sceneObjectsToSearchSet's scene(s)
|
private readonly HashSet<Object> sceneObjectsToSearchSet = new HashSet<Object>();
|
||||||
|
// sceneObjectsToSearchSet's scene(s)
|
||||||
|
private readonly HashSet<string> sceneObjectsToSearchScenesSet = new HashSet<string>();
|
||||||
|
|
||||||
private HashSet<Object> assetsToSearchSet; // Project asset(s) in objectsToSearchSet
|
// Project asset(s) in objectsToSearchSet
|
||||||
private HashSet<string> assetsToSearchPathsSet; // assetsToSearchSet's path(s)
|
private readonly HashSet<Object> assetsToSearchSet = new HashSet<Object>();
|
||||||
|
// assetsToSearchSet's path(s)
|
||||||
|
private readonly HashSet<string> assetsToSearchPathsSet = new HashSet<string>();
|
||||||
|
// The root prefab objects in assetsToSearch that will be used to search for prefab references
|
||||||
|
private readonly List<GameObject> assetsToSearchRootPrefabs = new List<GameObject>( 4 );
|
||||||
|
|
||||||
private SearchResultGroup currentSearchResultGroup; // Results for the currently searched scene
|
// Results for the currently searched scene
|
||||||
|
private SearchResultGroup currentSearchResultGroup;
|
||||||
|
|
||||||
private Dictionary<Type, VariableGetterHolder[]> typeToVariables; // An optimization to fetch & filter fields and properties of a class only once
|
// An optimization to fetch & filter fields and properties of a class only once
|
||||||
private Dictionary<string, ReferenceNode> searchedObjects; // An optimization to search an object only once (key is a hash of the searched object)
|
private readonly Dictionary<Type, VariableGetterHolder[]> typeToVariables = new Dictionary<Type, VariableGetterHolder[]>( 4096 );
|
||||||
private Dictionary<string, CacheEntry> assetDependencyCache; // An optimization to fetch the dependencies of an asset only once (key is the path of the asset)
|
// An optimization to search an object only once (key is a hash of the searched object)
|
||||||
|
private readonly Dictionary<string, ReferenceNode> searchedObjects = new Dictionary<string, ReferenceNode>( 32768 );
|
||||||
|
// An optimization to fetch the dependencies of an asset only once (key is the path of the asset)
|
||||||
|
private Dictionary<string, CacheEntry> assetDependencyCache;
|
||||||
|
|
||||||
private Dictionary<Type, Func<Object, ReferenceNode>> typeToSearchFunction; // Dictionary to quickly find the function to search a specific type with
|
// Dictionary to quickly find the function to search a specific type with
|
||||||
|
private Dictionary<Type, Func<Object, ReferenceNode>> typeToSearchFunction;
|
||||||
|
|
||||||
private List<object> callStack; // Stack of SearchObject function parameters to avoid infinite loops (which happens when same object is passed as parameter to function)
|
// Stack of SearchObject function parameters to avoid infinite loops (which happens when same object is passed as parameter to function)
|
||||||
|
private readonly List<object> callStack = new List<object>( 64 );
|
||||||
|
|
||||||
private bool searchPrefabConnections;
|
private bool searchPrefabConnections;
|
||||||
private bool searchMonoBehavioursForScript;
|
private bool searchMonoBehavioursForScript;
|
||||||
@@ -144,9 +148,17 @@ namespace AssetUsageDetectorNamespace
|
|||||||
|
|
||||||
private int searchDepthLimit; // Depth limit for recursively searching variables of objects
|
private int searchDepthLimit; // Depth limit for recursively searching variables of objects
|
||||||
|
|
||||||
private Object currentObject;
|
private Object currentSearchedObject;
|
||||||
private int currentDepth;
|
private int currentDepth;
|
||||||
|
|
||||||
|
private bool searchingSourceAssets;
|
||||||
|
private bool isInPlayMode;
|
||||||
|
|
||||||
|
#if UNITY_2018_3_OR_NEWER
|
||||||
|
private UnityEditor.Experimental.SceneManagement.PrefabStage openPrefabStage;
|
||||||
|
private GameObject openPrefabStagePrefabAsset;
|
||||||
|
#endif
|
||||||
|
|
||||||
private BindingFlags fieldModifiers, propertyModifiers;
|
private BindingFlags fieldModifiers, propertyModifiers;
|
||||||
private BindingFlags prevFieldModifiers, prevPropertyModifiers;
|
private BindingFlags prevFieldModifiers, prevPropertyModifiers;
|
||||||
|
|
||||||
@@ -163,16 +175,53 @@ namespace AssetUsageDetectorNamespace
|
|||||||
// Search for references!
|
// Search for references!
|
||||||
public SearchResult Run( Parameters searchParameters )
|
public SearchResult Run( Parameters searchParameters )
|
||||||
{
|
{
|
||||||
|
if( searchParameters == null )
|
||||||
|
{
|
||||||
|
Debug.LogError( "searchParameters must not be null!" );
|
||||||
|
return new SearchResult( false, null, null, this, searchParameters );
|
||||||
|
}
|
||||||
|
|
||||||
if( searchParameters.objectsToSearch == null )
|
if( searchParameters.objectsToSearch == null )
|
||||||
{
|
{
|
||||||
Debug.LogError( "objectsToSearch list is empty" );
|
Debug.LogError( "objectsToSearch list is empty!" );
|
||||||
return new SearchResult( false, null, null );
|
return new SearchResult( false, null, null, this, searchParameters );
|
||||||
|
}
|
||||||
|
|
||||||
|
if( !EditorApplication.isPlaying && !Utilities.AreScenesSaved() )
|
||||||
|
{
|
||||||
|
// Don't start the search if at least one scene is currently dirty (not saved)
|
||||||
|
Debug.LogError( "Save open scenes first!" );
|
||||||
|
return new SearchResult( false, null, null, this, searchParameters );
|
||||||
}
|
}
|
||||||
|
|
||||||
List<SearchResultGroup> searchResult = null;
|
List<SearchResultGroup> searchResult = null;
|
||||||
|
|
||||||
|
isInPlayMode = EditorApplication.isPlaying;
|
||||||
|
#if UNITY_2018_3_OR_NEWER
|
||||||
|
openPrefabStagePrefabAsset = null;
|
||||||
|
string openPrefabStageAssetPath = null;
|
||||||
|
openPrefabStage = UnityEditor.Experimental.SceneManagement.PrefabStageUtility.GetCurrentPrefabStage();
|
||||||
|
if( openPrefabStage != null )
|
||||||
|
{
|
||||||
|
if( !openPrefabStage.stageHandle.IsValid() )
|
||||||
|
openPrefabStage = null;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if( openPrefabStage.scene.isDirty )
|
||||||
|
{
|
||||||
|
// Don't start the search if a prefab stage is currently open and dirty (not saved)
|
||||||
|
Debug.LogError( "Save open prefabs first!" );
|
||||||
|
return new SearchResult( false, null, null, this, searchParameters );
|
||||||
|
}
|
||||||
|
|
||||||
|
openPrefabStagePrefabAsset = AssetDatabase.LoadAssetAtPath<GameObject>( openPrefabStage.prefabAssetPath );
|
||||||
|
openPrefabStageAssetPath = openPrefabStage.prefabAssetPath;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
// Get the scenes that are open right now
|
// Get the scenes that are open right now
|
||||||
SceneSetup[] initialSceneSetup = !EditorApplication.isPlaying ? EditorSceneManager.GetSceneManagerSetup() : null;
|
SceneSetup[] initialSceneSetup = !isInPlayMode ? EditorSceneManager.GetSceneManagerSetup() : null;
|
||||||
|
|
||||||
// Make sure the AssetDatabase is up-to-date
|
// Make sure the AssetDatabase is up-to-date
|
||||||
AssetDatabase.SaveAssets();
|
AssetDatabase.SaveAssets();
|
||||||
@@ -190,45 +239,17 @@ namespace AssetUsageDetectorNamespace
|
|||||||
// Initialize commonly used variables
|
// Initialize commonly used variables
|
||||||
searchResult = new List<SearchResultGroup>(); // Overall search results
|
searchResult = new List<SearchResultGroup>(); // Overall search results
|
||||||
|
|
||||||
if( typeToVariables == null )
|
if( prevFieldModifiers != fieldModifiers || prevPropertyModifiers != propertyModifiers )
|
||||||
typeToVariables = new Dictionary<Type, VariableGetterHolder[]>( 4096 );
|
|
||||||
else if( prevFieldModifiers != fieldModifiers || prevPropertyModifiers != propertyModifiers )
|
|
||||||
typeToVariables.Clear();
|
typeToVariables.Clear();
|
||||||
|
|
||||||
if( searchedObjects == null )
|
searchedObjects.Clear();
|
||||||
searchedObjects = new Dictionary<string, ReferenceNode>( 32768 );
|
callStack.Clear();
|
||||||
else
|
objectsToSearchSet.Clear();
|
||||||
searchedObjects.Clear();
|
sceneObjectsToSearchSet.Clear();
|
||||||
|
sceneObjectsToSearchScenesSet.Clear();
|
||||||
if( callStack == null )
|
assetsToSearchSet.Clear();
|
||||||
callStack = new List<object>( 64 );
|
assetsToSearchPathsSet.Clear();
|
||||||
else
|
assetsToSearchRootPrefabs.Clear();
|
||||||
callStack.Clear();
|
|
||||||
|
|
||||||
if( objectsToSearchSet == null )
|
|
||||||
objectsToSearchSet = new HashSet<Object>();
|
|
||||||
else
|
|
||||||
objectsToSearchSet.Clear();
|
|
||||||
|
|
||||||
if( sceneObjectsToSearchSet == null )
|
|
||||||
sceneObjectsToSearchSet = new HashSet<Object>();
|
|
||||||
else
|
|
||||||
sceneObjectsToSearchSet.Clear();
|
|
||||||
|
|
||||||
if( sceneObjectsToSearchScenesSet == null )
|
|
||||||
sceneObjectsToSearchScenesSet = new HashSet<string>();
|
|
||||||
else
|
|
||||||
sceneObjectsToSearchScenesSet.Clear();
|
|
||||||
|
|
||||||
if( assetsToSearchSet == null )
|
|
||||||
assetsToSearchSet = new HashSet<Object>();
|
|
||||||
else
|
|
||||||
assetsToSearchSet.Clear();
|
|
||||||
|
|
||||||
if( assetsToSearchPathsSet == null )
|
|
||||||
assetsToSearchPathsSet = new HashSet<string>();
|
|
||||||
else
|
|
||||||
assetsToSearchPathsSet.Clear();
|
|
||||||
|
|
||||||
if( assetDependencyCache == null )
|
if( assetDependencyCache == null )
|
||||||
{
|
{
|
||||||
@@ -283,7 +304,7 @@ namespace AssetUsageDetectorNamespace
|
|||||||
if( obj.IsFolder() )
|
if( obj.IsFolder() )
|
||||||
folderContentsSet.UnionWith( Utilities.EnumerateFolderContents( obj ) );
|
folderContentsSet.UnionWith( Utilities.EnumerateFolderContents( obj ) );
|
||||||
else
|
else
|
||||||
AddSearchedObjectToFilteredSets( obj );
|
AddSearchedObjectToFilteredSets( obj, true );
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach( string filePath in folderContentsSet )
|
foreach( string filePath in folderContentsSet )
|
||||||
@@ -297,7 +318,7 @@ namespace AssetUsageDetectorNamespace
|
|||||||
continue;
|
continue;
|
||||||
|
|
||||||
for( int i = 0; i < assets.Length; i++ )
|
for( int i = 0; i < assets.Length; i++ )
|
||||||
AddSearchedObjectToFilteredSets( assets[i] );
|
AddSearchedObjectToFilteredSets( assets[i], true );
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach( Object obj in objectsToSearchSet )
|
foreach( Object obj in objectsToSearchSet )
|
||||||
@@ -327,30 +348,36 @@ namespace AssetUsageDetectorNamespace
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Find the scenes to search for references
|
// Find the scenes to search for references
|
||||||
HashSet<string> openScenes = null;
|
HashSet<string> scenesToSearch = new HashSet<string>();
|
||||||
if( EditorApplication.isPlaying )
|
if( searchParameters.searchInScenesSubset != null )
|
||||||
{
|
{
|
||||||
// In Play mode, only open scenes can be searched
|
foreach( Object obj in searchParameters.searchInScenesSubset )
|
||||||
openScenes = new HashSet<string>();
|
|
||||||
for( int i = 0; i < EditorSceneManager.loadedSceneCount; i++ )
|
|
||||||
{
|
{
|
||||||
Scene scene = EditorSceneManager.GetSceneAt( i );
|
if( obj == null || obj.Equals( null ) )
|
||||||
if( scene.IsValid() )
|
continue;
|
||||||
openScenes.Add( scene.path );
|
|
||||||
|
if( !obj.IsAsset() )
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if( obj.IsFolder() )
|
||||||
|
{
|
||||||
|
string[] folderContents = AssetDatabase.FindAssets( "t:SceneAsset", new string[] { AssetDatabase.GetAssetPath( obj ) } );
|
||||||
|
if( folderContents == null )
|
||||||
|
continue;
|
||||||
|
|
||||||
|
for( int i = 0; i < folderContents.Length; i++ )
|
||||||
|
scenesToSearch.Add( AssetDatabase.GUIDToAssetPath( folderContents[i] ) );
|
||||||
|
}
|
||||||
|
else if( obj is SceneAsset )
|
||||||
|
scenesToSearch.Add( AssetDatabase.GetAssetPath( obj ) );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else if( ( searchParameters.searchInScenes & SceneSearchMode.AllScenes ) == SceneSearchMode.AllScenes )
|
||||||
HashSet<string> scenesToSearch = new HashSet<string>();
|
|
||||||
if( ( searchParameters.searchInScenes & SceneSearchMode.AllScenes ) == SceneSearchMode.AllScenes )
|
|
||||||
{
|
{
|
||||||
// Get all scenes from the Assets folder
|
// Get all scenes from the Assets folder
|
||||||
string[] sceneGuids = AssetDatabase.FindAssets( "t:SceneAsset" );
|
string[] sceneGuids = AssetDatabase.FindAssets( "t:SceneAsset" );
|
||||||
for( int i = 0; i < sceneGuids.Length; i++ )
|
for( int i = 0; i < sceneGuids.Length; i++ )
|
||||||
{
|
scenesToSearch.Add( AssetDatabase.GUIDToAssetPath( sceneGuids[i] ) );
|
||||||
string scenePath = AssetDatabase.GUIDToAssetPath( sceneGuids[i] );
|
|
||||||
if( !EditorApplication.isPlaying || openScenes.Contains( scenePath ) )
|
|
||||||
scenesToSearch.Add( scenePath );
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -372,44 +399,62 @@ namespace AssetUsageDetectorNamespace
|
|||||||
EditorBuildSettingsScene[] scenesTemp = EditorBuildSettings.scenes;
|
EditorBuildSettingsScene[] scenesTemp = EditorBuildSettings.scenes;
|
||||||
for( int i = 0; i < scenesTemp.Length; i++ )
|
for( int i = 0; i < scenesTemp.Length; i++ )
|
||||||
{
|
{
|
||||||
if( ( searchInScenesInBuildTickedAll || scenesTemp[i].enabled ) && ( !EditorApplication.isPlaying || openScenes.Contains( scenesTemp[i].path ) ) )
|
if( ( searchInScenesInBuildTickedAll || scenesTemp[i].enabled ) )
|
||||||
scenesToSearch.Add( scenesTemp[i].path );
|
scenesToSearch.Add( scenesTemp[i].path );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// In Play mode, only open scenes can be searched
|
||||||
|
if( isInPlayMode )
|
||||||
|
{
|
||||||
|
HashSet<string> openScenes = new HashSet<string>();
|
||||||
|
for( int i = 0; i < EditorSceneManager.loadedSceneCount; i++ )
|
||||||
|
{
|
||||||
|
Scene scene = EditorSceneManager.GetSceneAt( i );
|
||||||
|
if( scene.IsValid() )
|
||||||
|
openScenes.Add( scene.path );
|
||||||
|
}
|
||||||
|
|
||||||
|
scenesToSearch.RemoveWhere( ( path ) =>
|
||||||
|
{
|
||||||
|
if( !openScenes.Contains( path ) )
|
||||||
|
{
|
||||||
|
Debug.Log( "Can't search unloaded scenes while in play mode, skipped " + path );
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
} );
|
||||||
|
}
|
||||||
|
|
||||||
// By default, search only serializable variables for references
|
// By default, search only serializable variables for references
|
||||||
searchSerializableVariablesOnly = !searchParameters.searchNonSerializableVariables;
|
searchSerializableVariablesOnly = !searchParameters.searchNonSerializableVariables;
|
||||||
|
|
||||||
// Initialize the nodes of searched asset(s)
|
// Initialize the nodes of searched asset(s)
|
||||||
foreach( Object obj in objectsToSearchSet )
|
foreach( Object obj in objectsToSearchSet )
|
||||||
{
|
searchedObjects.Add( obj.Hash(), PopReferenceNode( obj ) );
|
||||||
BeginSearchObject( obj );
|
|
||||||
|
|
||||||
string objHash = obj.Hash();
|
|
||||||
ReferenceNode referenceNode;
|
|
||||||
if( !searchedObjects.TryGetValue( objHash, out referenceNode ) || referenceNode == null )
|
|
||||||
searchedObjects[objHash] = PopReferenceNode( obj );
|
|
||||||
}
|
|
||||||
|
|
||||||
// Progressbar values
|
// Progressbar values
|
||||||
int searchProgress = 0;
|
int searchProgress = 0;
|
||||||
int searchTotalProgress = scenesToSearch.Count;
|
int searchTotalProgress = scenesToSearch.Count;
|
||||||
if( EditorApplication.isPlaying )
|
if( isInPlayMode && searchParameters.searchInScenes != SceneSearchMode.None )
|
||||||
searchTotalProgress++; // DontDestroyOnLoad scene
|
searchTotalProgress++; // DontDestroyOnLoad scene
|
||||||
|
|
||||||
// Don't search assets if searched object(s) are all scene objects as assets can't hold references to scene objects
|
// Don't search assets if searched object(s) are all scene objects as assets can't hold references to scene objects
|
||||||
if( searchParameters.searchInAssetsFolder && assetsToSearchSet.Count > 0 )
|
if( searchParameters.searchInAssetsFolder && assetsToSearchSet.Count > 0 )
|
||||||
{
|
{
|
||||||
currentSearchResultGroup = new SearchResultGroup( "Project View (Assets)", false );
|
currentSearchResultGroup = new SearchResultGroup( "Project Window (Assets)", SearchResultGroup.GroupType.Assets );
|
||||||
|
|
||||||
// Get the paths of all assets that are to be searched
|
// Get the paths of all assets that are to be searched
|
||||||
IEnumerable<string> assetPaths;
|
IEnumerable<string> assetPaths;
|
||||||
if( searchParameters.searchInAssetsSubset == null )
|
if( searchParameters.searchInAssetsSubset == null )
|
||||||
{
|
{
|
||||||
string[] allAssetPaths = AssetDatabase.GetAllAssetPaths();
|
string[] allAssetPaths = AssetDatabase.GetAllAssetPaths();
|
||||||
searchTotalProgress += allAssetPaths.Length;
|
|
||||||
assetPaths = allAssetPaths;
|
assetPaths = allAssetPaths;
|
||||||
|
|
||||||
|
if( searchParameters.showDetailedProgressBar )
|
||||||
|
searchTotalProgress += allAssetPaths.Length;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -429,8 +474,10 @@ namespace AssetUsageDetectorNamespace
|
|||||||
folderContentsSet.Add( AssetDatabase.GetAssetPath( obj ) );
|
folderContentsSet.Add( AssetDatabase.GetAssetPath( obj ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
searchTotalProgress += folderContentsSet.Count;
|
|
||||||
assetPaths = folderContentsSet;
|
assetPaths = folderContentsSet;
|
||||||
|
|
||||||
|
if( searchParameters.showDetailedProgressBar )
|
||||||
|
searchTotalProgress += folderContentsSet.Count;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Calculate the path(s) of the assets that won't be searched for references
|
// Calculate the path(s) of the assets that won't be searched for references
|
||||||
@@ -455,9 +502,12 @@ namespace AssetUsageDetectorNamespace
|
|||||||
if( searchParameters.dontSearchInSourceAssets )
|
if( searchParameters.dontSearchInSourceAssets )
|
||||||
excludedAssetsPathsSet.UnionWith( assetsToSearchPathsSet );
|
excludedAssetsPathsSet.UnionWith( assetsToSearchPathsSet );
|
||||||
|
|
||||||
|
if( EditorUtility.DisplayCancelableProgressBar( "Please wait...", "Searching assets", 0f ) )
|
||||||
|
throw new Exception( "Search aborted" );
|
||||||
|
|
||||||
foreach( string path in assetPaths )
|
foreach( string path in assetPaths )
|
||||||
{
|
{
|
||||||
if( searchParameters.showProgressBar && ++searchProgress % 30 == 1 && EditorUtility.DisplayCancelableProgressBar( "Please wait...", "Searching assets", (float) searchProgress / searchTotalProgress ) )
|
if( searchParameters.showDetailedProgressBar && ++searchProgress % 30 == 1 && EditorUtility.DisplayCancelableProgressBar( "Please wait...", "Searching assets", (float) searchProgress / searchTotalProgress ) )
|
||||||
throw new Exception( "Search aborted" );
|
throw new Exception( "Search aborted" );
|
||||||
|
|
||||||
if( excludedAssetsPathsSet.Contains( path ) )
|
if( excludedAssetsPathsSet.Contains( path ) )
|
||||||
@@ -490,7 +540,7 @@ namespace AssetUsageDetectorNamespace
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Search non-serializable variables for references only if we are currently searching a scene and the editor is in play mode
|
// Search non-serializable variables for references only if we are currently searching a scene and the editor is in play mode
|
||||||
if( EditorApplication.isPlaying )
|
if( isInPlayMode )
|
||||||
searchSerializableVariablesOnly = false;
|
searchSerializableVariablesOnly = false;
|
||||||
|
|
||||||
if( scenesToSearch.Count > 0 )
|
if( scenesToSearch.Count > 0 )
|
||||||
@@ -523,7 +573,7 @@ namespace AssetUsageDetectorNamespace
|
|||||||
|
|
||||||
foreach( string scenePath in scenesToSearch )
|
foreach( string scenePath in scenesToSearch )
|
||||||
{
|
{
|
||||||
if( searchParameters.showProgressBar && EditorUtility.DisplayCancelableProgressBar( "Please wait...", "Searching scene: " + scenePath, (float) ++searchProgress / searchTotalProgress ) )
|
if( EditorUtility.DisplayCancelableProgressBar( "Please wait...", "Searching scene: " + scenePath, (float) ++searchProgress / searchTotalProgress ) )
|
||||||
throw new Exception( "Search aborted" );
|
throw new Exception( "Search aborted" );
|
||||||
|
|
||||||
// Search scene for references
|
// Search scene for references
|
||||||
@@ -533,17 +583,17 @@ namespace AssetUsageDetectorNamespace
|
|||||||
if( excludedScenesPathsSet.Contains( scenePath ) )
|
if( excludedScenesPathsSet.Contains( scenePath ) )
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
SearchScene( scenePath, searchResult, initialSceneSetup );
|
SearchScene( scenePath, searchResult, searchParameters.lazySceneSearch, initialSceneSetup );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Search through all the GameObjects under the DontDestroyOnLoad scene (if exists)
|
// Search through all the GameObjects under the DontDestroyOnLoad scene (if exists)
|
||||||
if( EditorApplication.isPlaying )
|
if( isInPlayMode && searchParameters.searchInScenes != SceneSearchMode.None )
|
||||||
{
|
{
|
||||||
if( searchParameters.showProgressBar && EditorUtility.DisplayCancelableProgressBar( "Please wait...", "Searching scene: DontDestroyOnLoad", 1f ) )
|
if( searchParameters.showDetailedProgressBar && EditorUtility.DisplayCancelableProgressBar( "Please wait...", "Searching scene: DontDestroyOnLoad", 1f ) )
|
||||||
throw new Exception( "Search aborted" );
|
throw new Exception( "Search aborted" );
|
||||||
|
|
||||||
currentSearchResultGroup = new SearchResultGroup( "DontDestroyOnLoad", false );
|
currentSearchResultGroup = new SearchResultGroup( "DontDestroyOnLoad", SearchResultGroup.GroupType.DontDestroyOnLoad );
|
||||||
|
|
||||||
GameObject[] rootGameObjects = GetDontDestroyOnLoadObjects();
|
GameObject[] rootGameObjects = GetDontDestroyOnLoadObjects();
|
||||||
for( int i = 0; i < rootGameObjects.Length; i++ )
|
for( int i = 0; i < rootGameObjects.Length; i++ )
|
||||||
@@ -553,17 +603,51 @@ namespace AssetUsageDetectorNamespace
|
|||||||
searchResult.Add( currentSearchResultGroup );
|
searchResult.Add( currentSearchResultGroup );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Searching source assets last prevents some references from being excluded due to callStack.ContainsFast
|
||||||
|
if( !searchParameters.dontSearchInSourceAssets )
|
||||||
|
{
|
||||||
|
searchingSourceAssets = true;
|
||||||
|
|
||||||
|
foreach( Object obj in objectsToSearchSet )
|
||||||
|
{
|
||||||
|
currentSearchedObject = obj;
|
||||||
|
SearchObject( obj );
|
||||||
|
}
|
||||||
|
|
||||||
|
searchingSourceAssets = false;
|
||||||
|
}
|
||||||
|
|
||||||
InitializeSearchResultNodes( searchResult );
|
InitializeSearchResultNodes( searchResult );
|
||||||
|
|
||||||
// Log some c00l stuff to console
|
// Log some c00l stuff to console
|
||||||
Debug.Log( "Searched " + searchedObjectsCount + " objects in " + ( EditorApplication.timeSinceStartup - searchStartTime ).ToString( "F2" ) + " seconds" );
|
Debug.Log( "Searched " + searchedObjectsCount + " objects in " + ( EditorApplication.timeSinceStartup - searchStartTime ).ToString( "F2" ) + " seconds" );
|
||||||
|
|
||||||
return new SearchResult( true, searchResult, initialSceneSetup );
|
return new SearchResult( true, searchResult, initialSceneSetup, this, searchParameters );
|
||||||
}
|
}
|
||||||
catch( Exception e )
|
catch( Exception e )
|
||||||
{
|
{
|
||||||
Debug.LogException( e );
|
Debug.LogException( e );
|
||||||
|
|
||||||
|
if( callStack.Count > 0 )
|
||||||
|
{
|
||||||
|
StringBuilder sb = new StringBuilder( callStack.Count * 50 );
|
||||||
|
sb.AppendLine( "Stack contents: " );
|
||||||
|
for( int i = 0; i < callStack.Count; i++ )
|
||||||
|
{
|
||||||
|
sb.Append( i ).Append( ": " );
|
||||||
|
|
||||||
|
Object unityObject = callStack[i] as Object;
|
||||||
|
if( unityObject != null )
|
||||||
|
sb.Append( unityObject.name ).Append( " (" ).Append( unityObject.GetType() ).AppendLine( ")" );
|
||||||
|
else if( callStack[i] != null )
|
||||||
|
sb.Append( callStack[i].GetType() ).AppendLine( " object" );
|
||||||
|
else
|
||||||
|
sb.AppendLine( "<<destroyed>>" );
|
||||||
|
}
|
||||||
|
|
||||||
|
Debug.LogError( sb.ToString() );
|
||||||
|
}
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
InitializeSearchResultNodes( searchResult );
|
InitializeSearchResultNodes( searchResult );
|
||||||
@@ -571,14 +655,20 @@ namespace AssetUsageDetectorNamespace
|
|||||||
catch
|
catch
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
return new SearchResult( false, searchResult, initialSceneSetup );
|
return new SearchResult( false, searchResult, initialSceneSetup, this, searchParameters );
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
currentSearchResultGroup = null;
|
currentSearchResultGroup = null;
|
||||||
currentObject = null;
|
currentSearchedObject = null;
|
||||||
|
|
||||||
EditorUtility.ClearProgressBar();
|
EditorUtility.ClearProgressBar();
|
||||||
|
|
||||||
|
#if UNITY_2018_3_OR_NEWER
|
||||||
|
// If a prefab stage was open when the search was triggered, try reopening the prefab stage after the search is completed
|
||||||
|
if( !string.IsNullOrEmpty( openPrefabStageAssetPath ) )
|
||||||
|
AssetDatabase.OpenAsset( AssetDatabase.LoadAssetAtPath<GameObject>( openPrefabStageAssetPath ) );
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -590,13 +680,13 @@ namespace AssetUsageDetectorNamespace
|
|||||||
// If there are any empty groups after node initialization, remove those groups
|
// If there are any empty groups after node initialization, remove those groups
|
||||||
for( int i = searchResult.Count - 1; i >= 0; i-- )
|
for( int i = searchResult.Count - 1; i >= 0; i-- )
|
||||||
{
|
{
|
||||||
if( searchResult[i].NumberOfReferences == 0 )
|
if( !searchResult[i].PendingSearch && searchResult[i].NumberOfReferences == 0 )
|
||||||
searchResult.RemoveAtFast( i );
|
searchResult.RemoveAtFast( i );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Checks if object is asset or scene object and adds it to the corresponding HashSet(s)
|
// Checks if object is asset or scene object and adds it to the corresponding HashSet(s)
|
||||||
private void AddSearchedObjectToFilteredSets( Object obj )
|
private void AddSearchedObjectToFilteredSets( Object obj, bool expandGameObjects )
|
||||||
{
|
{
|
||||||
if( obj == null || obj.Equals( null ) )
|
if( obj == null || obj.Equals( null ) )
|
||||||
return;
|
return;
|
||||||
@@ -606,6 +696,16 @@ namespace AssetUsageDetectorNamespace
|
|||||||
|
|
||||||
objectsToSearchSet.Add( obj );
|
objectsToSearchSet.Add( obj );
|
||||||
|
|
||||||
|
#if UNITY_2018_3_OR_NEWER
|
||||||
|
// When searching for references of a prefab stage object, try adding its corresponding prefab asset to the searched assets, as well
|
||||||
|
if( openPrefabStage != null && openPrefabStagePrefabAsset != null && obj is GameObject && openPrefabStage.IsPartOfPrefabContents( (GameObject) obj ) )
|
||||||
|
{
|
||||||
|
GameObject prefabStageObjectSource = ( (GameObject) obj ).FollowSymmetricHierarchy( openPrefabStagePrefabAsset );
|
||||||
|
if( prefabStageObjectSource != null )
|
||||||
|
AddSearchedObjectToFilteredSets( prefabStageObjectSource, expandGameObjects );
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
bool isAsset = obj.IsAsset();
|
bool isAsset = obj.IsAsset();
|
||||||
if( isAsset )
|
if( isAsset )
|
||||||
{
|
{
|
||||||
@@ -614,6 +714,34 @@ namespace AssetUsageDetectorNamespace
|
|||||||
string assetPath = AssetDatabase.GetAssetPath( obj );
|
string assetPath = AssetDatabase.GetAssetPath( obj );
|
||||||
if( !string.IsNullOrEmpty( assetPath ) )
|
if( !string.IsNullOrEmpty( assetPath ) )
|
||||||
assetsToSearchPathsSet.Add( assetPath );
|
assetsToSearchPathsSet.Add( assetPath );
|
||||||
|
|
||||||
|
GameObject go = null;
|
||||||
|
if( obj is GameObject )
|
||||||
|
go = (GameObject) obj;
|
||||||
|
else if( obj is Component )
|
||||||
|
go = ( (Component) obj ).gameObject;
|
||||||
|
|
||||||
|
if( go != null )
|
||||||
|
{
|
||||||
|
Transform transform = go.transform;
|
||||||
|
bool shouldAddRootPrefabEntry = true;
|
||||||
|
for( int i = assetsToSearchRootPrefabs.Count - 1; i >= 0; i-- )
|
||||||
|
{
|
||||||
|
Transform rootTransform = assetsToSearchRootPrefabs[i].transform;
|
||||||
|
|
||||||
|
if( transform.IsChildOf( rootTransform ) )
|
||||||
|
{
|
||||||
|
shouldAddRootPrefabEntry = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if( rootTransform.IsChildOf( transform ) )
|
||||||
|
assetsToSearchRootPrefabs.RemoveAt( i );
|
||||||
|
}
|
||||||
|
|
||||||
|
if( shouldAddRootPrefabEntry )
|
||||||
|
assetsToSearchRootPrefabs.Add( go );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -625,7 +753,7 @@ namespace AssetUsageDetectorNamespace
|
|||||||
sceneObjectsToSearchScenesSet.Add( ( (Component) obj ).gameObject.scene.path );
|
sceneObjectsToSearchScenesSet.Add( ( (Component) obj ).gameObject.scene.path );
|
||||||
}
|
}
|
||||||
|
|
||||||
if( obj is GameObject )
|
if( expandGameObjects && obj is GameObject )
|
||||||
{
|
{
|
||||||
// If searched asset is a GameObject, include its components in the search
|
// If searched asset is a GameObject, include its components in the search
|
||||||
Component[] components = ( (GameObject) obj ).GetComponents<Component>();
|
Component[] components = ( (GameObject) obj ).GetComponents<Component>();
|
||||||
@@ -642,27 +770,40 @@ namespace AssetUsageDetectorNamespace
|
|||||||
sceneObjectsToSearchSet.Add( components[i] );
|
sceneObjectsToSearchSet.Add( components[i] );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else if( obj is Component )
|
||||||
|
{
|
||||||
|
// Include searched components' GameObjects in the search, as well
|
||||||
|
AddSearchedObjectToFilteredSets( ( (Component) obj ).gameObject, false );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Search a scene for references
|
// Search a scene for references
|
||||||
private void SearchScene( string scenePath, List<SearchResultGroup> searchResult, SceneSetup[] initialSceneSetup )
|
private void SearchScene( string scenePath, List<SearchResultGroup> searchResult, bool lazySearch, SceneSetup[] initialSceneSetup )
|
||||||
{
|
{
|
||||||
Scene scene = EditorSceneManager.GetSceneByPath( scenePath );
|
Scene scene = EditorSceneManager.GetSceneByPath( scenePath );
|
||||||
if( EditorApplication.isPlaying && !scene.isLoaded )
|
if( isInPlayMode && !scene.isLoaded )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
bool canContainSceneObjectReference = scene.isLoaded && ( !EditorSceneManager.preventCrossSceneReferences || sceneObjectsToSearchScenesSet.Contains( scenePath ) );
|
bool canContainSceneObjectReference = scene.isLoaded && ( !EditorSceneManager.preventCrossSceneReferences || sceneObjectsToSearchScenesSet.Contains( scenePath ) );
|
||||||
if( !canContainSceneObjectReference )
|
if( !canContainSceneObjectReference )
|
||||||
{
|
{
|
||||||
bool canContainAssetReference = assetsToSearchSet.Count > 0 && ( EditorApplication.isPlaying || AssetHasAnyReference( scenePath ) );
|
bool canContainAssetReference = assetsToSearchSet.Count > 0 && ( isInPlayMode || AssetHasAnyReference( scenePath ) );
|
||||||
if( !canContainAssetReference )
|
if( !canContainAssetReference )
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if( !EditorApplication.isPlaying )
|
if( !scene.isLoaded )
|
||||||
scene = EditorSceneManager.OpenScene( scenePath, OpenSceneMode.Additive );
|
{
|
||||||
|
if( lazySearch )
|
||||||
|
{
|
||||||
|
searchResult.Add( new SearchResultGroup( scenePath, SearchResultGroup.GroupType.Scene, true, true ) );
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
currentSearchResultGroup = new SearchResultGroup( scenePath, true );
|
scene = EditorSceneManager.OpenScene( scenePath, OpenSceneMode.Additive );
|
||||||
|
}
|
||||||
|
|
||||||
|
currentSearchResultGroup = new SearchResultGroup( scenePath, SearchResultGroup.GroupType.Scene );
|
||||||
|
|
||||||
// Search through all the GameObjects in the scene
|
// Search through all the GameObjects in the scene
|
||||||
GameObject[] rootGameObjects = scene.GetRootGameObjects();
|
GameObject[] rootGameObjects = scene.GetRootGameObjects();
|
||||||
@@ -672,7 +813,7 @@ namespace AssetUsageDetectorNamespace
|
|||||||
// If no references are found in the scene and if the scene is not part of the initial scene setup, close it
|
// If no references are found in the scene and if the scene is not part of the initial scene setup, close it
|
||||||
if( currentSearchResultGroup.NumberOfReferences == 0 )
|
if( currentSearchResultGroup.NumberOfReferences == 0 )
|
||||||
{
|
{
|
||||||
if( !EditorApplication.isPlaying )
|
if( !isInPlayMode )
|
||||||
{
|
{
|
||||||
bool sceneIsOneOfInitials = false;
|
bool sceneIsOneOfInitials = false;
|
||||||
for( int i = 0; i < initialSceneSetup.Length; i++ )
|
for( int i = 0; i < initialSceneSetup.Length; i++ )
|
||||||
@@ -714,10 +855,10 @@ namespace AssetUsageDetectorNamespace
|
|||||||
if( obj is SceneAsset )
|
if( obj is SceneAsset )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
currentObject = obj;
|
currentSearchedObject = obj;
|
||||||
|
|
||||||
ReferenceNode searchResult = SearchObject( obj );
|
ReferenceNode searchResult = SearchObject( obj );
|
||||||
if( searchResult != null && currentSearchResultGroup != null )
|
if( searchResult != null )
|
||||||
currentSearchResultGroup.AddReference( searchResult );
|
currentSearchResultGroup.AddReference( searchResult );
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -731,16 +872,21 @@ namespace AssetUsageDetectorNamespace
|
|||||||
if( callStack.ContainsFast( obj ) )
|
if( callStack.ContainsFast( obj ) )
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
|
bool searchingSourceAsset = searchingSourceAssets && ReferenceEquals( currentSearchedObject, obj );
|
||||||
|
|
||||||
// Hashing does not work well with structs all the time, don't cache search results for structs
|
// Hashing does not work well with structs all the time, don't cache search results for structs
|
||||||
string objHash = null;
|
string objHash = null;
|
||||||
if( !( obj is ValueType ) )
|
if( !( obj is ValueType ) )
|
||||||
{
|
{
|
||||||
objHash = obj.Hash();
|
objHash = obj.Hash();
|
||||||
|
|
||||||
// If object was searched before, return the cached result
|
if( !searchingSourceAsset )
|
||||||
ReferenceNode cachedResult;
|
{
|
||||||
if( searchedObjects.TryGetValue( objHash, out cachedResult ) )
|
// If object was searched before, return the cached result
|
||||||
return cachedResult;
|
ReferenceNode cachedResult;
|
||||||
|
if( searchedObjects.TryGetValue( objHash, out cachedResult ) )
|
||||||
|
return cachedResult;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
searchedObjectsCount++;
|
searchedObjectsCount++;
|
||||||
@@ -749,21 +895,6 @@ namespace AssetUsageDetectorNamespace
|
|||||||
Object unityObject = obj as Object;
|
Object unityObject = obj as Object;
|
||||||
if( unityObject != null )
|
if( unityObject != null )
|
||||||
{
|
{
|
||||||
// If we hit a searched asset
|
|
||||||
if( objectsToSearchSet.Contains( unityObject ) )
|
|
||||||
{
|
|
||||||
// If we were searching for references of the searched asset that we hit (or a component of it),
|
|
||||||
// ignore the hit since the searched asset doesn't have a meaningful reference to itself at the moment
|
|
||||||
// If there is a meaningful reference, it will become available when calling the SearchX functions below
|
|
||||||
if( currentObject != unityObject && ( !( unityObject is Component ) || currentObject != ( (Component) unityObject ).gameObject ) )
|
|
||||||
{
|
|
||||||
result = PopReferenceNode( unityObject );
|
|
||||||
searchedObjects.Add( objHash, result );
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// If the Object is an asset, search it in detail only if its dependencies contain at least one of the searched asset(s)
|
// If the Object is an asset, search it in detail only if its dependencies contain at least one of the searched asset(s)
|
||||||
if( unityObject.IsAsset() && ( assetsToSearchSet.Count == 0 || !AssetHasAnyReference( AssetDatabase.GetAssetPath( unityObject ) ) ) )
|
if( unityObject.IsAsset() && ( assetsToSearchSet.Count == 0 || !AssetHasAnyReference( AssetDatabase.GetAssetPath( unityObject ) ) ) )
|
||||||
{
|
{
|
||||||
@@ -782,7 +913,7 @@ namespace AssetUsageDetectorNamespace
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
result = PopReferenceNode( unityObject );
|
result = PopReferenceNode( unityObject );
|
||||||
SearchFieldsAndPropertiesOf( result );
|
SearchWithSerializedObject( result );
|
||||||
}
|
}
|
||||||
|
|
||||||
callStack.RemoveAt( callStack.Count - 1 );
|
callStack.RemoveAt( callStack.Count - 1 );
|
||||||
@@ -813,7 +944,15 @@ namespace AssetUsageDetectorNamespace
|
|||||||
// and if the object is a UnityEngine.Object (if not, cache the result only if we have actually found something
|
// and if the object is a UnityEngine.Object (if not, cache the result only if we have actually found something
|
||||||
// or we are at the root of the search; i.e. currentDepth == 0)
|
// or we are at the root of the search; i.e. currentDepth == 0)
|
||||||
if( objHash != null && ( result != null || unityObject != null || currentDepth == 0 ) )
|
if( objHash != null && ( result != null || unityObject != null || currentDepth == 0 ) )
|
||||||
searchedObjects.Add( objHash, result );
|
{
|
||||||
|
if( !searchingSourceAsset )
|
||||||
|
searchedObjects.Add( objHash, result );
|
||||||
|
else if( result != null )
|
||||||
|
{
|
||||||
|
result.CopyReferencesTo( searchedObjects[objHash] );
|
||||||
|
PoolReferenceNode( result );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@@ -828,11 +967,10 @@ namespace AssetUsageDetectorNamespace
|
|||||||
{
|
{
|
||||||
#if UNITY_2018_3_OR_NEWER
|
#if UNITY_2018_3_OR_NEWER
|
||||||
Object prefab = PrefabUtility.GetCorrespondingObjectFromSource( go );
|
Object prefab = PrefabUtility.GetCorrespondingObjectFromSource( go );
|
||||||
if( objectsToSearchSet.Contains( prefab ) && go == PrefabUtility.GetNearestPrefabInstanceRoot( go ) )
|
|
||||||
#else
|
#else
|
||||||
Object prefab = PrefabUtility.GetPrefabParent( go );
|
Object prefab = PrefabUtility.GetPrefabParent( go );
|
||||||
if( objectsToSearchSet.Contains( prefab ) && go == PrefabUtility.FindRootGameObjectWithSameParentPrefab( go ) )
|
|
||||||
#endif
|
#endif
|
||||||
|
if( objectsToSearchSet.Contains( prefab ) && assetsToSearchRootPrefabs.ContainsFast( prefab as GameObject ) )
|
||||||
referenceNode.AddLinkTo( GetReferenceNode( prefab ), "Prefab object" );
|
referenceNode.AddLinkTo( GetReferenceNode( prefab ), "Prefab object" );
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -907,7 +1045,7 @@ namespace AssetUsageDetectorNamespace
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
SearchFieldsAndPropertiesOf( referenceNode );
|
SearchWithSerializedObject( referenceNode );
|
||||||
return referenceNode;
|
return referenceNode;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1089,6 +1227,57 @@ namespace AssetUsageDetectorNamespace
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
// Search through field and properties of an object for references with SerializedObject
|
||||||
|
private void SearchWithSerializedObject( ReferenceNode referenceNode )
|
||||||
|
{
|
||||||
|
if( !isInPlayMode || referenceNode.nodeObject.IsAsset() )
|
||||||
|
{
|
||||||
|
SerializedObject so = new SerializedObject( (Object) referenceNode.nodeObject );
|
||||||
|
SerializedProperty iterator = so.GetIterator();
|
||||||
|
if( iterator.NextVisible( true ) )
|
||||||
|
{
|
||||||
|
bool enterChildren;
|
||||||
|
do
|
||||||
|
{
|
||||||
|
ReferenceNode searchResult;
|
||||||
|
switch( iterator.propertyType )
|
||||||
|
{
|
||||||
|
case SerializedPropertyType.ObjectReference:
|
||||||
|
searchResult = SearchObject( iterator.objectReferenceValue );
|
||||||
|
enterChildren = false;
|
||||||
|
break;
|
||||||
|
case SerializedPropertyType.ExposedReference:
|
||||||
|
searchResult = SearchObject( iterator.exposedReferenceValue );
|
||||||
|
enterChildren = false;
|
||||||
|
break;
|
||||||
|
case SerializedPropertyType.Generic:
|
||||||
|
searchResult = null;
|
||||||
|
enterChildren = true;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
searchResult = null;
|
||||||
|
enterChildren = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if( searchResult != null && searchResult != referenceNode )
|
||||||
|
{
|
||||||
|
string propertyPath = iterator.propertyPath;
|
||||||
|
|
||||||
|
// m_RD.texture is a redundant reference that shows up when searching sprites
|
||||||
|
if( !propertyPath.EndsWith( "m_RD.texture", StringComparison.Ordinal ) )
|
||||||
|
referenceNode.AddLinkTo( searchResult, "Variable: " + propertyPath );
|
||||||
|
}
|
||||||
|
} while( iterator.NextVisible( enterChildren ) );
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Use reflection algorithm as fallback
|
||||||
|
SearchFieldsAndPropertiesOf( referenceNode );
|
||||||
|
}
|
||||||
|
|
||||||
// Search through field and properties of an object for references
|
// Search through field and properties of an object for references
|
||||||
private void SearchFieldsAndPropertiesOf( ReferenceNode referenceNode )
|
private void SearchFieldsAndPropertiesOf( ReferenceNode referenceNode )
|
||||||
{
|
{
|
||||||
@@ -1106,20 +1295,36 @@ namespace AssetUsageDetectorNamespace
|
|||||||
if( variableValue == null )
|
if( variableValue == null )
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if( !( variableValue is IEnumerable ) || variableValue is Transform )
|
// Values stored inside ICollection objects are searched using IEnumerable,
|
||||||
referenceNode.AddLinkTo( SearchObject( variableValue ), ( variables[i].isProperty ? "Property: " : "Variable: " ) + variables[i].name );
|
// no need to have duplicate search entries
|
||||||
else
|
if( !( variableValue is ICollection ) )
|
||||||
|
{
|
||||||
|
ReferenceNode searchResult = SearchObject( variableValue );
|
||||||
|
if( searchResult != null && searchResult != referenceNode )
|
||||||
|
referenceNode.AddLinkTo( searchResult, ( variables[i].isProperty ? "Property: " : "Variable: " ) + variables[i].name );
|
||||||
|
}
|
||||||
|
|
||||||
|
if( variableValue is IEnumerable && !( variableValue is Transform ) )
|
||||||
{
|
{
|
||||||
// If the field is IEnumerable (possibly an array or collection), search through members of it
|
// If the field is IEnumerable (possibly an array or collection), search through members of it
|
||||||
// Note that Transform IEnumerable (children of the transform) is not iterated
|
// Note that Transform IEnumerable (children of the transform) is not iterated
|
||||||
foreach( object arrayItem in (IEnumerable) variableValue )
|
int index = 0;
|
||||||
referenceNode.AddLinkTo( SearchObject( arrayItem ), ( variables[i].isProperty ? "Property (IEnumerable): " : "Variable (IEnumerable): " ) + variables[i].name );
|
foreach( object element in (IEnumerable) variableValue )
|
||||||
|
{
|
||||||
|
ReferenceNode searchResult = SearchObject( element );
|
||||||
|
if( searchResult != null && searchResult != referenceNode )
|
||||||
|
referenceNode.AddLinkTo( searchResult, string.Concat( variables[i].isProperty ? "Property: " : "Variable: ", variables[i].name, "[", index + "]" ) );
|
||||||
|
|
||||||
|
index++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch( UnassignedReferenceException )
|
catch( UnassignedReferenceException )
|
||||||
{ }
|
{ }
|
||||||
catch( MissingReferenceException )
|
catch( MissingReferenceException )
|
||||||
{ }
|
{ }
|
||||||
|
catch( MissingComponentException )
|
||||||
|
{ }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1149,12 +1354,14 @@ namespace AssetUsageDetectorNamespace
|
|||||||
FieldInfo[] fields = currType.GetFields( fieldModifiers );
|
FieldInfo[] fields = currType.GetFields( fieldModifiers );
|
||||||
for( int i = 0; i < fields.Length; i++ )
|
for( int i = 0; i < fields.Length; i++ )
|
||||||
{
|
{
|
||||||
|
FieldInfo field = fields[i];
|
||||||
|
|
||||||
// Skip obsolete fields
|
// Skip obsolete fields
|
||||||
if( Attribute.IsDefined( fields[i], typeof( ObsoleteAttribute ) ) )
|
if( Attribute.IsDefined( field, typeof( ObsoleteAttribute ) ) )
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
// Skip primitive types
|
// Skip primitive types
|
||||||
Type variableType = fields[i].FieldType;
|
Type variableType = field.FieldType;
|
||||||
if( variableType.IsPrimitiveUnityType() )
|
if( variableType.IsPrimitiveUnityType() )
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
@@ -1162,16 +1369,20 @@ namespace AssetUsageDetectorNamespace
|
|||||||
if( typeof( Type ).IsAssignableFrom( variableType ) || variableType.Namespace == reflectionNameSpace )
|
if( typeof( Type ).IsAssignableFrom( variableType ) || variableType.Namespace == reflectionNameSpace )
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
// Searching pointer variables for reference throws ArgumentException
|
||||||
|
if( variableType.IsPointer )
|
||||||
|
continue;
|
||||||
|
|
||||||
// Additional filtering for fields:
|
// Additional filtering for fields:
|
||||||
// 1- Ignore "m_RectTransform", "m_CanvasRenderer" and "m_Canvas" fields of Graphic components
|
// 1- Ignore "m_RectTransform", "m_CanvasRenderer" and "m_Canvas" fields of Graphic components
|
||||||
string fieldName = fields[i].Name;
|
string fieldName = field.Name;
|
||||||
if( typeof( Graphic ).IsAssignableFrom( currType ) &&
|
if( typeof( Graphic ).IsAssignableFrom( currType ) &&
|
||||||
( fieldName == "m_RectTransform" || fieldName == "m_CanvasRenderer" || fieldName == "m_Canvas" ) )
|
( fieldName == "m_RectTransform" || fieldName == "m_CanvasRenderer" || fieldName == "m_Canvas" ) )
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
VariableGetVal getter = fields[i].CreateGetter( type );
|
VariableGetVal getter = field.CreateGetter( type );
|
||||||
if( getter != null )
|
if( getter != null )
|
||||||
validVariables.Add( new VariableGetterHolder( fields[i], getter, fields[i].IsSerializable() ) );
|
validVariables.Add( new VariableGetterHolder( field, getter, field.IsSerializable() ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
currType = currType.BaseType;
|
currType = currType.BaseType;
|
||||||
@@ -1186,12 +1397,14 @@ namespace AssetUsageDetectorNamespace
|
|||||||
PropertyInfo[] properties = currType.GetProperties( propertyModifiers );
|
PropertyInfo[] properties = currType.GetProperties( propertyModifiers );
|
||||||
for( int i = 0; i < properties.Length; i++ )
|
for( int i = 0; i < properties.Length; i++ )
|
||||||
{
|
{
|
||||||
|
PropertyInfo property = properties[i];
|
||||||
|
|
||||||
// Skip obsolete properties
|
// Skip obsolete properties
|
||||||
if( Attribute.IsDefined( properties[i], typeof( ObsoleteAttribute ) ) )
|
if( Attribute.IsDefined( property, typeof( ObsoleteAttribute ) ) )
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
// Skip primitive types
|
// Skip primitive types
|
||||||
Type variableType = properties[i].PropertyType;
|
Type variableType = property.PropertyType;
|
||||||
if( variableType.IsPrimitiveUnityType() )
|
if( variableType.IsPrimitiveUnityType() )
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
@@ -1199,15 +1412,28 @@ namespace AssetUsageDetectorNamespace
|
|||||||
if( typeof( Type ).IsAssignableFrom( variableType ) || variableType.Namespace == reflectionNameSpace )
|
if( typeof( Type ).IsAssignableFrom( variableType ) || variableType.Namespace == reflectionNameSpace )
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
// Searching pointer variables for reference throws ArgumentException
|
||||||
|
if( variableType.IsPointer )
|
||||||
|
continue;
|
||||||
|
|
||||||
|
// Skip properties without a getter function
|
||||||
|
MethodInfo propertyGetter = property.GetGetMethod( true );
|
||||||
|
if( propertyGetter == null )
|
||||||
|
continue;
|
||||||
|
|
||||||
|
// Skip indexer properties
|
||||||
|
if( property.GetIndexParameters().Length > 0 )
|
||||||
|
continue;
|
||||||
|
|
||||||
// No need to check properties with 'override' keyword
|
// No need to check properties with 'override' keyword
|
||||||
if( properties[i].IsOverridden() )
|
if( propertyGetter.GetBaseDefinition().DeclaringType != propertyGetter.DeclaringType )
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
// Additional filtering for properties:
|
// Additional filtering for properties:
|
||||||
// 1- Ignore "gameObject", "transform", "rectTransform" and "attachedRigidbody" properties of Component's to get more useful results
|
// 1- Ignore "gameObject", "transform", "rectTransform" and "attachedRigidbody" properties of Component's to get more useful results
|
||||||
// 2- Ignore "canvasRenderer" and "canvas" properties of Graphic components
|
// 2- Ignore "canvasRenderer" and "canvas" properties of Graphic components
|
||||||
// 3 & 4- Prevent accessing properties of Unity that instantiate an existing resource (causing memory leak)
|
// 3 & 4- Prevent accessing properties of Unity that instantiate an existing resource (causing memory leak)
|
||||||
string propertyName = properties[i].Name;
|
string propertyName = property.Name;
|
||||||
if( typeof( Component ).IsAssignableFrom( currType ) && ( propertyName == "gameObject" ||
|
if( typeof( Component ).IsAssignableFrom( currType ) && ( propertyName == "gameObject" ||
|
||||||
propertyName == "transform" || propertyName == "attachedRigidbody" || propertyName == "rectTransform" ) )
|
propertyName == "transform" || propertyName == "attachedRigidbody" || propertyName == "rectTransform" ) )
|
||||||
continue;
|
continue;
|
||||||
@@ -1230,9 +1456,9 @@ namespace AssetUsageDetectorNamespace
|
|||||||
continue;
|
continue;
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
VariableGetVal getter = properties[i].CreateGetter();
|
VariableGetVal getter = property.CreateGetter();
|
||||||
if( getter != null )
|
if( getter != null )
|
||||||
validVariables.Add( new VariableGetterHolder( properties[i], getter, properties[i].IsSerializable() ) );
|
validVariables.Add( new VariableGetterHolder( property, getter, property.IsSerializable() ) );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1251,6 +1477,10 @@ namespace AssetUsageDetectorNamespace
|
|||||||
// Check if the asset at specified path depends on any of the references
|
// Check if the asset at specified path depends on any of the references
|
||||||
private bool AssetHasAnyReference( string assetPath )
|
private bool AssetHasAnyReference( string assetPath )
|
||||||
{
|
{
|
||||||
|
// "Find references of" assets can contain internal references
|
||||||
|
if( assetsToSearchPathsSet.Contains( assetPath ) )
|
||||||
|
return true;
|
||||||
|
|
||||||
CacheEntry cacheEntry;
|
CacheEntry cacheEntry;
|
||||||
if( !assetDependencyCache.TryGetValue( assetPath, out cacheEntry ) )
|
if( !assetDependencyCache.TryGetValue( assetPath, out cacheEntry ) )
|
||||||
{
|
{
|
||||||
@@ -1271,13 +1501,16 @@ namespace AssetUsageDetectorNamespace
|
|||||||
{
|
{
|
||||||
// If a dependency was renamed (which doesn't affect the verified hash, unfortunately),
|
// If a dependency was renamed (which doesn't affect the verified hash, unfortunately),
|
||||||
// force refresh the asset's dependencies and search it again
|
// force refresh the asset's dependencies and search it again
|
||||||
FileInfo assetFile = new FileInfo( dependencies[i] );
|
if( !Directory.Exists( dependencies[i] ) ) // Calling FileInfo.Length on a directory throws FileNotFoundException
|
||||||
if( !assetFile.Exists || assetFile.Length != fileSizes[i] )
|
|
||||||
{
|
{
|
||||||
cacheEntry.Refresh( assetPath );
|
FileInfo assetFile = new FileInfo( dependencies[i] );
|
||||||
cacheEntry.searchResult = CacheEntry.Result.Unknown;
|
if( !assetFile.Exists || assetFile.Length != fileSizes[i] )
|
||||||
|
{
|
||||||
|
cacheEntry.Refresh( assetPath );
|
||||||
|
cacheEntry.searchResult = CacheEntry.Result.Unknown;
|
||||||
|
|
||||||
return AssetHasAnyReference( assetPath );
|
return AssetHasAnyReference( assetPath );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if( assetsToSearchPathsSet.Contains( dependencies[i] ) )
|
if( assetsToSearchPathsSet.Contains( dependencies[i] ) )
|
||||||
@@ -1445,7 +1678,7 @@ namespace AssetUsageDetectorNamespace
|
|||||||
{
|
{
|
||||||
for( int i = 0; i < allAssets.Length; i++ )
|
for( int i = 0; i < allAssets.Length; i++ )
|
||||||
{
|
{
|
||||||
if( i % 30 == 0 && EditorUtility.DisplayCancelableProgressBar( "Please wait...", "Generating cache for the first time", (float) i / allAssets.Length ) )
|
if( i % 30 == 0 && EditorUtility.DisplayCancelableProgressBar( "Please wait...", "Generating cache for the first time (optional)", (float) i / allAssets.Length ) )
|
||||||
{
|
{
|
||||||
EditorUtility.ClearProgressBar();
|
EditorUtility.ClearProgressBar();
|
||||||
Debug.LogWarning( "Initial cache generation cancelled, cache will be generated on the fly as more and more assets are searched." );
|
Debug.LogWarning( "Initial cache generation cancelled, cache will be generated on the fly as more and more assets are searched." );
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ namespace AssetUsageDetectorNamespace.Extras
|
|||||||
private const string PREFS_SEARCH_FIELDS = "AUD_Fields";
|
private const string PREFS_SEARCH_FIELDS = "AUD_Fields";
|
||||||
private const string PREFS_SEARCH_PROPERTIES = "AUD_Properties";
|
private const string PREFS_SEARCH_PROPERTIES = "AUD_Properties";
|
||||||
private const string PREFS_SEARCH_NON_SERIALIZABLES = "AUD_NonSerializables";
|
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_PATH_DRAWING_MODE = "AUD_PathDrawing";
|
||||||
private const string PREFS_SHOW_PROGRESS = "AUD_Progress";
|
private const string PREFS_SHOW_PROGRESS = "AUD_Progress";
|
||||||
private const string PREFS_SHOW_TOOLTIPS = "AUD_Tooltips";
|
private const string PREFS_SHOW_TOOLTIPS = "AUD_Tooltips";
|
||||||
@@ -36,7 +37,7 @@ namespace AssetUsageDetectorNamespace.Extras
|
|||||||
private bool searchInScenesInBuild = true; // Scenes in build
|
private bool searchInScenesInBuild = true; // Scenes in build
|
||||||
private bool searchInScenesInBuildTickedOnly = true; // Scenes in build (ticked only or not)
|
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 searchInAllScenes = true; // All scenes (including scenes that are not in build)
|
||||||
private bool searchInAssetsFolder = true; // Assets in Project view
|
private bool searchInAssetsFolder = true; // Assets in Project window
|
||||||
private bool dontSearchInSourceAssets = false; // objectsToSearch won't be searched for internal references
|
private bool dontSearchInSourceAssets = false; // objectsToSearch won't be searched for internal references
|
||||||
|
|
||||||
private List<Object> searchInAssetsSubset = new List<Object>() { null }; // If not empty, only these assets are searched for references
|
private List<Object> searchInAssetsSubset = new List<Object>() { null }; // If not empty, only these assets are searched for references
|
||||||
@@ -49,13 +50,14 @@ namespace AssetUsageDetectorNamespace.Extras
|
|||||||
|
|
||||||
private string errorMessage = string.Empty;
|
private string errorMessage = string.Empty;
|
||||||
|
|
||||||
|
private bool lazySceneSearch = false;
|
||||||
private bool searchNonSerializableVariables = true;
|
private bool searchNonSerializableVariables = true;
|
||||||
private bool noAssetDatabaseChanges = false;
|
private bool noAssetDatabaseChanges = false;
|
||||||
private bool showProgressBar = false;
|
private bool showDetailedProgressBar = false;
|
||||||
|
|
||||||
private BindingFlags fieldModifiers, propertyModifiers;
|
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;
|
private double nextPlayModeRefreshTime = 0f;
|
||||||
|
|
||||||
@@ -76,20 +78,31 @@ namespace AssetUsageDetectorNamespace.Extras
|
|||||||
window.titleContent = new GUIContent( "Asset Usage Detector" );
|
window.titleContent = new GUIContent( "Asset Usage Detector" );
|
||||||
window.minSize = new Vector2( 325f, 220f );
|
window.minSize = new Vector2( 325f, 220f );
|
||||||
|
|
||||||
window.LoadPrefs();
|
|
||||||
window.Show();
|
window.Show();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Quickly initiate search for the selected assets
|
// Quickly initiate search for the selected assets
|
||||||
|
[MenuItem( "GameObject/Search for References", priority = 49 )]
|
||||||
[MenuItem( "Assets/Search for References", priority = 1000 )]
|
[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 so that there aren't multiple empty parents
|
||||||
|
// generated in one call
|
||||||
|
if( command.context )
|
||||||
|
{
|
||||||
|
EditorApplication.update -= CallSearchSelectedAssetReferencesOnce;
|
||||||
|
EditorApplication.update += CallSearchSelectedAssetReferencesOnce;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
ShowAndSearch( Selection.objects );
|
||||||
}
|
}
|
||||||
|
|
||||||
// Show the menu item only if there is a selection in the Editor
|
// Show the menu item only if there is a selection in the Editor
|
||||||
|
[MenuItem( "GameObject/Search for References", validate = true )]
|
||||||
[MenuItem( "Assets/Search for References", validate = true )]
|
[MenuItem( "Assets/Search for References", validate = true )]
|
||||||
private static bool SearchSelectedAssetReferencesValidate()
|
private static bool SearchSelectedAssetReferencesValidate( MenuCommand command )
|
||||||
{
|
{
|
||||||
return Selection.objects.Length > 0;
|
return Selection.objects.Length > 0;
|
||||||
}
|
}
|
||||||
@@ -112,6 +125,12 @@ namespace AssetUsageDetectorNamespace.Extras
|
|||||||
ShowAndSearchInternal( searchParameters.objectsToSearch, searchParameters );
|
ShowAndSearchInternal( searchParameters.objectsToSearch, searchParameters );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void CallSearchSelectedAssetReferencesOnce()
|
||||||
|
{
|
||||||
|
EditorApplication.update -= CallSearchSelectedAssetReferencesOnce;
|
||||||
|
SearchSelectedAssetReferences( new MenuCommand( null ) );
|
||||||
|
}
|
||||||
|
|
||||||
private static void ShowAndSearchInternal( IEnumerable<Object> searchObjects, AssetUsageDetector.Parameters searchParameters )
|
private static void ShowAndSearchInternal( IEnumerable<Object> searchObjects, AssetUsageDetector.Parameters searchParameters )
|
||||||
{
|
{
|
||||||
if( visibleWindow != null && !visibleWindow.ReturnToSetupPhase( true ) )
|
if( visibleWindow != null && !visibleWindow.ReturnToSetupPhase( true ) )
|
||||||
@@ -138,8 +157,9 @@ namespace AssetUsageDetectorNamespace.Extras
|
|||||||
visibleWindow.fieldModifiers = searchParameters.fieldModifiers;
|
visibleWindow.fieldModifiers = searchParameters.fieldModifiers;
|
||||||
visibleWindow.propertyModifiers = searchParameters.propertyModifiers;
|
visibleWindow.propertyModifiers = searchParameters.propertyModifiers;
|
||||||
visibleWindow.searchNonSerializableVariables = searchParameters.searchNonSerializableVariables;
|
visibleWindow.searchNonSerializableVariables = searchParameters.searchNonSerializableVariables;
|
||||||
|
visibleWindow.lazySceneSearch = searchParameters.lazySceneSearch;
|
||||||
visibleWindow.noAssetDatabaseChanges = searchParameters.noAssetDatabaseChanges;
|
visibleWindow.noAssetDatabaseChanges = searchParameters.noAssetDatabaseChanges;
|
||||||
visibleWindow.showProgressBar = searchParameters.showProgressBar;
|
visibleWindow.showDetailedProgressBar = searchParameters.showDetailedProgressBar;
|
||||||
|
|
||||||
visibleWindow.searchInAssetsSubset.Clear();
|
visibleWindow.searchInAssetsSubset.Clear();
|
||||||
if( searchParameters.searchInAssetsSubset != null )
|
if( searchParameters.searchInAssetsSubset != null )
|
||||||
@@ -166,6 +186,11 @@ namespace AssetUsageDetectorNamespace.Extras
|
|||||||
visibleWindow.InitiateSearch();
|
visibleWindow.InitiateSearch();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void Awake()
|
||||||
|
{
|
||||||
|
LoadPrefs();
|
||||||
|
}
|
||||||
|
|
||||||
private void OnEnable()
|
private void OnEnable()
|
||||||
{
|
{
|
||||||
visibleWindow = this;
|
visibleWindow = this;
|
||||||
@@ -197,8 +222,9 @@ namespace AssetUsageDetectorNamespace.Extras
|
|||||||
EditorPrefs.SetInt( PREFS_SEARCH_PROPERTIES, (int) propertyModifiers );
|
EditorPrefs.SetInt( PREFS_SEARCH_PROPERTIES, (int) propertyModifiers );
|
||||||
EditorPrefs.SetInt( PREFS_PATH_DRAWING_MODE, (int) searchResultDrawParameters.pathDrawingMode );
|
EditorPrefs.SetInt( PREFS_PATH_DRAWING_MODE, (int) searchResultDrawParameters.pathDrawingMode );
|
||||||
EditorPrefs.SetBool( PREFS_SEARCH_NON_SERIALIZABLES, searchNonSerializableVariables );
|
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_TOOLTIPS, searchResultDrawParameters.showTooltips );
|
||||||
EditorPrefs.SetBool( PREFS_SHOW_PROGRESS, showProgressBar );
|
EditorPrefs.SetBool( PREFS_SHOW_PROGRESS, showDetailedProgressBar );
|
||||||
}
|
}
|
||||||
|
|
||||||
private void LoadPrefs()
|
private void LoadPrefs()
|
||||||
@@ -206,7 +232,7 @@ namespace AssetUsageDetectorNamespace.Extras
|
|||||||
ParseSceneSearchMode( (SceneSearchMode) EditorPrefs.GetInt( PREFS_SEARCH_SCENES, (int) ( SceneSearchMode.OpenScenes | SceneSearchMode.ScenesInBuildSettingsTickedOnly | SceneSearchMode.AllScenes ) ) );
|
ParseSceneSearchMode( (SceneSearchMode) EditorPrefs.GetInt( PREFS_SEARCH_SCENES, (int) ( SceneSearchMode.OpenScenes | SceneSearchMode.ScenesInBuildSettingsTickedOnly | SceneSearchMode.AllScenes ) ) );
|
||||||
|
|
||||||
searchInAssetsFolder = EditorPrefs.GetBool( PREFS_SEARCH_ASSETS, true );
|
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 );
|
||||||
searchDepthLimit = EditorPrefs.GetInt( PREFS_SEARCH_DEPTH_LIMIT, 4 );
|
searchDepthLimit = EditorPrefs.GetInt( PREFS_SEARCH_DEPTH_LIMIT, 4 );
|
||||||
|
|
||||||
// Fetch public, protected and private non-static fields and properties from objects by default
|
// Fetch public, protected and private non-static fields and properties from objects by default
|
||||||
@@ -223,8 +249,9 @@ namespace AssetUsageDetectorNamespace.Extras
|
|||||||
}
|
}
|
||||||
|
|
||||||
searchNonSerializableVariables = EditorPrefs.GetBool( PREFS_SEARCH_NON_SERIALIZABLES, true );
|
searchNonSerializableVariables = EditorPrefs.GetBool( PREFS_SEARCH_NON_SERIALIZABLES, true );
|
||||||
|
lazySceneSearch = EditorPrefs.GetBool( PREFS_LAZY_SCENE_SEARCH, false );
|
||||||
searchResultDrawParameters.showTooltips = EditorPrefs.GetBool( PREFS_SHOW_TOOLTIPS, false );
|
searchResultDrawParameters.showTooltips = EditorPrefs.GetBool( PREFS_SHOW_TOOLTIPS, false );
|
||||||
showProgressBar = EditorPrefs.GetBool( PREFS_SHOW_PROGRESS, false );
|
showDetailedProgressBar = EditorPrefs.GetBool( PREFS_SHOW_PROGRESS, false );
|
||||||
}
|
}
|
||||||
|
|
||||||
private SceneSearchMode GetSceneSearchMode( bool hideOptionsInPlayMode )
|
private SceneSearchMode GetSceneSearchMode( bool hideOptionsInPlayMode )
|
||||||
@@ -279,7 +306,7 @@ namespace AssetUsageDetectorNamespace.Extras
|
|||||||
if( currentPhase == Phase.Processing )
|
if( currentPhase == Phase.Processing )
|
||||||
{
|
{
|
||||||
// If we are stuck at this phase, then we have encountered an exception
|
// If we are stuck at this phase, then we have encountered an exception
|
||||||
GUILayout.Label( ". . . Something went wrong, check console . . ." );
|
GUILayout.Label( ". . . Search in progress or something went wrong (check console) . . ." );
|
||||||
|
|
||||||
restoreInitialSceneSetup = EditorGUILayout.ToggleLeft( "Restore initial scene setup (Recommended)", restoreInitialSceneSetup );
|
restoreInitialSceneSetup = EditorGUILayout.ToggleLeft( "Restore initial scene setup (Recommended)", restoreInitialSceneSetup );
|
||||||
|
|
||||||
@@ -295,7 +322,7 @@ namespace AssetUsageDetectorNamespace.Extras
|
|||||||
|
|
||||||
GUILayout.Box( "SEARCH IN", Utilities.BoxGUIStyle, Utilities.GL_EXPAND_WIDTH );
|
GUILayout.Box( "SEARCH IN", Utilities.BoxGUIStyle, Utilities.GL_EXPAND_WIDTH );
|
||||||
|
|
||||||
searchInAssetsFolder = EditorGUILayout.ToggleLeft( "Project view (Assets folder)", searchInAssetsFolder );
|
searchInAssetsFolder = EditorGUILayout.ToggleLeft( "Project window (Assets folder)", searchInAssetsFolder );
|
||||||
|
|
||||||
if( searchInAssetsFolder )
|
if( searchInAssetsFolder )
|
||||||
{
|
{
|
||||||
@@ -306,7 +333,7 @@ namespace AssetUsageDetectorNamespace.Extras
|
|||||||
searchInAssetsSubsetDrawer.Draw( searchInAssetsSubset );
|
searchInAssetsSubsetDrawer.Draw( searchInAssetsSubset );
|
||||||
excludedAssetsDrawer.Draw( excludedAssets );
|
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.EndVertical();
|
||||||
GUILayout.EndHorizontal();
|
GUILayout.EndHorizontal();
|
||||||
@@ -350,58 +377,66 @@ namespace AssetUsageDetectorNamespace.Extras
|
|||||||
|
|
||||||
GUILayout.Space( 10 );
|
GUILayout.Space( 10 );
|
||||||
|
|
||||||
GUILayout.Box( "SEARCH SETTINGS", Utilities.BoxGUIStyle, Utilities.GL_EXPAND_WIDTH );
|
//GUILayout.Box( "SEARCH SETTINGS", Utilities.BoxGUIStyle, Utilities.GL_EXPAND_WIDTH );
|
||||||
|
|
||||||
GUILayout.BeginHorizontal();
|
//GUILayout.BeginHorizontal();
|
||||||
|
|
||||||
GUILayout.Label( new GUIContent( "> Search depth: " + searchDepthLimit, "Depth limit for recursively searching variables of objects" ), Utilities.GL_WIDTH_250 );
|
//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 );
|
//searchDepthLimit = (int) GUILayout.HorizontalSlider( searchDepthLimit, 0, 4 );
|
||||||
|
|
||||||
GUILayout.EndHorizontal();
|
//GUILayout.EndHorizontal();
|
||||||
|
|
||||||
GUILayout.Label( "> Search variables:" );
|
//GUILayout.Label( "> Search variables:" );
|
||||||
|
|
||||||
GUILayout.BeginHorizontal();
|
//GUILayout.BeginHorizontal();
|
||||||
|
|
||||||
GUILayout.Space( 35 );
|
//GUILayout.Space( 35 );
|
||||||
|
|
||||||
if( EditorGUILayout.ToggleLeft( "Public", ( fieldModifiers & BindingFlags.Public ) == BindingFlags.Public, Utilities.GL_WIDTH_100 ) )
|
//if( EditorGUILayout.ToggleLeft( "Public", ( fieldModifiers & BindingFlags.Public ) == BindingFlags.Public, Utilities.GL_WIDTH_100 ) )
|
||||||
fieldModifiers |= BindingFlags.Public;
|
// fieldModifiers |= BindingFlags.Public;
|
||||||
else
|
//else
|
||||||
fieldModifiers &= ~BindingFlags.Public;
|
// fieldModifiers &= ~BindingFlags.Public;
|
||||||
|
|
||||||
if( EditorGUILayout.ToggleLeft( "Non-public", ( fieldModifiers & BindingFlags.NonPublic ) == BindingFlags.NonPublic, Utilities.GL_WIDTH_100 ) )
|
//if( EditorGUILayout.ToggleLeft( "Non-public", ( fieldModifiers & BindingFlags.NonPublic ) == BindingFlags.NonPublic, Utilities.GL_WIDTH_100 ) )
|
||||||
fieldModifiers |= BindingFlags.NonPublic;
|
// fieldModifiers |= BindingFlags.NonPublic;
|
||||||
else
|
//else
|
||||||
fieldModifiers &= ~BindingFlags.NonPublic;
|
// fieldModifiers &= ~BindingFlags.NonPublic;
|
||||||
|
|
||||||
GUILayout.EndHorizontal();
|
//GUILayout.EndHorizontal();
|
||||||
|
|
||||||
GUILayout.Label( "> Search properties:" );
|
//GUILayout.Label( "> Search properties:" );
|
||||||
|
|
||||||
GUILayout.BeginHorizontal();
|
//GUILayout.BeginHorizontal();
|
||||||
|
|
||||||
GUILayout.Space( 35 );
|
//GUILayout.Space( 35 );
|
||||||
|
|
||||||
if( EditorGUILayout.ToggleLeft( "Public", ( propertyModifiers & BindingFlags.Public ) == BindingFlags.Public, Utilities.GL_WIDTH_100 ) )
|
//if( EditorGUILayout.ToggleLeft( "Public", ( propertyModifiers & BindingFlags.Public ) == BindingFlags.Public, Utilities.GL_WIDTH_100 ) )
|
||||||
propertyModifiers |= BindingFlags.Public;
|
// propertyModifiers |= BindingFlags.Public;
|
||||||
else
|
//else
|
||||||
propertyModifiers &= ~BindingFlags.Public;
|
// propertyModifiers &= ~BindingFlags.Public;
|
||||||
|
|
||||||
if( EditorGUILayout.ToggleLeft( "Non-public", ( propertyModifiers & BindingFlags.NonPublic ) == BindingFlags.NonPublic, Utilities.GL_WIDTH_100 ) )
|
//if( EditorGUILayout.ToggleLeft( "Non-public", ( propertyModifiers & BindingFlags.NonPublic ) == BindingFlags.NonPublic, Utilities.GL_WIDTH_100 ) )
|
||||||
propertyModifiers |= BindingFlags.NonPublic;
|
// propertyModifiers |= BindingFlags.NonPublic;
|
||||||
else
|
//else
|
||||||
propertyModifiers &= ~BindingFlags.NonPublic;
|
// propertyModifiers &= ~BindingFlags.NonPublic;
|
||||||
|
|
||||||
GUILayout.EndHorizontal();
|
//GUILayout.EndHorizontal();
|
||||||
|
|
||||||
|
//GUILayout.Space( 10 );
|
||||||
|
|
||||||
|
//searchNonSerializableVariables = EditorGUILayout.ToggleLeft( "Search non-serializable fields and properties", searchNonSerializableVariables );
|
||||||
|
|
||||||
|
//GUILayout.Space( 10 );
|
||||||
|
|
||||||
|
GUILayout.Box( "SETTINGS", Utilities.BoxGUIStyle, Utilities.GL_EXPAND_WIDTH );
|
||||||
|
|
||||||
|
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 );
|
||||||
|
showDetailedProgressBar = EditorGUILayout.ToggleLeft( "Show detailed progress bar (slower search)", showDetailedProgressBar );
|
||||||
|
|
||||||
GUILayout.Space( 10 );
|
GUILayout.Space( 10 );
|
||||||
|
|
||||||
searchNonSerializableVariables = EditorGUILayout.ToggleLeft( "Include non-serializable fields and properties in search (slower search)", searchNonSerializableVariables );
|
|
||||||
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 );
|
|
||||||
|
|
||||||
// Don't let the user press the GO button without any valid search location
|
// Don't let the user press the GO button without any valid search location
|
||||||
if( !searchInAllScenes && !searchInOpenScenes && !searchInScenesInBuild && !searchInAssetsFolder )
|
if( !searchInAllScenes && !searchInOpenScenes && !searchInScenesInBuild && !searchInAssetsFolder )
|
||||||
GUI.enabled = false;
|
GUI.enabled = false;
|
||||||
@@ -437,35 +472,39 @@ namespace AssetUsageDetectorNamespace.Extras
|
|||||||
GUILayout.Box( "Don't forget to save scene(s) if you made any changes!", Utilities.BoxGUIStyle, Utilities.GL_EXPAND_WIDTH );
|
GUILayout.Box( "Don't forget to save scene(s) if you made any changes!", Utilities.BoxGUIStyle, Utilities.GL_EXPAND_WIDTH );
|
||||||
GUI.color = c;
|
GUI.color = c;
|
||||||
|
|
||||||
GUILayout.Space( 10 );
|
|
||||||
|
|
||||||
if( searchResult.NumberOfGroups == 0 )
|
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
|
else
|
||||||
{
|
{
|
||||||
GUILayout.BeginHorizontal();
|
//GUILayout.Space( 10 );
|
||||||
|
//GUILayout.BeginHorizontal();
|
||||||
|
|
||||||
// Select all the references after filtering them (select only the GameObject's)
|
//// Select all the references after filtering them (select only the GameObject's)
|
||||||
if( GUILayout.Button( "Select All\n(GameObject-wise)", Utilities.GL_HEIGHT_35 ) )
|
//if( GUILayout.Button( "Select All\n(GameObject-wise)", Utilities.GL_HEIGHT_35 ) )
|
||||||
{
|
//{
|
||||||
GameObject[] objects = searchResult.SelectAllAsGameObjects();
|
// GameObject[] objects = searchResult.SelectAllAsGameObjects();
|
||||||
if( objects != null && objects.Length > 0 )
|
// if( objects != null && objects.Length > 0 )
|
||||||
Selection.objects = objects;
|
// Selection.objects = objects;
|
||||||
}
|
//}
|
||||||
|
|
||||||
// Select all the references without filtering them
|
//// Select all the references without filtering them
|
||||||
if( GUILayout.Button( "Select All\n(Object-wise)", Utilities.GL_HEIGHT_35 ) )
|
//if( GUILayout.Button( "Select All\n(Object-wise)", Utilities.GL_HEIGHT_35 ) )
|
||||||
{
|
//{
|
||||||
Object[] objects = searchResult.SelectAllAsObjects();
|
// Object[] objects = searchResult.SelectAllAsObjects();
|
||||||
if( objects != null && objects.Length > 0 )
|
// if( objects != null && objects.Length > 0 )
|
||||||
Selection.objects = objects;
|
// 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( "Show tooltips", 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 );
|
GUILayout.Space( 10 );
|
||||||
|
|
||||||
@@ -475,7 +514,7 @@ namespace AssetUsageDetectorNamespace.Extras
|
|||||||
|
|
||||||
GUILayout.Space( 35 );
|
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;
|
searchResultDrawParameters.pathDrawingMode = PathDrawingMode.Full;
|
||||||
|
|
||||||
GUILayout.EndHorizontal();
|
GUILayout.EndHorizontal();
|
||||||
@@ -525,22 +564,45 @@ namespace AssetUsageDetectorNamespace.Extras
|
|||||||
|
|
||||||
SavePrefs();
|
SavePrefs();
|
||||||
|
|
||||||
|
#if UNITY_2018_3_OR_NEWER
|
||||||
|
// Try replacing prefab stage objects with their corresponding prefab assets
|
||||||
|
var openPrefabStage = UnityEditor.Experimental.SceneManagement.PrefabStageUtility.GetCurrentPrefabStage();
|
||||||
|
if( openPrefabStage != null && openPrefabStage.stageHandle.IsValid() )
|
||||||
|
{
|
||||||
|
GameObject openPrefabStagePrefabAsset = AssetDatabase.LoadAssetAtPath<GameObject>( openPrefabStage.prefabAssetPath );
|
||||||
|
if( openPrefabStagePrefabAsset != null )
|
||||||
|
{
|
||||||
|
for( int i = 0; i < objectsToSearch.Count; i++ )
|
||||||
|
{
|
||||||
|
if( objectsToSearch[i].obj != null && !objectsToSearch[i].obj.Equals( null ) &&
|
||||||
|
objectsToSearch[i].obj is GameObject && openPrefabStage.IsPartOfPrefabContents( (GameObject) objectsToSearch[i].obj ) )
|
||||||
|
{
|
||||||
|
GameObject prefabStageObjectSource = ( (GameObject) objectsToSearch[i].obj ).FollowSymmetricHierarchy( openPrefabStagePrefabAsset );
|
||||||
|
if( prefabStageObjectSource != null )
|
||||||
|
objectsToSearch[i].obj = prefabStageObjectSource;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
// Start searching
|
// Start searching
|
||||||
searchResult = core.Run( new AssetUsageDetector.Parameters()
|
searchResult = core.Run( new AssetUsageDetector.Parameters()
|
||||||
{
|
{
|
||||||
objectsToSearch = !objectsToSearch.IsEmpty() ? new ObjectToSearchEnumerator( objectsToSearch ) : null,
|
objectsToSearch = new ObjectToSearchEnumerator( objectsToSearch ).ToArray(),
|
||||||
searchInScenes = GetSceneSearchMode( true ),
|
searchInScenes = GetSceneSearchMode( true ),
|
||||||
searchInAssetsFolder = searchInAssetsFolder,
|
searchInAssetsFolder = searchInAssetsFolder,
|
||||||
searchInAssetsSubset = !searchInAssetsSubset.IsEmpty() ? searchInAssetsSubset : null,
|
searchInAssetsSubset = !searchInAssetsSubset.IsEmpty() ? searchInAssetsSubset.ToArray() : null,
|
||||||
excludedAssetsFromSearch = !excludedAssets.IsEmpty() ? excludedAssets : null,
|
excludedAssetsFromSearch = !excludedAssets.IsEmpty() ? excludedAssets.ToArray() : null,
|
||||||
dontSearchInSourceAssets = dontSearchInSourceAssets,
|
dontSearchInSourceAssets = dontSearchInSourceAssets,
|
||||||
excludedScenesFromSearch = !excludedScenes.IsEmpty() ? excludedScenes : null,
|
excludedScenesFromSearch = !excludedScenes.IsEmpty() ? excludedScenes.ToArray() : null,
|
||||||
fieldModifiers = fieldModifiers,
|
//fieldModifiers = fieldModifiers,
|
||||||
propertyModifiers = propertyModifiers,
|
//propertyModifiers = propertyModifiers,
|
||||||
searchDepthLimit = searchDepthLimit,
|
//searchDepthLimit = searchDepthLimit,
|
||||||
searchNonSerializableVariables = searchNonSerializableVariables,
|
//searchNonSerializableVariables = searchNonSerializableVariables,
|
||||||
|
lazySceneSearch = lazySceneSearch,
|
||||||
noAssetDatabaseChanges = noAssetDatabaseChanges,
|
noAssetDatabaseChanges = noAssetDatabaseChanges,
|
||||||
showProgressBar = showProgressBar
|
showDetailedProgressBar = showDetailedProgressBar
|
||||||
} );
|
} );
|
||||||
|
|
||||||
currentPhase = Phase.Complete;
|
currentPhase = Phase.Complete;
|
||||||
|
|||||||
@@ -112,5 +112,19 @@ namespace AssetUsageDetectorNamespace.Extras
|
|||||||
{
|
{
|
||||||
return GetEnumerator();
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -46,8 +46,22 @@ namespace AssetUsageDetectorNamespace.Extras
|
|||||||
{
|
{
|
||||||
if( draggedObjects[i] != null && !draggedObjects[i].Equals( null ) )
|
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;
|
hasChanged = true;
|
||||||
list.Add( CreateElement( draggedObjects[i] ) );
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -107,6 +121,7 @@ namespace AssetUsageDetectorNamespace.Extras
|
|||||||
protected abstract T CreateElement( Object source );
|
protected abstract T CreateElement( Object source );
|
||||||
protected abstract Object GetObjectFromElement( T element );
|
protected abstract Object GetObjectFromElement( T element );
|
||||||
protected abstract void SetObjectOfElement( List<T> list, int index, Object value );
|
protected abstract void SetObjectOfElement( List<T> list, int index, Object value );
|
||||||
|
protected abstract bool IsElementNull( T element );
|
||||||
protected abstract void PostElementDrawer( T element );
|
protected abstract void PostElementDrawer( T element );
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -131,6 +146,11 @@ namespace AssetUsageDetectorNamespace.Extras
|
|||||||
list[index] = value;
|
list[index] = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected override bool IsElementNull( Object element )
|
||||||
|
{
|
||||||
|
return element == null || element.Equals( null );
|
||||||
|
}
|
||||||
|
|
||||||
protected override void PostElementDrawer( Object element )
|
protected override void PostElementDrawer( Object element )
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
@@ -138,7 +158,7 @@ namespace AssetUsageDetectorNamespace.Extras
|
|||||||
|
|
||||||
public class ObjectToSearchListDrawer : ListDrawer<ObjectToSearch>
|
public class ObjectToSearchListDrawer : ListDrawer<ObjectToSearch>
|
||||||
{
|
{
|
||||||
public ObjectToSearchListDrawer() : base( "Asset(s):", true )
|
public ObjectToSearchListDrawer() : base( "Find references of:", true )
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -158,6 +178,11 @@ namespace AssetUsageDetectorNamespace.Extras
|
|||||||
list[index].RefreshSubAssets();
|
list[index].RefreshSubAssets();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected override bool IsElementNull( ObjectToSearch element )
|
||||||
|
{
|
||||||
|
return element == null || element.obj == null || element.obj.Equals( null );
|
||||||
|
}
|
||||||
|
|
||||||
protected override void PostElementDrawer( ObjectToSearch element )
|
protected override void PostElementDrawer( ObjectToSearch element )
|
||||||
{
|
{
|
||||||
List<ObjectToSearch.SubAsset> subAssetsToSearch = element.subAssets;
|
List<ObjectToSearch.SubAsset> subAssetsToSearch = element.subAssets;
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ using System.Collections.Generic;
|
|||||||
using UnityEditor;
|
using UnityEditor;
|
||||||
using UnityEditor.SceneManagement;
|
using UnityEditor.SceneManagement;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
using UnityEngine.SceneManagement;
|
||||||
using Object = UnityEngine.Object;
|
using Object = UnityEngine.Object;
|
||||||
|
|
||||||
namespace AssetUsageDetectorNamespace
|
namespace AssetUsageDetectorNamespace
|
||||||
@@ -11,14 +12,19 @@ namespace AssetUsageDetectorNamespace
|
|||||||
[Serializable]
|
[Serializable]
|
||||||
public class SearchResultDrawParameters
|
public class SearchResultDrawParameters
|
||||||
{
|
{
|
||||||
|
public SearchResult searchResult;
|
||||||
public PathDrawingMode pathDrawingMode;
|
public PathDrawingMode pathDrawingMode;
|
||||||
public bool showTooltips;
|
public bool showTooltips;
|
||||||
|
public bool noAssetDatabaseChanges;
|
||||||
|
public Rect guiRect;
|
||||||
|
public bool shouldRefreshEditorWindow;
|
||||||
public string tooltip;
|
public string tooltip;
|
||||||
|
|
||||||
public SearchResultDrawParameters( PathDrawingMode pathDrawingMode, bool showTooltips )
|
public SearchResultDrawParameters( PathDrawingMode pathDrawingMode, bool showTooltips, bool noAssetDatabaseChanges )
|
||||||
{
|
{
|
||||||
this.pathDrawingMode = pathDrawingMode;
|
this.pathDrawingMode = pathDrawingMode;
|
||||||
this.showTooltips = showTooltips;
|
this.showTooltips = showTooltips;
|
||||||
|
this.noAssetDatabaseChanges = noAssetDatabaseChanges;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -31,7 +37,9 @@ namespace AssetUsageDetectorNamespace
|
|||||||
public class SerializableResultGroup
|
public class SerializableResultGroup
|
||||||
{
|
{
|
||||||
public string title;
|
public string title;
|
||||||
public bool clickable;
|
public SearchResultGroup.GroupType type;
|
||||||
|
public bool isExpanded;
|
||||||
|
public bool pendingSearch;
|
||||||
|
|
||||||
public List<int> initialSerializedNodes;
|
public List<int> initialSerializedNodes;
|
||||||
}
|
}
|
||||||
@@ -47,10 +55,20 @@ namespace AssetUsageDetectorNamespace
|
|||||||
public List<string> linkDescriptions;
|
public List<string> linkDescriptions;
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool success;
|
#pragma warning disable 1692
|
||||||
|
#pragma warning disable IDE0044
|
||||||
|
private bool success; // This is not readonly so that it can be serialized
|
||||||
|
#pragma warning restore IDE0044
|
||||||
|
#pragma warning restore 1692
|
||||||
|
|
||||||
private List<SearchResultGroup> result;
|
private List<SearchResultGroup> result;
|
||||||
private SceneSetup[] initialSceneSetup;
|
private SceneSetup[] initialSceneSetup;
|
||||||
|
|
||||||
|
private AssetUsageDetector searchHandler;
|
||||||
|
private AssetUsageDetector.Parameters m_searchParameters;
|
||||||
|
|
||||||
|
private float guiHeight; // Prevents scroll view's position from getting reset at domain reload
|
||||||
|
|
||||||
private List<SerializableNode> serializedNodes;
|
private List<SerializableNode> serializedNodes;
|
||||||
private List<SerializableResultGroup> serializedGroups;
|
private List<SerializableResultGroup> serializedGroups;
|
||||||
|
|
||||||
@@ -59,8 +77,9 @@ namespace AssetUsageDetectorNamespace
|
|||||||
|
|
||||||
public bool SearchCompletedSuccessfully { get { return success; } }
|
public bool SearchCompletedSuccessfully { get { return success; } }
|
||||||
public bool InitialSceneSetupConfigured { get { return initialSceneSetup != null && initialSceneSetup.Length > 0; } }
|
public bool InitialSceneSetupConfigured { get { return initialSceneSetup != null && initialSceneSetup.Length > 0; } }
|
||||||
|
public AssetUsageDetector.Parameters SearchParameters { get { return m_searchParameters; } }
|
||||||
|
|
||||||
public SearchResult( bool success, List<SearchResultGroup> result, SceneSetup[] initialSceneSetup )
|
public SearchResult( bool success, List<SearchResultGroup> result, SceneSetup[] initialSceneSetup, AssetUsageDetector searchHandler, AssetUsageDetector.Parameters searchParameters )
|
||||||
{
|
{
|
||||||
if( result == null )
|
if( result == null )
|
||||||
result = new List<SearchResultGroup>( 0 );
|
result = new List<SearchResultGroup>( 0 );
|
||||||
@@ -68,15 +87,137 @@ namespace AssetUsageDetectorNamespace
|
|||||||
this.success = success;
|
this.success = success;
|
||||||
this.result = result;
|
this.result = result;
|
||||||
this.initialSceneSetup = initialSceneSetup;
|
this.initialSceneSetup = initialSceneSetup;
|
||||||
|
this.searchHandler = searchHandler;
|
||||||
|
this.m_searchParameters = searchParameters;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void RefreshSearchResultGroup( SearchResultGroup searchResultGroup, bool noAssetDatabaseChanges )
|
||||||
|
{
|
||||||
|
if( searchResultGroup == null )
|
||||||
|
{
|
||||||
|
Debug.LogError( "SearchResultGroup is null!" );
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
int searchResultGroupIndex = -1;
|
||||||
|
for( int i = 0; i < result.Count; i++ )
|
||||||
|
{
|
||||||
|
if( result[i] == searchResultGroup )
|
||||||
|
{
|
||||||
|
searchResultGroupIndex = i;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if( searchResultGroupIndex < 0 )
|
||||||
|
{
|
||||||
|
Debug.LogError( "SearchResultGroup is not a part of SearchResult!" );
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if( searchResultGroup.Type == SearchResultGroup.GroupType.Scene && EditorApplication.isPlaying && !EditorSceneManager.GetSceneByPath( searchResultGroup.Title ).isLoaded )
|
||||||
|
{
|
||||||
|
Debug.LogError( "Can't search unloaded scene while in Play Mode!" );
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if( searchHandler == null )
|
||||||
|
searchHandler = new AssetUsageDetector();
|
||||||
|
|
||||||
|
SceneSearchMode searchInScenes = m_searchParameters.searchInScenes;
|
||||||
|
Object[] searchInScenesSubset = m_searchParameters.searchInScenesSubset;
|
||||||
|
bool searchInAssetsFolder = m_searchParameters.searchInAssetsFolder;
|
||||||
|
Object[] searchInAssetsSubset = m_searchParameters.searchInAssetsSubset;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if( searchResultGroup.Type == SearchResultGroup.GroupType.Assets )
|
||||||
|
{
|
||||||
|
m_searchParameters.searchInScenes = SceneSearchMode.None;
|
||||||
|
m_searchParameters.searchInScenesSubset = null;
|
||||||
|
}
|
||||||
|
else if( searchResultGroup.Type == SearchResultGroup.GroupType.Scene )
|
||||||
|
{
|
||||||
|
m_searchParameters.searchInScenes = SceneSearchMode.None;
|
||||||
|
m_searchParameters.searchInScenesSubset = new Object[1] { AssetDatabase.LoadAssetAtPath<SceneAsset>( searchResultGroup.Title ) };
|
||||||
|
m_searchParameters.searchInAssetsFolder = false;
|
||||||
|
m_searchParameters.searchInAssetsSubset = null;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
m_searchParameters.searchInScenes = (SceneSearchMode) 1024; // A unique value to search only the DontDestroyOnLoad scene
|
||||||
|
m_searchParameters.searchInScenesSubset = null;
|
||||||
|
m_searchParameters.searchInAssetsFolder = false;
|
||||||
|
m_searchParameters.searchInAssetsSubset = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
m_searchParameters.lazySceneSearch = false;
|
||||||
|
m_searchParameters.noAssetDatabaseChanges = noAssetDatabaseChanges;
|
||||||
|
|
||||||
|
// Make sure the AssetDatabase is up-to-date
|
||||||
|
AssetDatabase.SaveAssets();
|
||||||
|
|
||||||
|
SearchResult searchResult = searchHandler.Run( m_searchParameters );
|
||||||
|
if( !searchResult.success )
|
||||||
|
{
|
||||||
|
EditorUtility.DisplayDialog( "Error", "Couldn't refresh, check console for more info.", "OK" );
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
List<SearchResultGroup> searchResultGroups = searchResult.result;
|
||||||
|
if( searchResultGroups != null )
|
||||||
|
{
|
||||||
|
int newSearchResultGroupIndex = -1;
|
||||||
|
for( int i = 0; i < searchResultGroups.Count; i++ )
|
||||||
|
{
|
||||||
|
if( searchResultGroup.Title == searchResultGroups[i].Title )
|
||||||
|
{
|
||||||
|
newSearchResultGroupIndex = i;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if( newSearchResultGroupIndex >= 0 )
|
||||||
|
result[searchResultGroupIndex] = searchResultGroups[newSearchResultGroupIndex];
|
||||||
|
else
|
||||||
|
searchResultGroup.Clear();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
m_searchParameters.searchInScenes = searchInScenes;
|
||||||
|
m_searchParameters.searchInScenesSubset = searchInScenesSubset;
|
||||||
|
m_searchParameters.searchInAssetsFolder = searchInAssetsFolder;
|
||||||
|
m_searchParameters.searchInAssetsSubset = searchInAssetsSubset;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void DrawOnGUI( SearchResultDrawParameters parameters )
|
public void DrawOnGUI( SearchResultDrawParameters parameters )
|
||||||
{
|
{
|
||||||
|
parameters.searchResult = this;
|
||||||
parameters.tooltip = null;
|
parameters.tooltip = null;
|
||||||
|
parameters.guiRect = EditorGUILayout.GetControlRect( Utilities.GL_EXPAND_WIDTH, Utilities.GL_HEIGHT_0 );
|
||||||
|
|
||||||
|
float guiInitialY = parameters.guiRect.y;
|
||||||
|
|
||||||
for( int i = 0; i < result.Count; i++ )
|
for( int i = 0; i < result.Count; i++ )
|
||||||
|
{
|
||||||
result[i].DrawOnGUI( parameters );
|
result[i].DrawOnGUI( parameters );
|
||||||
|
|
||||||
|
if( i < result.Count - 1 )
|
||||||
|
{
|
||||||
|
Rect rect = parameters.guiRect;
|
||||||
|
rect.y += 10f;
|
||||||
|
parameters.guiRect = rect;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if( Event.current.type == EventType.Repaint )
|
||||||
|
guiHeight = parameters.guiRect.y - guiInitialY;
|
||||||
|
|
||||||
|
// To work nicely with GUILayout and scroll view
|
||||||
|
EditorGUILayout.GetControlRect( Utilities.GL_EXPAND_WIDTH, GUILayout.Height( guiHeight ) );
|
||||||
|
|
||||||
if( parameters.tooltip != null )
|
if( parameters.tooltip != null )
|
||||||
{
|
{
|
||||||
// Show tooltip at mouse position
|
// Show tooltip at mouse position
|
||||||
@@ -86,6 +227,19 @@ namespace AssetUsageDetectorNamespace
|
|||||||
|
|
||||||
GUI.Box( new Rect( new Vector2( mousePos.x - size.x * 0.5f, mousePos.y - size.y ), size ), parameters.tooltip, Utilities.TooltipGUIStyle );
|
GUI.Box( new Rect( new Vector2( mousePos.x - size.x * 0.5f, mousePos.y - size.y ), size ), parameters.tooltip, Utilities.TooltipGUIStyle );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if( parameters.shouldRefreshEditorWindow )
|
||||||
|
{
|
||||||
|
parameters.shouldRefreshEditorWindow = false;
|
||||||
|
|
||||||
|
EditorWindow focusedWindow = EditorWindow.focusedWindow;
|
||||||
|
if( focusedWindow != null )
|
||||||
|
focusedWindow.Repaint();
|
||||||
|
|
||||||
|
EditorWindow mouseOverWindow = EditorWindow.mouseOverWindow;
|
||||||
|
if( mouseOverWindow != null && mouseOverWindow != focusedWindow )
|
||||||
|
mouseOverWindow.Repaint();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Object[] SelectAllAsObjects()
|
public Object[] SelectAllAsObjects()
|
||||||
@@ -164,6 +318,16 @@ namespace AssetUsageDetectorNamespace
|
|||||||
if( EditorApplication.isPlaying || !EditorSceneManager.SaveCurrentModifiedScenesIfUserWantsTo() )
|
if( EditorApplication.isPlaying || !EditorSceneManager.SaveCurrentModifiedScenesIfUserWantsTo() )
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
for( int i = 0; i < initialSceneSetup.Length; i++ )
|
||||||
|
{
|
||||||
|
Scene scene = EditorSceneManager.GetSceneByPath( initialSceneSetup[i].path );
|
||||||
|
if( !scene.isLoaded )
|
||||||
|
scene = EditorSceneManager.OpenScene( initialSceneSetup[i].path, initialSceneSetup[i].isLoaded ? OpenSceneMode.Additive : OpenSceneMode.AdditiveWithoutLoading );
|
||||||
|
|
||||||
|
if( initialSceneSetup[i].isActive )
|
||||||
|
EditorSceneManager.SetActiveScene( scene );
|
||||||
|
}
|
||||||
|
|
||||||
SceneSetup[] sceneFinalSetup = EditorSceneManager.GetSceneManagerSetup();
|
SceneSetup[] sceneFinalSetup = EditorSceneManager.GetSceneManagerSetup();
|
||||||
for( int i = 0; i < sceneFinalSetup.Length; i++ )
|
for( int i = 0; i < sceneFinalSetup.Length; i++ )
|
||||||
{
|
{
|
||||||
@@ -232,7 +396,7 @@ namespace AssetUsageDetectorNamespace
|
|||||||
|
|
||||||
for( int i = 0; i < serializedGroups.Count; i++ )
|
for( int i = 0; i < serializedGroups.Count; i++ )
|
||||||
{
|
{
|
||||||
result.Add( new SearchResultGroup( serializedGroups[i].title, serializedGroups[i].clickable ) );
|
result.Add( new SearchResultGroup( serializedGroups[i].title, serializedGroups[i].type, serializedGroups[i].isExpanded, serializedGroups[i].pendingSearch ) );
|
||||||
result[i].Deserialize( serializedGroups[i], allNodes );
|
result[i].Deserialize( serializedGroups[i], allNodes );
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -244,6 +408,8 @@ namespace AssetUsageDetectorNamespace
|
|||||||
// Custom class to hold the results for a single scene or Assets folder
|
// Custom class to hold the results for a single scene or Assets folder
|
||||||
public class SearchResultGroup
|
public class SearchResultGroup
|
||||||
{
|
{
|
||||||
|
public enum GroupType { Assets = 0, Scene = 1, DontDestroyOnLoad = 2 };
|
||||||
|
|
||||||
// Custom struct to hold a single path to a reference
|
// Custom struct to hold a single path to a reference
|
||||||
public struct ReferencePath
|
public struct ReferencePath
|
||||||
{
|
{
|
||||||
@@ -257,24 +423,38 @@ namespace AssetUsageDetectorNamespace
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private readonly string title;
|
private const float HEADER_HEIGHT = 40f;
|
||||||
private readonly bool clickable;
|
|
||||||
|
public string Title { get; private set; }
|
||||||
|
public GroupType Type { get; private set; }
|
||||||
|
public bool IsExpanded { get; private set; }
|
||||||
|
public bool PendingSearch { get; private set; }
|
||||||
|
|
||||||
private readonly List<ReferenceNode> references;
|
private readonly List<ReferenceNode> references;
|
||||||
private List<ReferencePath> referencePathsShortUnique;
|
private List<ReferencePath> referencePathsShortUnique;
|
||||||
private List<ReferencePath> referencePathsShortest;
|
private List<ReferencePath> referencePathsShortest;
|
||||||
|
|
||||||
|
private float calculatedGUIWidth;
|
||||||
|
private float calculatedGUIHeight;
|
||||||
|
private PathDrawingMode calculatedGUIMode;
|
||||||
|
private ReferenceNodeGUI[] guiNodes;
|
||||||
|
|
||||||
public int NumberOfReferences { get { return references.Count; } }
|
public int NumberOfReferences { get { return references.Count; } }
|
||||||
public ReferenceNode this[int index] { get { return references[index]; } }
|
public ReferenceNode this[int index] { get { return references[index]; } }
|
||||||
|
|
||||||
public SearchResultGroup( string title, bool clickable )
|
public SearchResultGroup( string title, GroupType type, bool isExpanded = true, bool pendingSearch = false )
|
||||||
{
|
{
|
||||||
this.title = title;
|
Title = title;
|
||||||
this.clickable = clickable;
|
Type = type;
|
||||||
|
IsExpanded = isExpanded;
|
||||||
|
PendingSearch = pendingSearch;
|
||||||
|
|
||||||
references = new List<ReferenceNode>();
|
references = new List<ReferenceNode>();
|
||||||
referencePathsShortUnique = null;
|
referencePathsShortUnique = null;
|
||||||
referencePathsShortest = null;
|
referencePathsShortest = null;
|
||||||
|
|
||||||
|
calculatedGUIWidth = 0f;
|
||||||
|
guiNodes = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add a reference to the list
|
// Add a reference to the list
|
||||||
@@ -283,6 +463,21 @@ namespace AssetUsageDetectorNamespace
|
|||||||
references.Add( node );
|
references.Add( node );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Removes all nodes
|
||||||
|
public void Clear()
|
||||||
|
{
|
||||||
|
references.Clear();
|
||||||
|
|
||||||
|
if( referencePathsShortUnique != null )
|
||||||
|
referencePathsShortUnique.Clear();
|
||||||
|
if( referencePathsShortest != null )
|
||||||
|
referencePathsShortest.Clear();
|
||||||
|
|
||||||
|
PendingSearch = false;
|
||||||
|
calculatedGUIWidth = 0f;
|
||||||
|
guiNodes = null;
|
||||||
|
}
|
||||||
|
|
||||||
// Initializes commonly used variables of the nodes
|
// Initializes commonly used variables of the nodes
|
||||||
public void InitializeNodes( Func<object, ReferenceNode> nodeGetter )
|
public void InitializeNodes( Func<object, ReferenceNode> nodeGetter )
|
||||||
{
|
{
|
||||||
@@ -299,10 +494,24 @@ namespace AssetUsageDetectorNamespace
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for( int i = references.Count - 1; i >= 0; i-- )
|
||||||
|
{
|
||||||
|
references[i].VerifyLinksRecursively();
|
||||||
|
|
||||||
|
// Some links might be removed during verification
|
||||||
|
if( references[i].NumberOfOutgoingLinks == 0 )
|
||||||
|
references.RemoveAtFast( i );
|
||||||
|
}
|
||||||
|
|
||||||
|
if( references.Count == 0 )
|
||||||
|
return;
|
||||||
|
|
||||||
|
List<ReferenceNode> callStack = new List<ReferenceNode>( 8 );
|
||||||
|
|
||||||
// For simplicity's sake, get rid of root nodes that are already part of another node's hierarchy
|
// For simplicity's sake, get rid of root nodes that are already part of another node's hierarchy
|
||||||
for( int i = references.Count - 1; i >= 0; i-- )
|
for( int i = references.Count - 1; i >= 0; i-- )
|
||||||
{
|
{
|
||||||
if( IsRootNodePartOfAnotherRootNode( i ) )
|
if( IsRootNodePartOfAnotherRootNode( i, callStack ) )
|
||||||
references.RemoveAtFast( i );
|
references.RemoveAtFast( i );
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -320,6 +529,10 @@ namespace AssetUsageDetectorNamespace
|
|||||||
if( mainAsset == null || mainAsset.Equals( null ) )
|
if( mainAsset == null || mainAsset.Equals( null ) )
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
// We're already calling AssetDatabase.IsMainAsset but just in case...
|
||||||
|
if( ReferenceEquals( nodeObject, mainAsset ) )
|
||||||
|
continue;
|
||||||
|
|
||||||
if( nodeObject is Component && ( (Component) nodeObject ).gameObject == mainAsset )
|
if( nodeObject is Component && ( (Component) nodeObject ).gameObject == mainAsset )
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
@@ -329,12 +542,12 @@ namespace AssetUsageDetectorNamespace
|
|||||||
references[i] = newRootNode;
|
references[i] = newRootNode;
|
||||||
|
|
||||||
// Make sure that the new root node isn't already a part of another node's hierarchy
|
// Make sure that the new root node isn't already a part of another node's hierarchy
|
||||||
if( IsRootNodePartOfAnotherRootNode( i ) )
|
if( IsRootNodePartOfAnotherRootNode( i, callStack ) )
|
||||||
references.RemoveAtFast( i );
|
references.RemoveAtFast( i );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for( int i = references.Count - 1; i >= 0; i-- )
|
for( int i = 0; i < references.Count; i++ )
|
||||||
references[i].InitializeRecursively();
|
references[i].InitializeRecursively();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -350,7 +563,7 @@ namespace AssetUsageDetectorNamespace
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool IsRootNodePartOfAnotherRootNode( int index )
|
private bool IsRootNodePartOfAnotherRootNode( int index, List<ReferenceNode> callStack )
|
||||||
{
|
{
|
||||||
ReferenceNode node = references[index];
|
ReferenceNode node = references[index];
|
||||||
for( int i = references.Count - 1; i >= 0; i-- )
|
for( int i = references.Count - 1; i >= 0; i-- )
|
||||||
@@ -358,7 +571,7 @@ namespace AssetUsageDetectorNamespace
|
|||||||
if( index == i )
|
if( index == i )
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if( references[i].nodeObject == node.nodeObject || references[i].NodeExistsInChildrenRecursive( node ) )
|
if( references[i].nodeObject == node.nodeObject || references[i].NodeExistsInChildrenRecursive( node, callStack ) )
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -368,6 +581,9 @@ namespace AssetUsageDetectorNamespace
|
|||||||
// Add all the Object's in this container to the set
|
// Add all the Object's in this container to the set
|
||||||
public void AddObjectsTo( HashSet<Object> objectsSet )
|
public void AddObjectsTo( HashSet<Object> objectsSet )
|
||||||
{
|
{
|
||||||
|
if( PendingSearch )
|
||||||
|
return;
|
||||||
|
|
||||||
CalculateShortestPathsToReferences();
|
CalculateShortestPathsToReferences();
|
||||||
|
|
||||||
for( int i = 0; i < referencePathsShortUnique.Count; i++ )
|
for( int i = 0; i < referencePathsShortUnique.Count; i++ )
|
||||||
@@ -381,6 +597,9 @@ namespace AssetUsageDetectorNamespace
|
|||||||
// Add all the GameObject's in this container to the set
|
// Add all the GameObject's in this container to the set
|
||||||
public void AddGameObjectsTo( HashSet<GameObject> gameObjectsSet )
|
public void AddGameObjectsTo( HashSet<GameObject> gameObjectsSet )
|
||||||
{
|
{
|
||||||
|
if( PendingSearch )
|
||||||
|
return;
|
||||||
|
|
||||||
CalculateShortestPathsToReferences();
|
CalculateShortestPathsToReferences();
|
||||||
|
|
||||||
for( int i = 0; i < referencePathsShortUnique.Count; i++ )
|
for( int i = 0; i < referencePathsShortUnique.Count; i++ )
|
||||||
@@ -397,7 +616,7 @@ namespace AssetUsageDetectorNamespace
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Calculate short unique paths to the references
|
// Calculate short unique paths to the references
|
||||||
public void CalculateShortestPathsToReferences()
|
private void CalculateShortestPathsToReferences()
|
||||||
{
|
{
|
||||||
if( referencePathsShortUnique != null )
|
if( referencePathsShortUnique != null )
|
||||||
return;
|
return;
|
||||||
@@ -436,60 +655,163 @@ namespace AssetUsageDetectorNamespace
|
|||||||
// Draw the results found for this container
|
// Draw the results found for this container
|
||||||
public void DrawOnGUI( SearchResultDrawParameters parameters )
|
public void DrawOnGUI( SearchResultDrawParameters parameters )
|
||||||
{
|
{
|
||||||
|
if( Event.current.type == EventType.Repaint && ( guiNodes == null || parameters.pathDrawingMode != calculatedGUIMode || parameters.guiRect.width != calculatedGUIWidth ) )
|
||||||
|
{
|
||||||
|
GenerateGUINodes( parameters );
|
||||||
|
parameters.shouldRefreshEditorWindow = true; // A repaint is needed to work nicely with GUILayout
|
||||||
|
}
|
||||||
|
|
||||||
Color c = GUI.color;
|
Color c = GUI.color;
|
||||||
GUI.color = Color.cyan;
|
GUI.color = Color.cyan;
|
||||||
|
|
||||||
if( GUILayout.Button( title, Utilities.BoxGUIStyle, Utilities.GL_EXPAND_WIDTH, Utilities.GL_HEIGHT_40 ) && clickable )
|
Rect rect = parameters.guiRect;
|
||||||
|
float width = rect.width;
|
||||||
|
rect.width = 40f;
|
||||||
|
rect.height = HEADER_HEIGHT;
|
||||||
|
if( GUI.Button( rect, IsExpanded ? "v" : ">" ) )
|
||||||
{
|
{
|
||||||
// If the container (scene, usually) is clicked, highlight it on Project view
|
IsExpanded = !IsExpanded;
|
||||||
AssetDatabase.LoadAssetAtPath<SceneAsset>( title ).SelectInEditor();
|
|
||||||
|
parameters.shouldRefreshEditorWindow = true;
|
||||||
|
GUIUtility.ExitGUI();
|
||||||
}
|
}
|
||||||
|
|
||||||
GUI.color = Color.yellow;
|
rect.x += 40f;
|
||||||
|
rect.width = width - ( parameters.searchResult != null ? 140f : 40f );
|
||||||
if( parameters.pathDrawingMode == PathDrawingMode.Full )
|
if( GUI.Button( rect, Title, Utilities.BoxGUIStyle ) && Type == GroupType.Scene )
|
||||||
{
|
{
|
||||||
for( int i = 0; i < references.Count; i++ )
|
if( Event.current.button != 1 )
|
||||||
{
|
{
|
||||||
GUILayout.Space( 5 );
|
// If the container (scene, usually) is left clicked, highlight it on Project view
|
||||||
references[i].DrawOnGUIRecursively( parameters, null );
|
AssetDatabase.LoadAssetAtPath<SceneAsset>( Title ).SelectInEditor();
|
||||||
}
|
}
|
||||||
}
|
else if( !EditorApplication.isPlaying && EditorSceneManager.loadedSceneCount > 1 )
|
||||||
else
|
|
||||||
{
|
|
||||||
if( referencePathsShortUnique == null )
|
|
||||||
CalculateShortestPathsToReferences();
|
|
||||||
|
|
||||||
List<ReferencePath> pathsToDraw;
|
|
||||||
if( parameters.pathDrawingMode == PathDrawingMode.ShortRelevantParts )
|
|
||||||
pathsToDraw = referencePathsShortUnique;
|
|
||||||
else
|
|
||||||
pathsToDraw = referencePathsShortest;
|
|
||||||
|
|
||||||
for( int i = 0; i < pathsToDraw.Count; i++ )
|
|
||||||
{
|
{
|
||||||
GUILayout.Space( 5 );
|
// Show context menu when SearchResultGroup's header is right clicked
|
||||||
|
Scene scene = EditorSceneManager.GetSceneByPath( Title );
|
||||||
GUILayout.BeginHorizontal();
|
if( scene.isLoaded )
|
||||||
|
|
||||||
ReferencePath path = pathsToDraw[i];
|
|
||||||
path.startNode.DrawOnGUI( parameters, null );
|
|
||||||
|
|
||||||
ReferenceNode currentNode = path.startNode;
|
|
||||||
for( int j = 0; j < path.pathLinksToFollow.Length; j++ )
|
|
||||||
{
|
{
|
||||||
ReferenceNode.Link link = currentNode[path.pathLinksToFollow[j]];
|
GenericMenu contextMenu = new GenericMenu();
|
||||||
link.targetNode.DrawOnGUI( parameters, link.description );
|
contextMenu.AddItem( new GUIContent( "Close Scene" ), false, () =>
|
||||||
currentNode = link.targetNode;
|
{
|
||||||
|
if( !scene.isDirty || EditorSceneManager.SaveModifiedScenesIfUserWantsTo( new Scene[1] { scene } ) )
|
||||||
|
EditorSceneManager.CloseScene( scene, true );
|
||||||
|
} );
|
||||||
|
contextMenu.ShowAsContext();
|
||||||
}
|
}
|
||||||
|
|
||||||
GUILayout.EndHorizontal();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
GUI.color = c;
|
if( parameters.searchResult != null )
|
||||||
|
{
|
||||||
|
rect.x += width - 140f;
|
||||||
|
rect.width = 100f;
|
||||||
|
if( GUI.Button( rect, "Refresh" ) )
|
||||||
|
{
|
||||||
|
if( Utilities.AreScenesSaved() || ( EditorUtility.DisplayDialog( "Refresh", "Some scene(s) have unsaved changes, they must be saved before the refresh.", "Save Scenes", "Cancel" ) && EditorSceneManager.SaveOpenScenes() ) )
|
||||||
|
{
|
||||||
|
parameters.searchResult.RefreshSearchResultGroup( this, parameters.noAssetDatabaseChanges );
|
||||||
|
GUIUtility.ExitGUI();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
GUILayout.Space( 10 );
|
rect = parameters.guiRect;
|
||||||
|
rect.y += HEADER_HEIGHT + 5f;
|
||||||
|
|
||||||
|
if( IsExpanded )
|
||||||
|
{
|
||||||
|
GUI.color = Color.yellow;
|
||||||
|
|
||||||
|
if( PendingSearch )
|
||||||
|
{
|
||||||
|
rect.height = 25f;
|
||||||
|
GUI.Box( rect, "Lazy Search: this scene potentially has some references, hit Refresh to find them", Utilities.BoxGUIStyle );
|
||||||
|
}
|
||||||
|
else if( references.Count == 0 )
|
||||||
|
{
|
||||||
|
rect.height = 25f;
|
||||||
|
GUI.Box( rect, "No references found...", Utilities.BoxGUIStyle );
|
||||||
|
}
|
||||||
|
else if( guiNodes != null )
|
||||||
|
{
|
||||||
|
rect.height = calculatedGUIHeight;
|
||||||
|
parameters.guiRect = rect;
|
||||||
|
|
||||||
|
for( int i = 0; i < guiNodes.Length; i++ )
|
||||||
|
guiNodes[i].DrawOnGUI( parameters );
|
||||||
|
}
|
||||||
|
|
||||||
|
rect.y += rect.height;
|
||||||
|
}
|
||||||
|
|
||||||
|
parameters.guiRect = rect;
|
||||||
|
GUI.color = c;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void GenerateGUINodes( SearchResultDrawParameters parameters )
|
||||||
|
{
|
||||||
|
float guiRectWidth = parameters.guiRect.width;
|
||||||
|
|
||||||
|
if( guiNodes == null || parameters.pathDrawingMode != calculatedGUIMode )
|
||||||
|
{
|
||||||
|
if( parameters.pathDrawingMode == PathDrawingMode.Full )
|
||||||
|
{
|
||||||
|
List<ReferenceNode> stack = new List<ReferenceNode>( 8 );
|
||||||
|
guiNodes = new ReferenceNodeGUI[references.Count];
|
||||||
|
|
||||||
|
for( int i = 0; i < guiNodes.Length; i++ )
|
||||||
|
guiNodes[i] = references[i].GenerateGUINodeRecursive( stack, null );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if( referencePathsShortUnique == null )
|
||||||
|
CalculateShortestPathsToReferences();
|
||||||
|
|
||||||
|
List<ReferencePath> pathsToDraw;
|
||||||
|
if( parameters.pathDrawingMode == PathDrawingMode.ShortRelevantParts )
|
||||||
|
pathsToDraw = referencePathsShortUnique;
|
||||||
|
else
|
||||||
|
pathsToDraw = referencePathsShortest;
|
||||||
|
|
||||||
|
guiNodes = new ReferenceNodeGUI[pathsToDraw.Count];
|
||||||
|
|
||||||
|
for( int i = 0; i < guiNodes.Length; i++ )
|
||||||
|
{
|
||||||
|
ReferencePath path = pathsToDraw[i];
|
||||||
|
ReferenceNode currentNode = path.startNode;
|
||||||
|
|
||||||
|
ReferenceNodeGUI currentNodeGUI = currentNode.GenerateGUINode( null );
|
||||||
|
guiNodes[i] = currentNodeGUI;
|
||||||
|
|
||||||
|
for( int j = 0; j < path.pathLinksToFollow.Length; j++ )
|
||||||
|
{
|
||||||
|
ReferenceNode.Link link = currentNode[path.pathLinksToFollow[j]];
|
||||||
|
currentNodeGUI.links = new ReferenceNodeGUI[1] { link.targetNode.GenerateGUINode( link.description ) };
|
||||||
|
|
||||||
|
currentNode = link.targetNode;
|
||||||
|
currentNodeGUI = currentNodeGUI.links[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
currentNodeGUI.links = new ReferenceNodeGUI[0];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for( int i = 0; i < guiNodes.Length; i++ )
|
||||||
|
guiNodes[i].CalculateDepth();
|
||||||
|
}
|
||||||
|
|
||||||
|
calculatedGUIMode = parameters.pathDrawingMode;
|
||||||
|
calculatedGUIWidth = guiRectWidth;
|
||||||
|
|
||||||
|
calculatedGUIHeight = -5f; // will start from -5f + 5f = 0f
|
||||||
|
for( int i = 0; i < guiNodes.Length; i++ )
|
||||||
|
{
|
||||||
|
calculatedGUIHeight += 5f;
|
||||||
|
guiNodes[i].CalculateHeight( guiRectWidth );
|
||||||
|
guiNodes[i].CalculateOffset( new Vector2( 0f, calculatedGUIHeight ) );
|
||||||
|
calculatedGUIHeight += guiNodes[i].size.y;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Serialize this result group
|
// Serialize this result group
|
||||||
@@ -497,8 +819,10 @@ namespace AssetUsageDetectorNamespace
|
|||||||
{
|
{
|
||||||
SearchResult.SerializableResultGroup serializedResultGroup = new SearchResult.SerializableResultGroup()
|
SearchResult.SerializableResultGroup serializedResultGroup = new SearchResult.SerializableResultGroup()
|
||||||
{
|
{
|
||||||
title = title,
|
title = Title,
|
||||||
clickable = clickable
|
type = Type,
|
||||||
|
isExpanded = IsExpanded,
|
||||||
|
pendingSearch = PendingSearch
|
||||||
};
|
};
|
||||||
|
|
||||||
if( references != null )
|
if( references != null )
|
||||||
@@ -545,12 +869,12 @@ namespace AssetUsageDetectorNamespace
|
|||||||
private static int uid_last = 0;
|
private static int uid_last = 0;
|
||||||
private readonly int uid;
|
private readonly int uid;
|
||||||
|
|
||||||
public object nodeObject;
|
internal object nodeObject;
|
||||||
private readonly List<Link> links;
|
|
||||||
|
|
||||||
private int? instanceId; // instanceId of the nodeObject if it is a Unity object, null otherwise
|
private int? instanceId; // instanceId of the nodeObject if it is a Unity object, null otherwise
|
||||||
private string description; // String to print on this node
|
private string description; // String to print on this node
|
||||||
|
|
||||||
|
private readonly List<Link> links;
|
||||||
|
|
||||||
public Object UnityObject { get { return instanceId.HasValue ? EditorUtility.InstanceIDToObject( instanceId.Value ) : null; } }
|
public Object UnityObject { get { return instanceId.HasValue ? EditorUtility.InstanceIDToObject( instanceId.Value ) : null; } }
|
||||||
|
|
||||||
public int NumberOfOutgoingLinks { get { return links.Count; } }
|
public int NumberOfOutgoingLinks { get { return links.Count; } }
|
||||||
@@ -562,11 +886,6 @@ namespace AssetUsageDetectorNamespace
|
|||||||
uid = uid_last++;
|
uid = uid_last++;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ReferenceNode( object obj ) : this()
|
|
||||||
{
|
|
||||||
nodeObject = obj;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Add a one-way connection to another node
|
// Add a one-way connection to another node
|
||||||
public void AddLinkTo( ReferenceNode nextNode, string description = null )
|
public void AddLinkTo( ReferenceNode nextNode, string description = null )
|
||||||
{
|
{
|
||||||
@@ -596,6 +915,40 @@ namespace AssetUsageDetectorNamespace
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void CopyReferencesTo( ReferenceNode other )
|
||||||
|
{
|
||||||
|
other.links.Clear();
|
||||||
|
other.links.AddRange( links );
|
||||||
|
}
|
||||||
|
|
||||||
|
// Remove any redundant connections that this node has
|
||||||
|
public void VerifyLinksRecursively()
|
||||||
|
{
|
||||||
|
// Make sure that this functions isn't called multiple times per node (avoids StackOverflowException)
|
||||||
|
if( description != null )
|
||||||
|
return;
|
||||||
|
|
||||||
|
description = "";
|
||||||
|
|
||||||
|
for( int i = links.Count - 1; i >= 0; i-- )
|
||||||
|
{
|
||||||
|
// Links from a GameObject to its components should be omitted if the component has no references (these are redundant links)
|
||||||
|
if( links[i].targetNode.links.Count == 0 && nodeObject is GameObject )
|
||||||
|
{
|
||||||
|
Component component = links[i].targetNode.nodeObject as Component;
|
||||||
|
if( component != null && !component.Equals( null ) && component.gameObject == (GameObject) nodeObject )
|
||||||
|
{
|
||||||
|
links.RemoveAtFast( i );
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
links[i].targetNode.VerifyLinksRecursively();
|
||||||
|
}
|
||||||
|
|
||||||
|
description = null;
|
||||||
|
}
|
||||||
|
|
||||||
// Initialize node's commonly used variables
|
// Initialize node's commonly used variables
|
||||||
public void InitializeRecursively()
|
public void InitializeRecursively()
|
||||||
{
|
{
|
||||||
@@ -626,20 +979,29 @@ namespace AssetUsageDetectorNamespace
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Returns whether or not specified node is part of this node's siblings
|
// Returns whether or not specified node is part of this node's siblings
|
||||||
public bool NodeExistsInChildrenRecursive( ReferenceNode node )
|
public bool NodeExistsInChildrenRecursive( ReferenceNode node, List<ReferenceNode> callStack )
|
||||||
{
|
{
|
||||||
|
if( callStack.ContainsFast( this ) )
|
||||||
|
return false;
|
||||||
|
|
||||||
for( int i = 0; i < links.Count; i++ )
|
for( int i = 0; i < links.Count; i++ )
|
||||||
{
|
{
|
||||||
if( links[i].targetNode == node )
|
if( links[i].targetNode == node )
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
callStack.Add( this );
|
||||||
|
|
||||||
for( int i = 0; i < links.Count; i++ )
|
for( int i = 0; i < links.Count; i++ )
|
||||||
{
|
{
|
||||||
if( links[i].targetNode.NodeExistsInChildrenRecursive( node ) )
|
if( links[i].targetNode.NodeExistsInChildrenRecursive( node, callStack ) )
|
||||||
|
{
|
||||||
|
callStack.RemoveAt( callStack.Count - 1 );
|
||||||
return true;
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
callStack.RemoveAt( callStack.Count - 1 );
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -653,16 +1015,16 @@ namespace AssetUsageDetectorNamespace
|
|||||||
// Calculate short unique paths that start with this node
|
// Calculate short unique paths that start with this node
|
||||||
public void CalculateShortUniquePaths( List<SearchResultGroup.ReferencePath> currentPaths )
|
public void CalculateShortUniquePaths( List<SearchResultGroup.ReferencePath> currentPaths )
|
||||||
{
|
{
|
||||||
CalculateShortUniquePaths( currentPaths, new List<ReferenceNode>( 8 ), new List<int>( 8 ) { -1 }, 0 );
|
CalculateShortUniquePaths( currentPaths, new List<ReferenceNode>( 8 ), new List<int>( 8 ) { -1 }, 0, new List<ReferenceNode>( 8 ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
// Just some boring calculations to find the short unique paths recursively
|
// Just some boring calculations to find the short unique paths recursively
|
||||||
private void CalculateShortUniquePaths( List<SearchResultGroup.ReferencePath> shortestPaths, List<ReferenceNode> currentPath, List<int> currentPathIndices, int latestObjectIndexInPath )
|
private void CalculateShortUniquePaths( List<SearchResultGroup.ReferencePath> shortestPaths, List<ReferenceNode> currentPath, List<int> currentPathIndices, int latestObjectIndexInPath, List<ReferenceNode> stack )
|
||||||
{
|
{
|
||||||
int currentIndex = currentPath.Count;
|
int currentIndex = currentPath.Count;
|
||||||
currentPath.Add( this );
|
currentPath.Add( this );
|
||||||
|
|
||||||
if( links.Count == 0 )
|
if( links.Count == 0 || stack.ContainsFast( this ) )
|
||||||
{
|
{
|
||||||
// Check if the path to the reference is unique (not discovered so far)
|
// Check if the path to the reference is unique (not discovered so far)
|
||||||
bool isUnique = true;
|
bool isUnique = true;
|
||||||
@@ -703,7 +1065,11 @@ namespace AssetUsageDetectorNamespace
|
|||||||
for( int i = 0; i < links.Count; i++ )
|
for( int i = 0; i < links.Count; i++ )
|
||||||
{
|
{
|
||||||
currentPathIndices.Add( i );
|
currentPathIndices.Add( i );
|
||||||
links[i].targetNode.CalculateShortUniquePaths( shortestPaths, currentPath, currentPathIndices, latestObjectIndexInPath );
|
stack.Add( this );
|
||||||
|
|
||||||
|
links[i].targetNode.CalculateShortUniquePaths( shortestPaths, currentPath, currentPathIndices, latestObjectIndexInPath, stack );
|
||||||
|
|
||||||
|
stack.RemoveAt( stack.Count - 1 );
|
||||||
currentPathIndices.RemoveAt( currentIndex + 1 );
|
currentPathIndices.RemoveAt( currentIndex + 1 );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -711,41 +1077,33 @@ namespace AssetUsageDetectorNamespace
|
|||||||
currentPath.RemoveAt( currentIndex );
|
currentPath.RemoveAt( currentIndex );
|
||||||
}
|
}
|
||||||
|
|
||||||
// Draw all the paths that start with this node on GUI recursively
|
public ReferenceNodeGUI GenerateGUINode( string linkToPrevNodeDescription )
|
||||||
public void DrawOnGUIRecursively( SearchResultDrawParameters parameters, string linkToPrevNodeDescription )
|
|
||||||
{
|
{
|
||||||
GUILayout.BeginHorizontal();
|
return new ReferenceNodeGUI()
|
||||||
|
|
||||||
DrawOnGUI( parameters, linkToPrevNodeDescription );
|
|
||||||
|
|
||||||
if( links.Count > 0 )
|
|
||||||
{
|
{
|
||||||
GUILayout.BeginVertical();
|
label = new GUIContent( string.IsNullOrEmpty( linkToPrevNodeDescription ) ? description : ( linkToPrevNodeDescription + "\n" + description ) ),
|
||||||
|
instanceId = instanceId
|
||||||
for( int i = 0; i < links.Count; i++ )
|
};
|
||||||
{
|
|
||||||
ReferenceNode next = links[i].targetNode;
|
|
||||||
next.DrawOnGUIRecursively( parameters, links[i].description );
|
|
||||||
}
|
|
||||||
|
|
||||||
GUILayout.EndVertical();
|
|
||||||
}
|
|
||||||
|
|
||||||
GUILayout.EndHorizontal();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Draw only this node on GUI
|
public ReferenceNodeGUI GenerateGUINodeRecursive( List<ReferenceNode> stack, string linkToPrevNodeDescription )
|
||||||
public void DrawOnGUI( SearchResultDrawParameters parameters, string linkToPrevNodeDescription )
|
|
||||||
{
|
{
|
||||||
string label = string.IsNullOrEmpty( linkToPrevNodeDescription ) ? description : ( linkToPrevNodeDescription + "\n" + description );
|
ReferenceNodeGUI guiNode = GenerateGUINode( linkToPrevNodeDescription );
|
||||||
if( GUILayout.Button( label, Utilities.BoxGUIStyle, Utilities.GL_EXPAND_HEIGHT ) )
|
|
||||||
|
if( stack.ContainsFast( this ) )
|
||||||
|
guiNode.links = new ReferenceNodeGUI[0];
|
||||||
|
else
|
||||||
{
|
{
|
||||||
// If a reference is clicked, highlight it (either on Hierarchy view or Project view)
|
stack.Add( this );
|
||||||
UnityObject.SelectInEditor();
|
|
||||||
|
guiNode.links = new ReferenceNodeGUI[links.Count];
|
||||||
|
for( int i = 0; i < links.Count; i++ )
|
||||||
|
guiNode.links[i] = links[i].targetNode.GenerateGUINodeRecursive( stack, links[i].description );
|
||||||
|
|
||||||
|
stack.RemoveAt( stack.Count - 1 );
|
||||||
}
|
}
|
||||||
|
|
||||||
if( parameters.showTooltips && Event.current.type == EventType.Repaint && GUILayoutUtility.GetLastRect().Contains( Event.current.mousePosition ) )
|
return guiNode;
|
||||||
parameters.tooltip = label;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Serialize this node and its connected nodes recursively
|
// Serialize this node and its connected nodes recursively
|
||||||
@@ -803,4 +1161,95 @@ namespace AssetUsageDetectorNamespace
|
|||||||
return uid;
|
return uid;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public class ReferenceNodeGUI
|
||||||
|
{
|
||||||
|
public GUIContent label;
|
||||||
|
public ReferenceNodeGUI[] links;
|
||||||
|
public int? instanceId;
|
||||||
|
|
||||||
|
private int depth;
|
||||||
|
|
||||||
|
private Vector2 offset;
|
||||||
|
public Vector2 size;
|
||||||
|
|
||||||
|
public void CalculateDepth()
|
||||||
|
{
|
||||||
|
depth = 0;
|
||||||
|
|
||||||
|
for( int i = 0; i < links.Length; i++ )
|
||||||
|
{
|
||||||
|
links[i].CalculateDepth();
|
||||||
|
if( links[i].depth > depth )
|
||||||
|
depth = links[i].depth;
|
||||||
|
}
|
||||||
|
|
||||||
|
depth++;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void CalculateHeight( float totalWidth )
|
||||||
|
{
|
||||||
|
size.x = totalWidth / depth;
|
||||||
|
totalWidth -= size.x;
|
||||||
|
size.y = Utilities.BoxGUIStyle.CalcHeight( label, size.x );
|
||||||
|
float connectedNodesHeight = 0f;
|
||||||
|
for( int i = 0; i < links.Length; i++ )
|
||||||
|
{
|
||||||
|
links[i].CalculateHeight( totalWidth );
|
||||||
|
connectedNodesHeight += links[i].size.y;
|
||||||
|
}
|
||||||
|
|
||||||
|
if( size.y < connectedNodesHeight )
|
||||||
|
size.y = connectedNodesHeight;
|
||||||
|
else if( size.y > connectedNodesHeight )
|
||||||
|
ExpandHeightLeftToRight();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ExpandHeightLeftToRight()
|
||||||
|
{
|
||||||
|
float connectedNodesHeight = 0f;
|
||||||
|
for( int i = 0; i < links.Length; i++ )
|
||||||
|
connectedNodesHeight += links[i].size.y;
|
||||||
|
|
||||||
|
if( size.y > connectedNodesHeight )
|
||||||
|
{
|
||||||
|
for( int i = 0; i < links.Length; i++ )
|
||||||
|
{
|
||||||
|
links[i].size.y = size.y * links[i].size.y / connectedNodesHeight;
|
||||||
|
links[i].ExpandHeightLeftToRight();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void CalculateOffset( Vector2 baseOffset )
|
||||||
|
{
|
||||||
|
offset = baseOffset;
|
||||||
|
baseOffset.x += size.x;
|
||||||
|
|
||||||
|
for( int i = 0; i < links.Length; i++ )
|
||||||
|
{
|
||||||
|
links[i].CalculateOffset( baseOffset );
|
||||||
|
baseOffset.y += links[i].size.y;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void DrawOnGUI( SearchResultDrawParameters parameters )
|
||||||
|
{
|
||||||
|
Rect rect = parameters.guiRect;
|
||||||
|
rect.position += offset;
|
||||||
|
rect.size = size;
|
||||||
|
|
||||||
|
if( GUI.Button( rect, label, Utilities.BoxGUIStyle ) && instanceId.HasValue )
|
||||||
|
{
|
||||||
|
// If a reference is clicked, highlight it (either on Hierarchy view or Project view)
|
||||||
|
EditorUtility.InstanceIDToObject( instanceId.Value ).SelectInEditor();
|
||||||
|
}
|
||||||
|
|
||||||
|
for( int i = 0; i < links.Length; i++ )
|
||||||
|
links[i].DrawOnGUI( parameters );
|
||||||
|
|
||||||
|
if( parameters.showTooltips && Event.current.type == EventType.Repaint && rect.Contains( Event.current.mousePosition ) )
|
||||||
|
parameters.tooltip = label.text;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -12,31 +12,43 @@ namespace AssetUsageDetectorNamespace.Extras
|
|||||||
public static class Utilities
|
public static class Utilities
|
||||||
{
|
{
|
||||||
// A set of commonly used Unity types
|
// A set of commonly used Unity types
|
||||||
private static readonly HashSet<Type> primitiveUnityTypes = new HashSet<Type>() {
|
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( string ), typeof( Vector4 ), typeof( Vector3 ), typeof( Vector2 ), typeof( Rect ),
|
||||||
typeof( Matrix4x4 ), typeof( AnimationCurve ), typeof( Gradient ), typeof( RectOffset ),
|
typeof( Quaternion ), typeof( Color ), typeof( Color32 ), typeof( LayerMask ), typeof( Bounds ),
|
||||||
typeof( bool[] ), typeof( byte[] ), typeof( sbyte[] ), typeof( char[] ), typeof( decimal[] ),
|
typeof( Matrix4x4 ), typeof( AnimationCurve ), typeof( Gradient ), typeof( RectOffset ),
|
||||||
typeof( double[] ), typeof( float[] ), typeof( int[] ), typeof( uint[] ), typeof( long[] ),
|
typeof( bool[] ), typeof( byte[] ), typeof( sbyte[] ), typeof( char[] ), typeof( decimal[] ),
|
||||||
typeof( ulong[] ), typeof( short[] ), typeof( ushort[] ), typeof( string[] ),
|
typeof( double[] ), typeof( float[] ), typeof( int[] ), typeof( uint[] ), typeof( long[] ),
|
||||||
typeof( Vector4[] ), typeof( Vector3[] ), typeof( Vector2[] ), typeof( Rect[] ),
|
typeof( ulong[] ), typeof( short[] ), typeof( ushort[] ), typeof( string[] ),
|
||||||
typeof( Quaternion[] ), typeof( Color[] ), typeof( Color32[] ), typeof( LayerMask[] ),
|
typeof( Vector4[] ), typeof( Vector3[] ), typeof( Vector2[] ), typeof( Rect[] ),
|
||||||
typeof( Matrix4x4[] ), typeof( AnimationCurve[] ), typeof( Gradient[] ), typeof( RectOffset[] ),
|
typeof( Quaternion[] ), typeof( Color[] ), typeof( Color32[] ), typeof( LayerMask[] ), typeof( Bounds[] ),
|
||||||
typeof( List<bool> ), typeof( List<byte> ), typeof( List<sbyte> ), typeof( List<char> ), typeof( List<decimal> ),
|
typeof( Matrix4x4[] ), typeof( AnimationCurve[] ), typeof( Gradient[] ), typeof( RectOffset[] ),
|
||||||
typeof( List<double> ), typeof( List<float> ), typeof( List<int> ), typeof( List<uint> ), typeof( List<long> ),
|
typeof( List<bool> ), typeof( List<byte> ), typeof( List<sbyte> ), typeof( List<char> ), typeof( List<decimal> ),
|
||||||
typeof( List<ulong> ), typeof( List<short> ), typeof( List<ushort> ), typeof( List<string> ),
|
typeof( List<double> ), typeof( List<float> ), typeof( List<int> ), typeof( List<uint> ), typeof( List<long> ),
|
||||||
typeof( List<Vector4> ), typeof( List<Vector3> ), typeof( List<Vector2> ), typeof( List<Rect> ),
|
typeof( List<ulong> ), typeof( List<short> ), typeof( List<ushort> ), typeof( List<string> ),
|
||||||
typeof( List<Quaternion> ), typeof( List<Color> ), typeof( List<Color32> ), typeof( List<LayerMask> ),
|
typeof( List<Vector4> ), typeof( List<Vector3> ), typeof( List<Vector2> ), typeof( List<Rect> ),
|
||||||
typeof( List<Matrix4x4> ), typeof( List<AnimationCurve> ), typeof( List<Gradient> ), typeof( List<RectOffset> )
|
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 HashSet<string> folderContentsSet = new HashSet<string>();
|
private static readonly HashSet<string> folderContentsSet = new HashSet<string>();
|
||||||
|
|
||||||
|
#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_WIDTH = GUILayout.ExpandWidth( true );
|
||||||
public static readonly GUILayoutOption GL_EXPAND_HEIGHT = GUILayout.ExpandHeight( 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_25 = GUILayout.Width( 25 );
|
||||||
public static readonly GUILayoutOption GL_WIDTH_100 = GUILayout.Width( 100 );
|
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_WIDTH_250 = GUILayout.Width( 250 );
|
||||||
|
public static readonly GUILayoutOption GL_HEIGHT_0 = GUILayout.Height( 0 );
|
||||||
public static readonly GUILayoutOption GL_HEIGHT_30 = GUILayout.Height( 30 );
|
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_35 = GUILayout.Height( 35 );
|
||||||
public static readonly GUILayoutOption GL_HEIGHT_40 = GUILayout.Height( 40 );
|
public static readonly GUILayoutOption GL_HEIGHT_40 = GUILayout.Height( 40 );
|
||||||
@@ -142,9 +154,9 @@ namespace AssetUsageDetectorNamespace.Extras
|
|||||||
|
|
||||||
Event e = Event.current;
|
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
|
// otherwise select only the clicked object and ping it in editor
|
||||||
if( !e.control )
|
if( !e.control && !e.shift )
|
||||||
Selection.activeObject = obj.PingInEditor();
|
Selection.activeObject = obj.PingInEditor();
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -211,23 +223,26 @@ namespace AssetUsageDetectorNamespace.Extras
|
|||||||
{
|
{
|
||||||
string assetPath = AssetDatabase.GetAssetPath( objTR.gameObject );
|
string assetPath = AssetDatabase.GetAssetPath( objTR.gameObject );
|
||||||
var openPrefabStage = UnityEditor.Experimental.SceneManagement.PrefabStageUtility.GetCurrentPrefabStage();
|
var openPrefabStage = UnityEditor.Experimental.SceneManagement.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 &&
|
||||||
|
( openPrefabStage == null || !openPrefabStage.stageHandle.IsValid() || assetPath != openPrefabStage.prefabAssetPath ) )
|
||||||
|
{
|
||||||
|
AssetDatabase.OpenAsset( objTR.gameObject );
|
||||||
|
openPrefabStage = UnityEditor.Experimental.SceneManagement.PrefabStageUtility.GetCurrentPrefabStage();
|
||||||
|
}
|
||||||
|
|
||||||
|
previousPingedPrefabInstanceId = objTR.GetInstanceID();
|
||||||
|
previousPingedPrefabPingTime = EditorApplication.timeSinceStartup;
|
||||||
|
|
||||||
if( openPrefabStage != null && openPrefabStage.stageHandle.IsValid() && assetPath == openPrefabStage.prefabAssetPath )
|
if( openPrefabStage != null && openPrefabStage.stageHandle.IsValid() && assetPath == openPrefabStage.prefabAssetPath )
|
||||||
{
|
{
|
||||||
// Ping the object in prefab stage
|
GameObject prefabStageGO = FollowSymmetricHierarchy( (GameObject) obj, openPrefabStage.prefabContentsRoot );
|
||||||
Transform targetParent = objTR;
|
if( prefabStageGO != null )
|
||||||
Transform selectedObject = ( (GameObject) obj ).transform;
|
|
||||||
objTR = openPrefabStage.prefabContentsRoot.transform;
|
|
||||||
while( targetParent != selectedObject )
|
|
||||||
{
|
{
|
||||||
Transform temp = selectedObject;
|
objTR = prefabStageGO.transform;
|
||||||
while( temp.parent != targetParent )
|
selection = objTR.gameObject;
|
||||||
temp = temp.parent;
|
|
||||||
|
|
||||||
objTR = objTR.GetChild( temp.GetSiblingIndex() );
|
|
||||||
targetParent = temp;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
selection = objTR.gameObject;
|
|
||||||
}
|
}
|
||||||
#if UNITY_2019_1_OR_NEWER
|
#if UNITY_2019_1_OR_NEWER
|
||||||
else if( obj != objTR.gameObject )
|
else if( obj != objTR.gameObject )
|
||||||
@@ -253,6 +268,38 @@ namespace AssetUsageDetectorNamespace.Extras
|
|||||||
return selection;
|
return selection;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static GameObject FollowSymmetricHierarchy( this GameObject go, GameObject symmetricRoot )
|
||||||
|
{
|
||||||
|
Transform target = go.transform;
|
||||||
|
Transform root1 = target.root;
|
||||||
|
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
|
// Check if the field is serializable
|
||||||
public static bool IsSerializable( this FieldInfo fieldInfo )
|
public static bool IsSerializable( this FieldInfo fieldInfo )
|
||||||
{
|
{
|
||||||
@@ -310,13 +357,6 @@ namespace AssetUsageDetectorNamespace.Extras
|
|||||||
return type.IsPrimitive || primitiveUnityTypes.Contains( type ) || type.IsEnum;
|
return type.IsPrimitive || primitiveUnityTypes.Contains( type ) || type.IsEnum;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if property has override keyword
|
|
||||||
public static bool IsOverridden( this PropertyInfo propertyInfo )
|
|
||||||
{
|
|
||||||
MethodInfo mi = propertyInfo.GetGetMethod( true );
|
|
||||||
return mi.GetBaseDefinition().DeclaringType != mi.DeclaringType;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get <get> function for a field
|
// Get <get> function for a field
|
||||||
public static VariableGetVal CreateGetter( this FieldInfo fieldInfo, Type type )
|
public static VariableGetVal CreateGetter( this FieldInfo fieldInfo, Type type )
|
||||||
{
|
{
|
||||||
@@ -339,22 +379,12 @@ namespace AssetUsageDetectorNamespace.Extras
|
|||||||
// Get <get> function for a property
|
// Get <get> function for a property
|
||||||
public static VariableGetVal CreateGetter( this PropertyInfo propertyInfo )
|
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
|
// Can't use PropertyWrapper (which uses CreateDelegate) for property getters of structs
|
||||||
if( propertyInfo.DeclaringType.IsValueType )
|
if( propertyInfo.DeclaringType.IsValueType )
|
||||||
return propertyInfo.CanRead ? ( ( obj ) => propertyInfo.GetValue( obj, null ) ) : (VariableGetVal) null;
|
return propertyInfo.CanRead ? ( ( obj ) => propertyInfo.GetValue( obj, null ) ) : (VariableGetVal) null;
|
||||||
|
|
||||||
MethodInfo mi = propertyInfo.GetGetMethod( true );
|
Type GenType = typeof( PropertyWrapper<,> ).MakeGenericType( propertyInfo.DeclaringType, propertyInfo.PropertyType );
|
||||||
if( mi != null )
|
return ( (IPropertyAccessor) Activator.CreateInstance( GenType, propertyInfo.GetGetMethod( true ) ) ).GetValue;
|
||||||
{
|
|
||||||
Type GenType = typeof( PropertyWrapper<,> ).MakeGenericType( propertyInfo.DeclaringType, propertyInfo.PropertyType );
|
|
||||||
return ( (IPropertyAccessor) Activator.CreateInstance( GenType, mi ) ).GetValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if all open scenes are saved (not dirty)
|
// Check if all open scenes are saved (not dirty)
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
namespace AssetUsageDetectorNamespace.Extras
|
namespace AssetUsageDetectorNamespace.Extras
|
||||||
{
|
{
|
||||||
@@ -32,7 +33,15 @@ namespace AssetUsageDetectorNamespace.Extras
|
|||||||
|
|
||||||
public object Get( object obj )
|
public object Get( object obj )
|
||||||
{
|
{
|
||||||
return getter( obj );
|
try
|
||||||
|
{
|
||||||
|
return getter( obj );
|
||||||
|
}
|
||||||
|
catch( Exception e )
|
||||||
|
{
|
||||||
|
Debug.LogException( e );
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ E-mail: yasirkula@gmail.com
|
|||||||
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.
|
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
|
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.
|
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
|
3. KNOWN LIMITATIONS
|
||||||
- static variables are not searched
|
- static variables are not searched
|
||||||
|
|||||||
@@ -14,14 +14,12 @@ This editor extension helps you figure out at which places an asset or GameObjec
|
|||||||
|
|
||||||
- Import [AssetUsageDetector.unitypackage](https://github.com/yasirkula/UnityAssetUsageDetector/releases) to your project
|
- Import [AssetUsageDetector.unitypackage](https://github.com/yasirkula/UnityAssetUsageDetector/releases) to your project
|
||||||
- Open **Window - Asset Usage Detector** window, configure the settings and hit **GO!**
|
- 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
|
- or, right click an object and select **Search For References**
|
||||||
|
|
||||||
**NOTE:** If your project uses an older version of AssetUsageDetector, delete the older version before updating the plugin.
|
|
||||||
|
|
||||||
### C. FEATURES
|
### C. FEATURES
|
||||||
|
|
||||||
- You can search for references of any object that extends *UnityEngine.Object*
|
- 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)
|
- Extensive search algorithm that uses *SerializedObject* and *reflection* to find references
|
||||||
- Can search in multiple scenes at once
|
- 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)
|
- Can show complete paths to the references or only the most relevant parts of the paths (see the demonstration below)
|
||||||
|
|
||||||
|
|||||||
Binary file not shown.
|
Before Width: | Height: | Size: 51 KiB After Width: | Height: | Size: 40 KiB |
Reference in New Issue
Block a user