Compare commits
36 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 6939dbc088 | |||
| dd922e85e4 | |||
| 9648f856d1 | |||
| f724dd2fdb | |||
| 7b3b7957d8 | |||
| d5942a66c4 | |||
| dcc5d5e0ad | |||
| 8872a0fcc5 | |||
| 8c04db9b25 | |||
| b7b6f8815e | |||
| 40a28f5961 | |||
| b535e09ba2 | |||
| 499e4bc43e | |||
| 93c955993a | |||
| 21f8daffde | |||
| 8cc7798f17 | |||
| 45b0f6f1d9 | |||
| c599ea6273 | |||
| 7ba33e2d4e | |||
| ac294324dd | |||
| 8dc7d5508b | |||
| c9131811e2 | |||
| 133b8b1227 | |||
| 1db9dbf9b0 | |||
| a6b0f5ae92 | |||
| 8e7369e44e | |||
| 7b60eeacf7 | |||
| b8470536b9 | |||
| 1bebc8691d | |||
| 5a81e5011b | |||
| ba7539d983 | |||
| f4129574fb | |||
| 7738da9d19 | |||
| 077505a217 | |||
| 003cedd363 | |||
| 68f1b2809e |
|
After Width: | Height: | Size: 145 KiB |
|
After Width: | Height: | Size: 148 KiB |
|
After Width: | Height: | Size: 112 KiB |
|
After Width: | Height: | Size: 114 KiB |
|
After Width: | Height: | Size: 83 KiB |
@@ -1,16 +1,18 @@
|
||||
# Asset Usage Detector for Unity 3D
|
||||
|
||||

|
||||

|
||||
|
||||
**Available on Asset Store:** https://assetstore.unity.com/packages/tools/utilities/asset-usage-detector-112837
|
||||
|
||||
**Forum Thread:** https://forum.unity.com/threads/asset-usage-detector-find-references-to-an-asset-object-open-source.408134/
|
||||
|
||||
**Discord:** https://discord.gg/UJJt549AaV
|
||||
|
||||
**[Support the Developer ☕](https://yasirkula.itch.io/unity3d)**
|
||||
|
||||
## ABOUT
|
||||
|
||||
This editor extension helps you figure out at which places an asset or GameObject is used, i.e. lists the objects that refer to the asset. It is possible to search for references in the Assets folder (Project view) and/or in the scene(s) of your project. You can also search for references while in Play mode!
|
||||
This tool helps you find usages of the selected asset(s) and/or scene object(s), i.e. lists the objects that refer to them. It is possible to search for references in the Assets folder (Project view) and/or in the scene(s) of your project. You can also search for references while in Play mode!
|
||||
|
||||
## INSTALLATION
|
||||
|
||||
@@ -28,19 +30,17 @@ There are 5 ways to install this plugin:
|
||||
|
||||
- Open **Window - Asset Usage Detector** window, configure the settings and hit **GO!**
|
||||
- or, right click an object and select **Search For References**
|
||||
- In the search results page, each row represents a reference to the searched Object(s). Rows can be traversed from left to right to see how the references are formed. If a node's label contains text inside square brackets (e.g. *\[Child object\]*), then that text describes how that node is connected to the node to its left
|
||||
- To learn how to interpret the search results and for more instructions, please see the included [README.txt](Plugins/AssetUsageDetector/README.txt) file
|
||||
- You can tweak most settings/colors via *Project Settings/yasirkula/Asset Usage Detector* page (on older versions, this menu is located at *Preferences* window)
|
||||
|
||||
## FEATURES
|
||||

|
||||
|
||||
- You can search for references of any object that extends *UnityEngine.Object*
|
||||
- Extensive search algorithm that uses *SerializedObject* and *reflection* to find references
|
||||
- Can search in multiple scenes at once
|
||||
- Can show complete paths to the references or only the most relevant parts of the paths (see the demonstration below)
|
||||
|
||||

|
||||

|
||||
|
||||
## KNOWN LIMITATIONS
|
||||
|
||||
- *static* variables are not searched
|
||||
- GUIText materials are not searched
|
||||
- Textures in Lens Flare's can not be searched
|
||||
- *Addressables* aren't supported
|
||||
- *static* variables aren't searched
|
||||
- *Resources.Load* usages can't be found
|
||||
- *GUIText* materials aren't searched
|
||||
- Textures in *Lens Flares* can't be searched
|
||||
|
||||
|
Before Width: | Height: | Size: 40 KiB |
|
Before Width: | Height: | Size: 103 KiB |
@@ -10,12 +10,15 @@ using System;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using Object = UnityEngine.Object;
|
||||
#if UNITY_2018_3_OR_NEWER
|
||||
using PrefabStage = UnityEditor.Experimental.SceneManagement.PrefabStage;
|
||||
using PrefabStageUtility = UnityEditor.Experimental.SceneManagement.PrefabStageUtility;
|
||||
#endif
|
||||
|
||||
namespace AssetUsageDetectorNamespace
|
||||
{
|
||||
[Flags]
|
||||
public enum SceneSearchMode { None = 0, OpenScenes = 1, ScenesInBuildSettingsAll = 2, ScenesInBuildSettingsTickedOnly = 4, AllScenes = 8 };
|
||||
public enum PathDrawingMode { Full = 0, ShortRelevantParts = 1, Shortest = 2 };
|
||||
|
||||
public partial class AssetUsageDetector
|
||||
{
|
||||
@@ -39,13 +42,18 @@ namespace AssetUsageDetectorNamespace
|
||||
public BindingFlags propertyModifiers = BindingFlags.Public | BindingFlags.NonPublic;
|
||||
public bool searchNonSerializableVariables = true;
|
||||
|
||||
public bool lazySceneSearch = false;
|
||||
public bool searchUnusedMaterialProperties = true;
|
||||
|
||||
public bool lazySceneSearch = true;
|
||||
public bool calculateUnusedObjects = false;
|
||||
public bool hideDuplicateRows = true;
|
||||
public bool hideReduntantPrefabVariantLinks = true;
|
||||
public bool noAssetDatabaseChanges = false;
|
||||
public bool showDetailedProgressBar = false;
|
||||
public bool showDetailedProgressBar = true;
|
||||
}
|
||||
#endregion
|
||||
|
||||
// A set that contains the searched asset(s) and their sub-assets (if any)
|
||||
// A set that contains the searched scene object(s), asset(s) and their sub-assets (if any)
|
||||
private readonly HashSet<Object> objectsToSearchSet = new HashSet<Object>();
|
||||
// Scenes of scene object(s) in objectsToSearchSet
|
||||
private readonly HashSet<string> sceneObjectsToSearchScenesSet = new HashSet<string>();
|
||||
@@ -64,7 +72,8 @@ namespace AssetUsageDetectorNamespace
|
||||
private SearchResultGroup currentSearchResultGroup;
|
||||
|
||||
// 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 );
|
||||
private readonly Dictionary<string, ReferenceNode> searchedObjects = new Dictionary<string, ReferenceNode>( 4096 );
|
||||
private readonly Dictionary<int, ReferenceNode> searchedUnityObjects = new Dictionary<int, ReferenceNode>( 32768 ); // Unity objects use their instanceIDs as key which is more performant
|
||||
|
||||
// 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 );
|
||||
@@ -74,13 +83,18 @@ namespace AssetUsageDetectorNamespace
|
||||
private Object currentSearchedObject;
|
||||
private int currentDepth;
|
||||
|
||||
private bool searchUnusedMaterialProperties;
|
||||
|
||||
private bool dontSearchInSourceAssets;
|
||||
private bool searchingSourceAssets;
|
||||
private bool isInPlayMode;
|
||||
|
||||
#if UNITY_2018_3_OR_NEWER
|
||||
private UnityEditor.Experimental.SceneManagement.PrefabStage openPrefabStage;
|
||||
private PrefabStage openPrefabStage;
|
||||
private GameObject openPrefabStagePrefabAsset;
|
||||
#if UNITY_2020_1_OR_NEWER
|
||||
private GameObject openPrefabStageContextObject;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
private int searchedObjectsCount; // Number of searched objects
|
||||
@@ -93,30 +107,20 @@ namespace AssetUsageDetectorNamespace
|
||||
{
|
||||
if( searchParameters == null )
|
||||
{
|
||||
Debug.LogError( "searchParameters must not be null!" );
|
||||
return new SearchResult( false, null, null, this, searchParameters );
|
||||
Debug.LogError( "'searchParameters' mustn't be null!" );
|
||||
return new SearchResult( false, null, null, null, this, searchParameters );
|
||||
}
|
||||
|
||||
if( searchParameters.objectsToSearch == null )
|
||||
{
|
||||
Debug.LogError( "objectsToSearch list is empty!" );
|
||||
return new SearchResult( false, null, null, this, searchParameters );
|
||||
Debug.LogError( "'objectsToSearch' list (\"SEARCHED OBJECTS\") is empty!" );
|
||||
return new SearchResult( false, null, 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;
|
||||
|
||||
isInPlayMode = EditorApplication.isPlaying;
|
||||
#if UNITY_2018_3_OR_NEWER
|
||||
openPrefabStagePrefabAsset = null;
|
||||
string openPrefabStageAssetPath = null;
|
||||
openPrefabStage = UnityEditor.Experimental.SceneManagement.PrefabStageUtility.GetCurrentPrefabStage();
|
||||
openPrefabStage = PrefabStageUtility.GetCurrentPrefabStage();
|
||||
if( openPrefabStage != null )
|
||||
{
|
||||
if( !openPrefabStage.stageHandle.IsValid() )
|
||||
@@ -126,16 +130,34 @@ namespace AssetUsageDetectorNamespace
|
||||
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 );
|
||||
Debug.LogError( "Save open prefab first!" );
|
||||
return new SearchResult( false, null, null, null, this, searchParameters );
|
||||
}
|
||||
|
||||
openPrefabStagePrefabAsset = AssetDatabase.LoadAssetAtPath<GameObject>( openPrefabStage.prefabAssetPath );
|
||||
openPrefabStageAssetPath = openPrefabStage.prefabAssetPath;
|
||||
#if UNITY_2020_1_OR_NEWER
|
||||
string prefabAssetPath = openPrefabStage.assetPath;
|
||||
#else
|
||||
string prefabAssetPath = openPrefabStage.prefabAssetPath;
|
||||
#endif
|
||||
openPrefabStagePrefabAsset = AssetDatabase.LoadAssetAtPath<GameObject>( prefabAssetPath );
|
||||
openPrefabStageAssetPath = prefabAssetPath;
|
||||
|
||||
#if UNITY_2020_1_OR_NEWER
|
||||
openPrefabStageContextObject = openPrefabStage.openedFromInstanceRoot;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
List<SearchResultGroup> searchResult = null;
|
||||
isInPlayMode = EditorApplication.isPlaying;
|
||||
|
||||
if( !isInPlayMode && !Utilities.AreScenesSaved() && !EditorUtility.DisplayDialog( "Asset Usage Detector", "Some scene(s) aren't saved. This may result in incorrect search results in those scene(s). Proceed?", "Yes", "Cancel" ) )
|
||||
{
|
||||
Debug.LogError( "Save open scene(s) first!" );
|
||||
return new SearchResult( false, null, null, null, this, searchParameters );
|
||||
}
|
||||
|
||||
// Get the scenes that are open right now
|
||||
SceneSetup[] initialSceneSetup = !isInPlayMode ? EditorSceneManager.GetSceneManagerSetup() : null;
|
||||
|
||||
@@ -154,8 +176,10 @@ namespace AssetUsageDetectorNamespace
|
||||
|
||||
searchDepthLimit = searchParameters.searchDepthLimit;
|
||||
dontSearchInSourceAssets = searchParameters.dontSearchInSourceAssets;
|
||||
searchUnusedMaterialProperties = searchParameters.searchUnusedMaterialProperties;
|
||||
|
||||
searchedObjects.Clear();
|
||||
searchedUnityObjects.Clear();
|
||||
animationClipUniqueBindings.Clear();
|
||||
callStack.Clear();
|
||||
objectsToSearchSet.Clear();
|
||||
@@ -314,7 +338,7 @@ namespace AssetUsageDetectorNamespace
|
||||
|
||||
// Initialize the nodes of searched asset(s)
|
||||
foreach( Object obj in objectsToSearchSet )
|
||||
searchedObjects.Add( obj.Hash(), PopReferenceNode( obj ) );
|
||||
searchedUnityObjects.Add( obj.GetHashCode(), PopReferenceNode( obj ) );
|
||||
|
||||
// Progressbar values
|
||||
int searchProgress = 0;
|
||||
@@ -522,35 +546,28 @@ namespace AssetUsageDetectorNamespace
|
||||
searchingSourceAssets = false;
|
||||
}
|
||||
|
||||
EditorUtility.DisplayProgressBar( "Please wait...", "Post-processing search results", 1f );
|
||||
|
||||
InitializeSearchResultNodes( searchResult );
|
||||
|
||||
HashSet<Object> usedObjects = null;
|
||||
if( searchResult.Count > 0 && searchParameters.calculateUnusedObjects )
|
||||
CalculateUnusedObjects( searchResult, out usedObjects );
|
||||
|
||||
// Log some c00l stuff to console
|
||||
Debug.Log( "Searched " + searchedObjectsCount + " objects in " + ( EditorApplication.timeSinceStartup - searchStartTime ).ToString( "F2" ) + " seconds" );
|
||||
|
||||
return new SearchResult( true, searchResult, initialSceneSetup, this, searchParameters );
|
||||
return new SearchResult( true, searchResult, usedObjects, initialSceneSetup, this, searchParameters );
|
||||
}
|
||||
catch( Exception e )
|
||||
{
|
||||
StringBuilder sb = new StringBuilder( objectsToSearchSet.Count * 50 + callStack.Count * 50 + 500 );
|
||||
sb.AppendLine( "<b>AssetUsageDetector Error:</b>" ).AppendLine();
|
||||
if( callStack.Count > 0 )
|
||||
{
|
||||
sb.AppendLine( "Stack contents: " );
|
||||
for( int i = callStack.Count - 1; i >= 0; i-- )
|
||||
{
|
||||
sb.Append( i ).Append( ": " );
|
||||
StringBuilder sb = Utilities.stringBuilder;
|
||||
sb.Length = 0;
|
||||
sb.EnsureCapacity( objectsToSearchSet.Count * 50 + callStack.Count * 50 + 500 );
|
||||
|
||||
Object unityObject = callStack[i] as Object;
|
||||
if( unityObject )
|
||||
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>>" );
|
||||
}
|
||||
sb.AppendLine( "<b>AssetUsageDetector Error:</b> The following Exception is thrown during the search. Details:" );
|
||||
|
||||
sb.AppendLine();
|
||||
}
|
||||
Object latestUnityObjectInCallStack = AppendCallStackToStringBuilder( sb );
|
||||
|
||||
sb.AppendLine( "Searching references of: " );
|
||||
foreach( Object obj in objectsToSearchSet )
|
||||
@@ -559,10 +576,8 @@ namespace AssetUsageDetectorNamespace
|
||||
sb.Append( obj.name ).Append( " (" ).Append( obj.GetType() ).AppendLine( ")" );
|
||||
}
|
||||
|
||||
sb.AppendLine();
|
||||
sb.Append( e ).AppendLine();
|
||||
|
||||
Debug.LogError( sb.ToString() );
|
||||
Debug.LogError( sb.ToString(), latestUnityObjectInCallStack );
|
||||
Debug.LogException( e, latestUnityObjectInCallStack );
|
||||
|
||||
try
|
||||
{
|
||||
@@ -571,7 +586,7 @@ namespace AssetUsageDetectorNamespace
|
||||
catch
|
||||
{ }
|
||||
|
||||
return new SearchResult( false, searchResult, initialSceneSetup, this, searchParameters );
|
||||
return new SearchResult( false, searchResult, null, initialSceneSetup, this, searchParameters );
|
||||
}
|
||||
finally
|
||||
{
|
||||
@@ -583,7 +598,30 @@ namespace AssetUsageDetectorNamespace
|
||||
#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 ) );
|
||||
{
|
||||
#if UNITY_2020_1_OR_NEWER
|
||||
bool shouldOpenPrefabStageWithoutContext = true;
|
||||
if( openPrefabStageContextObject != null && !openPrefabStageContextObject.Equals( null ) )
|
||||
{
|
||||
try
|
||||
{
|
||||
// Try to access this method: https://github.com/Unity-Technologies/UnityCsReference/blob/73925b1711847c067e607ec8371f8e9ffe7ab65d/Editor/Mono/SceneManagement/StageManager/PrefabStage/PrefabStageUtility.cs#L61-L65
|
||||
MethodInfo prefabStageOpenerWithContext = typeof( PrefabStageUtility ).GetMethod( "OpenPrefab", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static, null, new Type[2] { typeof( string ), typeof( GameObject ) }, null );
|
||||
if( prefabStageOpenerWithContext != null )
|
||||
{
|
||||
prefabStageOpenerWithContext.Invoke( null, new object[2] { openPrefabStageAssetPath, openPrefabStageContextObject } );
|
||||
shouldOpenPrefabStageWithoutContext = false;
|
||||
}
|
||||
}
|
||||
catch { }
|
||||
}
|
||||
|
||||
if( shouldOpenPrefabStageWithoutContext )
|
||||
#endif
|
||||
{
|
||||
AssetDatabase.OpenAsset( AssetDatabase.LoadAssetAtPath<GameObject>( openPrefabStageAssetPath ) );
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
@@ -591,13 +629,168 @@ namespace AssetUsageDetectorNamespace
|
||||
private void InitializeSearchResultNodes( List<SearchResultGroup> searchResult )
|
||||
{
|
||||
for( int i = 0; i < searchResult.Count; i++ )
|
||||
searchResult[i].InitializeNodes( GetReferenceNode );
|
||||
|
||||
// If there are any empty groups after node initialization, remove those groups
|
||||
for( int i = searchResult.Count - 1; i >= 0; i-- )
|
||||
{
|
||||
searchResult[i].InitializeNodes( objectsToSearchSet );
|
||||
|
||||
// Remove empty search result groups
|
||||
if( !searchResult[i].PendingSearch && searchResult[i].NumberOfReferences == 0 )
|
||||
searchResult.RemoveAtFast( i );
|
||||
searchResult.RemoveAt( i-- );
|
||||
}
|
||||
}
|
||||
|
||||
private void CalculateUnusedObjects( List<SearchResultGroup> searchResult, out HashSet<Object> usedObjectsSet )
|
||||
{
|
||||
currentSearchResultGroup = new SearchResultGroup( "Unused Objects", SearchResultGroup.GroupType.UnusedObjects, false, false );
|
||||
|
||||
usedObjectsSet = new HashSet<Object>();
|
||||
HashSet<string> usedObjectPathsSet = new HashSet<string>(); // For assets: stores the filepaths, For scene objects: stores the topmost GameObject's instanceID
|
||||
foreach( SearchResultGroup searchResultGroup in searchResult )
|
||||
{
|
||||
for( int j = 0; j < searchResultGroup.NumberOfReferences; j++ )
|
||||
{
|
||||
Object obj = searchResultGroup[j].UnityObject;
|
||||
if( obj is Component )
|
||||
obj = ( (Component) obj ).gameObject;
|
||||
|
||||
if( usedObjectsSet.Add( obj ) )
|
||||
{
|
||||
string assetPath = AssetDatabase.GetAssetPath( obj );
|
||||
if( !string.IsNullOrEmpty( assetPath ) )
|
||||
usedObjectPathsSet.Add( assetPath );
|
||||
else
|
||||
{
|
||||
for( Transform parent = ( (GameObject) obj ).transform.parent; parent != null; parent = parent.parent )
|
||||
usedObjectPathsSet.Add( parent.gameObject.GetHashCode().ToString() );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Dictionary<string, ReferenceNode> unusedMainObjectNodes = new Dictionary<string, ReferenceNode>( objectsToSearchSet.Count - usedObjectsSet.Count );
|
||||
Dictionary<string, List<ReferenceNode>> unusedSubObjectNodes = new Dictionary<string, List<ReferenceNode>>( objectsToSearchSet.Count - usedObjectsSet.Count );
|
||||
foreach( Object obj in objectsToSearchSet )
|
||||
{
|
||||
// Omit components, their GameObjects are already included in search
|
||||
if( obj is Component )
|
||||
continue;
|
||||
|
||||
// Omit assets that are invisible in Hierarchy/Inspector
|
||||
if( ( obj.hideFlags & ( HideFlags.HideInInspector | HideFlags.HideInHierarchy ) ) != HideFlags.None )
|
||||
continue;
|
||||
|
||||
if( usedObjectsSet.Contains( obj ) )
|
||||
continue;
|
||||
|
||||
string assetPath = AssetDatabase.GetAssetPath( obj );
|
||||
GameObject searchedTopmostGameObject = null;
|
||||
if( obj is GameObject )
|
||||
{
|
||||
if( string.IsNullOrEmpty( assetPath ) )
|
||||
{
|
||||
for( Transform parent = ( (GameObject) obj ).transform.parent; parent != null; parent = parent.parent )
|
||||
{
|
||||
if( objectsToSearchSet.Contains( parent ) && !usedObjectsSet.Contains( parent.gameObject ) )
|
||||
searchedTopmostGameObject = parent.gameObject;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for( Transform parent = ( (GameObject) obj ).transform.parent; parent != null; parent = parent.parent )
|
||||
{
|
||||
if( objectsToSearchSet.Contains( parent ) )
|
||||
{
|
||||
searchedTopmostGameObject = parent.gameObject;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if( searchedTopmostGameObject && !string.IsNullOrEmpty( assetPath ) ) // Omit GameObject assets if their parent objects are already included in search
|
||||
continue;
|
||||
}
|
||||
|
||||
// Omit meshes of an imported model asset
|
||||
if( obj is Mesh && !string.IsNullOrEmpty( assetPath ) && AssetDatabase.GetMainAssetTypeAtPath( assetPath ) == typeof( GameObject ) && objectsToSearchSet.Contains( AssetDatabase.LoadMainAssetAtPath( assetPath ) ) )
|
||||
continue;
|
||||
|
||||
// Omit MonoScripts whose types can't be determined
|
||||
if( obj is MonoScript && ( (MonoScript) obj ).GetClass() == null )
|
||||
continue;
|
||||
|
||||
// Use new ReferenceNodes in UnusedObjects search result group because we don't want these nodes to be linked to the actual ReferenceNodes in any way
|
||||
// (i.e. we don't use actual ReferenceNodes of these objects (GetReferenceNode) because these may have links to other nodes in unknown circumstances)
|
||||
ReferenceNode node = PopReferenceNode( obj );
|
||||
node.usedState = ReferenceNode.UsedState.Unused;
|
||||
|
||||
if( string.IsNullOrEmpty( assetPath ) )
|
||||
{
|
||||
if( !searchedTopmostGameObject )
|
||||
{
|
||||
if( obj is GameObject )
|
||||
unusedMainObjectNodes[obj.GetHashCode().ToString()] = node;
|
||||
else
|
||||
currentSearchResultGroup.AddReference( node );
|
||||
}
|
||||
else // List child GameObject scene objects under their parent GameObject
|
||||
{
|
||||
string dictionaryKey = searchedTopmostGameObject.GetHashCode().ToString();
|
||||
List<ReferenceNode> unusedSubObjectNodesAtPath;
|
||||
if( !unusedSubObjectNodes.TryGetValue( dictionaryKey, out unusedSubObjectNodesAtPath ) )
|
||||
unusedSubObjectNodes[dictionaryKey] = unusedSubObjectNodesAtPath = new List<ReferenceNode>( 2 );
|
||||
|
||||
unusedSubObjectNodesAtPath.Add( node );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if( AssetDatabase.IsMainAsset( obj ) )
|
||||
unusedMainObjectNodes[assetPath] = node;
|
||||
else
|
||||
{
|
||||
List<ReferenceNode> unusedSubObjectNodesAtPath;
|
||||
if( !unusedSubObjectNodes.TryGetValue( assetPath, out unusedSubObjectNodesAtPath ) )
|
||||
unusedSubObjectNodes[assetPath] = unusedSubObjectNodesAtPath = new List<ReferenceNode>( 2 );
|
||||
|
||||
unusedSubObjectNodesAtPath.Add( node );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
foreach( KeyValuePair<string, ReferenceNode> kvPair in unusedMainObjectNodes )
|
||||
{
|
||||
List<ReferenceNode> unusedSubAssetNodesAtPath;
|
||||
if( unusedSubObjectNodes.TryGetValue( kvPair.Key, out unusedSubAssetNodesAtPath ) )
|
||||
{
|
||||
currentSearchResultGroup.AddReference( kvPair.Value );
|
||||
for( int i = 0; i < unusedSubAssetNodesAtPath.Count; i++ )
|
||||
kvPair.Value.AddLinkTo( unusedSubAssetNodesAtPath[i] );
|
||||
|
||||
if( usedObjectPathsSet.Contains( kvPair.Key ) )
|
||||
kvPair.Value.usedState = ReferenceNode.UsedState.MixedCollapsed;
|
||||
|
||||
unusedSubObjectNodes.Remove( kvPair.Key );
|
||||
}
|
||||
else if( !usedObjectPathsSet.Contains( kvPair.Key ) ) // If a main asset has sub-assets and all of them are used, consider the main asset as used, as well (especially useful for Sprite assets)
|
||||
currentSearchResultGroup.AddReference( kvPair.Value );
|
||||
else if( !AssetDatabase.Contains( (Object) kvPair.Value.nodeObject ) )
|
||||
{
|
||||
currentSearchResultGroup.AddReference( kvPair.Value );
|
||||
kvPair.Value.usedState = ReferenceNode.UsedState.MixedCollapsed;
|
||||
}
|
||||
}
|
||||
|
||||
foreach( KeyValuePair<string, List<ReferenceNode>> kvPair in unusedSubObjectNodes ) // These aren't linked to any unusedMainObjectNodes, add them as root nodes to the search result group
|
||||
{
|
||||
foreach( ReferenceNode node in kvPair.Value )
|
||||
currentSearchResultGroup.AddReference( node );
|
||||
}
|
||||
|
||||
if( currentSearchResultGroup.NumberOfReferences > 0 )
|
||||
{
|
||||
for( int i = 0; i < currentSearchResultGroup.NumberOfReferences; i++ )
|
||||
currentSearchResultGroup[i].InitializeRecursively();
|
||||
|
||||
searchResult.Insert( 0, currentSearchResultGroup );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -787,18 +980,12 @@ namespace AssetUsageDetectorNamespace
|
||||
bool searchingSourceAsset = searchingSourceAssets && ReferenceEquals( currentSearchedObject, obj );
|
||||
|
||||
// Hashing does not work well with structs all the time, don't cache search results for structs
|
||||
string objHash = null;
|
||||
if( !( obj is ValueType ) )
|
||||
if( !( obj is ValueType ) && !searchingSourceAsset )
|
||||
{
|
||||
objHash = obj.Hash();
|
||||
|
||||
if( !searchingSourceAsset )
|
||||
{
|
||||
// If object was searched before, return the cached result
|
||||
ReferenceNode cachedResult;
|
||||
if( searchedObjects.TryGetValue( objHash, out cachedResult ) )
|
||||
return cachedResult;
|
||||
}
|
||||
// If object was searched before, return the cached result
|
||||
ReferenceNode cachedResult;
|
||||
if( TryGetReferenceNode( obj, out cachedResult ) )
|
||||
return cachedResult;
|
||||
}
|
||||
|
||||
searchedObjectsCount++;
|
||||
@@ -813,14 +1000,14 @@ namespace AssetUsageDetectorNamespace
|
||||
{
|
||||
if( assetsToSearchSet.Count == 0 )
|
||||
{
|
||||
searchedObjects.Add( objHash, null );
|
||||
searchedUnityObjects.Add( unityObject.GetHashCode(), null );
|
||||
return null;
|
||||
}
|
||||
|
||||
assetPath = AssetDatabase.GetAssetPath( unityObject );
|
||||
if( !AssetHasAnyReference( assetPath ) )
|
||||
if( excludedAssetsPathsSet.Contains( assetPath ) || !AssetHasAnyReference( assetPath ) )
|
||||
{
|
||||
searchedObjects.Add( objHash, null );
|
||||
searchedUnityObjects.Add( unityObject.GetHashCode(), null );
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -841,6 +1028,23 @@ namespace AssetUsageDetectorNamespace
|
||||
SearchVariablesWithSerializedObject( result );
|
||||
}
|
||||
|
||||
// A prefab asset should have a link to its children because when a scene object uses a prefab and a child of that prefab uses
|
||||
// a searched object, the scene object needs to appear in the search results. Since prefab assets aren't automatically linked to
|
||||
// their children, we need to create that link manually
|
||||
if( assetPath != null && unityObject is GameObject && AssetDatabase.IsMainAsset( unityObject ) )
|
||||
{
|
||||
if( result == null )
|
||||
result = PopReferenceNode( unityObject );
|
||||
|
||||
GameObject prefabGameObject = (GameObject) unityObject;
|
||||
Transform[] prefabChildren = prefabGameObject.GetComponentsInChildren<Transform>( true );
|
||||
for( int i = 0; i < prefabChildren.Length; i++ )
|
||||
{
|
||||
if( prefabChildren[i].gameObject != prefabGameObject )
|
||||
result.AddLinkTo( SearchObject( prefabChildren[i].gameObject ), isWeakLink: true );
|
||||
}
|
||||
}
|
||||
|
||||
callStack.RemoveAt( callStack.Count - 1 );
|
||||
}
|
||||
else
|
||||
@@ -868,13 +1072,18 @@ namespace AssetUsageDetectorNamespace
|
||||
// Cache the search result if we are skimming through a class (not a struct; i.e. objHash != null)
|
||||
// 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)
|
||||
if( objHash != null && ( result != null || unityObject != null || currentDepth == 0 ) )
|
||||
if( !( obj is ValueType ) && ( result != null || unityObject != null || currentDepth == 0 ) )
|
||||
{
|
||||
if( !searchingSourceAsset )
|
||||
searchedObjects.Add( objHash, result );
|
||||
{
|
||||
if( obj is Object )
|
||||
searchedUnityObjects.Add( unityObject.GetHashCode(), result );
|
||||
else
|
||||
searchedObjects.Add( GetNodeObjectHash( obj ), result );
|
||||
}
|
||||
else if( result != null )
|
||||
{
|
||||
result.CopyReferencesTo( searchedObjects[objHash] );
|
||||
result.CopyReferencesTo( searchedUnityObjects[unityObject.GetHashCode()] );
|
||||
PoolReferenceNode( result );
|
||||
}
|
||||
}
|
||||
@@ -926,7 +1135,10 @@ namespace AssetUsageDetectorNamespace
|
||||
// if that happens, log useful information to help reproduce the issue
|
||||
if( lastRefreshedCacheEntry == cacheEntry )
|
||||
{
|
||||
StringBuilder sb = new StringBuilder( 1000 );
|
||||
StringBuilder sb = Utilities.stringBuilder;
|
||||
sb.Length = 0;
|
||||
sb.EnsureCapacity( 1000 );
|
||||
|
||||
sb.AppendLine( "<b>Infinite loop while refreshing a cache entry, please report it to the author.</b>" ).AppendLine();
|
||||
sb.Append( "Asset path: " ).AppendLine( assetPath );
|
||||
|
||||
@@ -995,15 +1207,42 @@ namespace AssetUsageDetectorNamespace
|
||||
return false;
|
||||
}
|
||||
|
||||
// If object was already searched, return its ReferenceNode
|
||||
private bool TryGetReferenceNode( object nodeObject, out ReferenceNode referenceNode )
|
||||
{
|
||||
if( nodeObject is Object )
|
||||
{
|
||||
if( searchedUnityObjects.TryGetValue( nodeObject.GetHashCode(), out referenceNode ) )
|
||||
return true;
|
||||
}
|
||||
else if( searchedObjects.TryGetValue( GetNodeObjectHash( nodeObject ), out referenceNode ) )
|
||||
return true;
|
||||
|
||||
referenceNode = null;
|
||||
return false;
|
||||
}
|
||||
|
||||
// Get reference node for object
|
||||
private ReferenceNode GetReferenceNode( object nodeObject )
|
||||
{
|
||||
ReferenceNode result;
|
||||
string hash = nodeObject.Hash();
|
||||
if( !searchedObjects.TryGetValue( hash, out result ) || result == null )
|
||||
if( nodeObject is Object )
|
||||
{
|
||||
result = PopReferenceNode( nodeObject );
|
||||
searchedObjects[hash] = result;
|
||||
int hash = nodeObject.GetHashCode();
|
||||
if( !searchedUnityObjects.TryGetValue( hash, out result ) || result == null )
|
||||
{
|
||||
result = PopReferenceNode( nodeObject );
|
||||
searchedUnityObjects[hash] = result;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
string hash = GetNodeObjectHash( nodeObject );
|
||||
if( !searchedObjects.TryGetValue( hash, out result ) || result == null )
|
||||
{
|
||||
result = PopReferenceNode( nodeObject );
|
||||
searchedObjects[hash] = result;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
@@ -1033,6 +1272,12 @@ namespace AssetUsageDetectorNamespace
|
||||
nodesPool.Add( node );
|
||||
}
|
||||
|
||||
// Get a unique-ish string hash code for a plain C# object (i.e. non-UnityEngine.Object object)
|
||||
private string GetNodeObjectHash( object nodeObject )
|
||||
{
|
||||
return nodeObject.GetHashCode() + nodeObject.GetType().Name;
|
||||
}
|
||||
|
||||
// Retrieve the game objects listed under the DontDestroyOnLoad scene
|
||||
private GameObject[] GetDontDestroyOnLoadObjects()
|
||||
{
|
||||
@@ -1053,5 +1298,48 @@ namespace AssetUsageDetectorNamespace
|
||||
Object.DestroyImmediate( temp );
|
||||
}
|
||||
}
|
||||
|
||||
// Appends contents of callStack to StringBuilder and returns the most recent Unity object in callStack
|
||||
private Object AppendCallStackToStringBuilder( StringBuilder sb )
|
||||
{
|
||||
Object latestUnityObjectInCallStack = null;
|
||||
if( callStack.Count > 0 )
|
||||
{
|
||||
sb.AppendLine().AppendLine( "Stack contents: " );
|
||||
|
||||
for( int i = callStack.Count - 1; i >= 0; i-- )
|
||||
{
|
||||
latestUnityObjectInCallStack = callStack[i] as Object;
|
||||
if( latestUnityObjectInCallStack )
|
||||
{
|
||||
if( !AssetDatabase.Contains( latestUnityObjectInCallStack ) )
|
||||
{
|
||||
string scenePath = AssetDatabase.GetAssetOrScenePath( latestUnityObjectInCallStack );
|
||||
if( !string.IsNullOrEmpty( scenePath ) && SceneManager.GetSceneByPath( scenePath ).IsValid() )
|
||||
sb.Append( "Scene: " ).AppendLine( scenePath );
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
for( int i = callStack.Count - 1; i >= 0; i-- )
|
||||
{
|
||||
sb.Append( i ).Append( ": " );
|
||||
|
||||
Object unityObject = callStack[i] as Object;
|
||||
if( unityObject )
|
||||
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>>" );
|
||||
}
|
||||
|
||||
sb.AppendLine();
|
||||
}
|
||||
|
||||
return latestUnityObjectInCallStack;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -51,10 +51,35 @@ namespace AssetUsageDetectorNamespace
|
||||
if( fileSizes == null || fileSizes.Length != dependencies.Length )
|
||||
fileSizes = new long[dependencies.Length];
|
||||
|
||||
for( int i = 0; i < dependencies.Length; i++ )
|
||||
int length = dependencies.Length;
|
||||
for( int i = 0; i < length; i++ )
|
||||
{
|
||||
FileInfo assetFile = new FileInfo( dependencies[i] );
|
||||
fileSizes[i] = assetFile.Exists ? assetFile.Length : 0L;
|
||||
if( !string.IsNullOrEmpty( dependencies[i] ) )
|
||||
{
|
||||
FileInfo assetFile = new FileInfo( dependencies[i] );
|
||||
fileSizes[i] = assetFile.Exists ? assetFile.Length : 0L;
|
||||
}
|
||||
else
|
||||
{
|
||||
// This dependency is empty which causes issues when passed to FileInfo constructor
|
||||
// Find a non-empty dependency and move it to this index
|
||||
for( int j = length - 1; j > i; j--, length-- )
|
||||
{
|
||||
if( !string.IsNullOrEmpty( dependencies[j] ) )
|
||||
{
|
||||
dependencies[i--] = dependencies[j];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
length--;
|
||||
}
|
||||
}
|
||||
|
||||
if( length != fileSizes.Length )
|
||||
{
|
||||
Array.Resize( ref dependencies, length );
|
||||
Array.Resize( ref fileSizes, length );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ using System.Collections.Generic;
|
||||
using System.Collections;
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
using UnityEditor;
|
||||
using UnityEditor.Animations;
|
||||
using UnityEngine;
|
||||
@@ -165,8 +166,9 @@ namespace AssetUsageDetectorNamespace
|
||||
private readonly Dictionary<Type, VariableGetterHolder[]> typeToVariables = new Dictionary<Type, VariableGetterHolder[]>( 4096 );
|
||||
private readonly List<VariableGetterHolder> validVariables = new List<VariableGetterHolder>( 32 );
|
||||
|
||||
// Dictionary to store whether or not instances of a Type can be searched with SearchVariablesWithSerializedObject
|
||||
private readonly Dictionary<Type, bool> typesSearchabilityWithSerializedObject = new Dictionary<Type, bool>( 4096 );
|
||||
// All MonoScripts in objectsToSearchSet
|
||||
private readonly List<MonoScript> monoScriptsToSearch = new List<MonoScript>();
|
||||
private readonly List<Type> monoScriptsToSearchTypes = new List<Type>();
|
||||
|
||||
// Path(s) of .cginc, .cg, .hlsl and .glslinc assets in assetsToSearchSet
|
||||
private readonly HashSet<string> shaderIncludesToSearchSet = new HashSet<string>();
|
||||
@@ -181,8 +183,6 @@ namespace AssetUsageDetectorNamespace
|
||||
|
||||
private bool searchPrefabConnections;
|
||||
private bool searchMonoBehavioursForScript;
|
||||
private bool searchRenderers;
|
||||
private bool searchMaterialsForShader;
|
||||
private bool searchTextureReferences;
|
||||
#if UNITY_2018_1_OR_NEWER
|
||||
private bool searchShaderGraphsForSubGraphs;
|
||||
@@ -194,6 +194,10 @@ namespace AssetUsageDetectorNamespace
|
||||
private BindingFlags fieldModifiers, propertyModifiers;
|
||||
private BindingFlags prevFieldModifiers, prevPropertyModifiers;
|
||||
|
||||
// Unity's internal function that returns a SerializedProperty's corresponding FieldInfo
|
||||
private delegate FieldInfo FieldInfoGetter( SerializedProperty p, out Type t );
|
||||
private FieldInfoGetter fieldInfoGetter;
|
||||
|
||||
private void InitializeSearchFunctionsData( Parameters searchParameters )
|
||||
{
|
||||
if( typeToSearchFunction == null )
|
||||
@@ -253,8 +257,6 @@ namespace AssetUsageDetectorNamespace
|
||||
|
||||
searchPrefabConnections = false;
|
||||
searchMonoBehavioursForScript = false;
|
||||
searchRenderers = false;
|
||||
searchMaterialsForShader = false;
|
||||
searchTextureReferences = false;
|
||||
#if UNITY_2018_1_OR_NEWER
|
||||
searchShaderGraphsForSubGraphs = false;
|
||||
@@ -262,19 +264,18 @@ namespace AssetUsageDetectorNamespace
|
||||
|
||||
foreach( Object obj in objectsToSearchSet )
|
||||
{
|
||||
if( obj is Texture )
|
||||
{
|
||||
searchRenderers = true;
|
||||
if( obj is Texture || obj is Sprite )
|
||||
searchTextureReferences = true;
|
||||
}
|
||||
else if( obj is Material )
|
||||
searchRenderers = true;
|
||||
else if( obj is MonoScript )
|
||||
searchMonoBehavioursForScript = true;
|
||||
else if( obj is Shader )
|
||||
{
|
||||
searchRenderers = true;
|
||||
searchMaterialsForShader = true;
|
||||
searchMonoBehavioursForScript = true;
|
||||
|
||||
Type monoScriptType = ( (MonoScript) obj ).GetClass();
|
||||
if( monoScriptType != null && !monoScriptType.IsSealed )
|
||||
{
|
||||
monoScriptsToSearch.Add( (MonoScript) obj );
|
||||
monoScriptsToSearchTypes.Add( monoScriptType );
|
||||
}
|
||||
}
|
||||
else if( obj is GameObject )
|
||||
searchPrefabConnections = true;
|
||||
@@ -284,6 +285,13 @@ namespace AssetUsageDetectorNamespace
|
||||
#endif
|
||||
}
|
||||
|
||||
// We need to search for class/interface inheritance references manually because AssetDatabase.GetDependencies doesn't take that into account
|
||||
if( monoScriptsToSearch.Count > 0 )
|
||||
{
|
||||
alwaysSearchedExtensionsSet.Add( "cs" );
|
||||
alwaysSearchedExtensionsSet.Add( "dll" );
|
||||
}
|
||||
|
||||
foreach( string path in assetsToSearchPathsSet )
|
||||
{
|
||||
string extension = Utilities.GetFileExtension( path );
|
||||
@@ -330,6 +338,13 @@ namespace AssetUsageDetectorNamespace
|
||||
alwaysSearchedExtensionsSet.Add( "shadersubgraph" );
|
||||
}
|
||||
#endif
|
||||
|
||||
#if UNITY_2019_3_OR_NEWER
|
||||
MethodInfo fieldInfoGetterMethod = typeof( Editor ).Assembly.GetType( "UnityEditor.ScriptAttributeUtility" ).GetMethod( "GetFieldInfoAndStaticTypeFromProperty", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static );
|
||||
#else
|
||||
MethodInfo fieldInfoGetterMethod = typeof( Editor ).Assembly.GetType( "UnityEditor.ScriptAttributeUtility" ).GetMethod( "GetFieldInfoFromProperty", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static );
|
||||
#endif
|
||||
fieldInfoGetter = (FieldInfoGetter) Delegate.CreateDelegate( typeof( FieldInfoGetter ), fieldInfoGetterMethod );
|
||||
}
|
||||
|
||||
private ReferenceNode SearchGameObject( Object unityObject )
|
||||
@@ -341,18 +356,22 @@ namespace AssetUsageDetectorNamespace
|
||||
if( searchPrefabConnections )
|
||||
{
|
||||
#if UNITY_2018_3_OR_NEWER
|
||||
Object prefab = PrefabUtility.GetCorrespondingObjectFromSource( go );
|
||||
#else
|
||||
Object prefab = PrefabUtility.GetPrefabParent( go );
|
||||
Object prefab = go;
|
||||
while( prefab = PrefabUtility.GetCorrespondingObjectFromSource( prefab ) )
|
||||
#endif
|
||||
if( objectsToSearchSet.Contains( prefab ) && assetsToSearchRootPrefabs.ContainsFast( prefab as GameObject ) )
|
||||
referenceNode.AddLinkTo( GetReferenceNode( prefab ), "Prefab object" );
|
||||
{
|
||||
#if !UNITY_2018_3_OR_NEWER
|
||||
Object prefab = PrefabUtility.GetPrefabParent( go );
|
||||
#endif
|
||||
if( objectsToSearchSet.Contains( prefab ) && assetsToSearchRootPrefabs.ContainsFast( prefab as GameObject ) )
|
||||
referenceNode.AddLinkTo( GetReferenceNode( prefab ), "Prefab object" );
|
||||
}
|
||||
}
|
||||
|
||||
// Search through all the components of the object
|
||||
Component[] components = go.GetComponents<Component>();
|
||||
for( int i = 0; i < components.Length; i++ )
|
||||
referenceNode.AddLinkTo( SearchObject( components[i] ) );
|
||||
referenceNode.AddLinkTo( SearchObject( components[i] ), isWeakLink: true );
|
||||
|
||||
return referenceNode;
|
||||
}
|
||||
@@ -370,21 +389,15 @@ namespace AssetUsageDetectorNamespace
|
||||
if( searchMonoBehavioursForScript && component is MonoBehaviour )
|
||||
{
|
||||
// If a searched asset is script, check if this component is an instance of it
|
||||
// Although SearchVariablesWithSerializedObject can detect these references with SerializedObject, it isn't possible when reflection is used in Play mode
|
||||
MonoScript script = MonoScript.FromMonoBehaviour( (MonoBehaviour) component );
|
||||
if( objectsToSearchSet.Contains( script ) )
|
||||
referenceNode.AddLinkTo( GetReferenceNode( script ) );
|
||||
}
|
||||
else if( searchRenderers && component is Renderer )
|
||||
|
||||
if( component is Animation )
|
||||
{
|
||||
// If an asset is a shader, texture or material, and this component is a Renderer,
|
||||
// search it for references
|
||||
Material[] materials = ( (Renderer) component ).sharedMaterials;
|
||||
for( int i = 0; i < materials.Length; i++ )
|
||||
referenceNode.AddLinkTo( SearchObject( materials[i] ) );
|
||||
}
|
||||
else if( component is Animation )
|
||||
{
|
||||
// If this component is an Animation, search its animation clips for references
|
||||
// Search animation clips for references
|
||||
foreach( AnimationState anim in (Animation) component )
|
||||
referenceNode.AddLinkTo( SearchObject( anim.clip ) );
|
||||
|
||||
@@ -393,7 +406,7 @@ namespace AssetUsageDetectorNamespace
|
||||
}
|
||||
else if( component is Animator )
|
||||
{
|
||||
// If this component is an Animator, search its animation clips for references (via AnimatorController)
|
||||
// Search animation clips for references (via AnimatorController)
|
||||
referenceNode.AddLinkTo( SearchObject( ( (Animator) component ).runtimeAnimatorController ) );
|
||||
|
||||
// Search the objects that are animated by this Animator component for references
|
||||
@@ -402,7 +415,7 @@ namespace AssetUsageDetectorNamespace
|
||||
#if UNITY_2017_2_OR_NEWER
|
||||
else if( component is Tilemap )
|
||||
{
|
||||
// If this component is a Tilemap, search its tiles for references
|
||||
// Search the tiles for references
|
||||
TileBase[] tiles = new TileBase[( (Tilemap) component ).GetUsedTilesCount()];
|
||||
( (Tilemap) component ).GetUsedTilesNonAlloc( tiles );
|
||||
|
||||
@@ -416,7 +429,7 @@ namespace AssetUsageDetectorNamespace
|
||||
#if UNITY_2017_1_OR_NEWER
|
||||
else if( component is PlayableDirector )
|
||||
{
|
||||
// If this component is a PlayableDirectory, search its PlayableAsset's scene bindings for references
|
||||
// Search the PlayableAsset's scene bindings for references
|
||||
PlayableAsset playableAsset = ( (PlayableDirector) component ).playableAsset;
|
||||
if( playableAsset != null && !playableAsset.Equals( null ) )
|
||||
{
|
||||
@@ -432,28 +445,55 @@ namespace AssetUsageDetectorNamespace
|
||||
|
||||
private ReferenceNode SearchMaterial( Object unityObject )
|
||||
{
|
||||
const string TEXTURE_PROPERTY_PREFIX = "m_SavedProperties.m_TexEnvs[";
|
||||
|
||||
Material material = (Material) unityObject;
|
||||
ReferenceNode referenceNode = PopReferenceNode( material );
|
||||
|
||||
if( searchMaterialsForShader && objectsToSearchSet.Contains( material.shader ) )
|
||||
referenceNode.AddLinkTo( GetReferenceNode( material.shader ), "Shader" );
|
||||
// We used to search only the shader and the Texture properties in this function but it has changed for 2 major reasons:
|
||||
// 1) Materials can store more than these references now. For example, HDRP materials can have references to other HDRP materials
|
||||
// 2) It wasn't possible to search Texture properties that were no longer used by the shader
|
||||
// Thus, we are searching every property of the material using SerializedObject
|
||||
SearchVariablesWithSerializedObject( referenceNode );
|
||||
|
||||
if( searchTextureReferences )
|
||||
// Post-process the found results and convert links that start with TEXTURE_PROPERTY_PREFIX to their readable names
|
||||
SerializedObject materialSO = null;
|
||||
for( int i = referenceNode.NumberOfOutgoingLinks - 1; i >= 0; i-- )
|
||||
{
|
||||
// Search through all the textures attached to this material
|
||||
// Credit: http://answers.unity3d.com/answers/1116025/view.html
|
||||
Shader shader = material.shader;
|
||||
int shaderPropertyCount = ShaderUtil.GetPropertyCount( shader );
|
||||
for( int i = 0; i < shaderPropertyCount; i++ )
|
||||
List<string> linkDescriptions = referenceNode[i].descriptions;
|
||||
for( int j = linkDescriptions.Count - 1; j >= 0; j-- )
|
||||
{
|
||||
if( ShaderUtil.GetPropertyType( shader, i ) == ShaderUtil.ShaderPropertyType.TexEnv )
|
||||
int texturePropertyPrefixIndex = linkDescriptions[j].IndexOf( TEXTURE_PROPERTY_PREFIX );
|
||||
if( texturePropertyPrefixIndex >= 0 )
|
||||
{
|
||||
string propertyName = ShaderUtil.GetPropertyName( shader, i );
|
||||
Texture assignedTexture = material.GetTexture( propertyName );
|
||||
if( objectsToSearchSet.Contains( assignedTexture ) )
|
||||
referenceNode.AddLinkTo( GetReferenceNode( assignedTexture ), "Shader property: " + propertyName );
|
||||
texturePropertyPrefixIndex += TEXTURE_PROPERTY_PREFIX.Length;
|
||||
int texturePropertyEndIndex = linkDescriptions[j].IndexOf( ']', texturePropertyPrefixIndex );
|
||||
if( texturePropertyEndIndex > texturePropertyPrefixIndex )
|
||||
{
|
||||
int texturePropertyIndex;
|
||||
if( int.TryParse( linkDescriptions[j].Substring( texturePropertyPrefixIndex, texturePropertyEndIndex - texturePropertyPrefixIndex ), out texturePropertyIndex ) )
|
||||
{
|
||||
if( materialSO == null )
|
||||
materialSO = new SerializedObject( material );
|
||||
|
||||
string propertyName = materialSO.FindProperty( "m_SavedProperties.m_TexEnvs.Array.data[" + texturePropertyIndex + "].first" ).stringValue;
|
||||
if( material.HasProperty( propertyName ) )
|
||||
linkDescriptions[j] = "[Property: " + propertyName + "]";
|
||||
else if( searchUnusedMaterialProperties )
|
||||
{
|
||||
// Move unused references to the end of the list so that used references come first
|
||||
linkDescriptions.Add( "[Property (UNUSED): " + propertyName + "]" );
|
||||
linkDescriptions.RemoveAt( j );
|
||||
}
|
||||
else
|
||||
linkDescriptions.RemoveAt( j );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if( linkDescriptions.Count == 0 ) // All shader properties were unused and we weren't searching for unused material properties
|
||||
referenceNode.RemoveLink( i );
|
||||
}
|
||||
|
||||
return referenceNode;
|
||||
@@ -507,7 +547,7 @@ namespace AssetUsageDetectorNamespace
|
||||
return referenceNode;
|
||||
}
|
||||
|
||||
// Searches default UnityEngine.Object values assigned to script variables
|
||||
// Searches class/interface inheritances and default UnityEngine.Object values assigned to script variables
|
||||
private ReferenceNode SearchMonoScript( Object unityObject )
|
||||
{
|
||||
MonoScript script = (MonoScript) unityObject;
|
||||
@@ -515,20 +555,27 @@ namespace AssetUsageDetectorNamespace
|
||||
if( scriptType == null || ( !scriptType.IsSubclassOf( typeof( MonoBehaviour ) ) && !scriptType.IsSubclassOf( typeof( ScriptableObject ) ) ) )
|
||||
return null;
|
||||
|
||||
MonoImporter scriptImporter = AssetImporter.GetAtPath( AssetDatabase.GetAssetPath( unityObject ) ) as MonoImporter;
|
||||
if( scriptImporter == null )
|
||||
return null;
|
||||
|
||||
ReferenceNode referenceNode = PopReferenceNode( script );
|
||||
|
||||
VariableGetterHolder[] variables = GetFilteredVariablesForType( scriptType );
|
||||
for( int i = 0; i < variables.Length; i++ )
|
||||
// Check for class/interface inheritance references
|
||||
for( int i = monoScriptsToSearch.Count - 1; i >= 0; i-- )
|
||||
{
|
||||
if( variables[i].isSerializable && !variables[i].isProperty )
|
||||
if( monoScriptsToSearchTypes[i] != scriptType && monoScriptsToSearchTypes[i].IsAssignableFrom( scriptType ) )
|
||||
referenceNode.AddLinkTo( GetReferenceNode( monoScriptsToSearch[i] ), monoScriptsToSearchTypes[i].IsInterface ? "Implements interface" : "Extends class" );
|
||||
}
|
||||
|
||||
MonoImporter scriptImporter = AssetImporter.GetAtPath( AssetDatabase.GetAssetPath( unityObject ) ) as MonoImporter;
|
||||
if( scriptImporter != null )
|
||||
{
|
||||
VariableGetterHolder[] variables = GetFilteredVariablesForType( scriptType );
|
||||
for( int i = 0; i < variables.Length; i++ )
|
||||
{
|
||||
Object defaultValue = scriptImporter.GetDefaultReference( variables[i].name );
|
||||
if( objectsToSearchSet.Contains( defaultValue ) )
|
||||
referenceNode.AddLinkTo( GetReferenceNode( defaultValue ), "Default Variable Value: " + variables[i].name );
|
||||
if( variables[i].isSerializable && !variables[i].isProperty )
|
||||
{
|
||||
Object defaultValue = scriptImporter.GetDefaultReference( variables[i].name );
|
||||
if( objectsToSearchSet.Contains( defaultValue ) )
|
||||
referenceNode.AddLinkTo( GetReferenceNode( defaultValue ), "Default variable value: " + variables[i].name );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -553,6 +600,13 @@ namespace AssetUsageDetectorNamespace
|
||||
}
|
||||
else
|
||||
{
|
||||
if( controller is AnimatorOverrideController )
|
||||
{
|
||||
RuntimeAnimatorController parentController = ( (AnimatorOverrideController) controller ).runtimeAnimatorController;
|
||||
if( objectsToSearchSet.Contains( parentController ) )
|
||||
referenceNode.AddLinkTo( GetReferenceNode( parentController ) );
|
||||
}
|
||||
|
||||
AnimationClip[] animClips = controller.animationClips;
|
||||
for( int i = 0; i < animClips.Length; i++ )
|
||||
referenceNode.AddLinkTo( SearchObject( animClips[i] ) );
|
||||
@@ -669,19 +723,61 @@ namespace AssetUsageDetectorNamespace
|
||||
if( packables != null )
|
||||
{
|
||||
for( int i = 0; i < packables.Length; i++ )
|
||||
referenceNode.AddLinkTo( SearchObject( packables[i] ), "Packed Texture" );
|
||||
SearchSpriteAtlas( referenceNode, packables[i] );
|
||||
}
|
||||
#else
|
||||
SerializedProperty packables = spriteAtlasSO.FindProperty( "m_EditorData.packables" );
|
||||
if( packables != null )
|
||||
{
|
||||
for( int i = 0, length = packables.arraySize; i < length; i++ )
|
||||
referenceNode.AddLinkTo( SearchObject( packables.GetArrayElementAtIndex( i ).objectReferenceValue ), "Packed Texture" );
|
||||
SearchSpriteAtlas( referenceNode, packables.GetArrayElementAtIndex( i ).objectReferenceValue );
|
||||
}
|
||||
#endif
|
||||
|
||||
return referenceNode;
|
||||
}
|
||||
|
||||
private void SearchSpriteAtlas( ReferenceNode referenceNode, Object packedAsset )
|
||||
{
|
||||
if( packedAsset == null || packedAsset.Equals( null ) )
|
||||
return;
|
||||
|
||||
referenceNode.AddLinkTo( SearchObject( packedAsset ), "Packed Texture" );
|
||||
|
||||
if( packedAsset is Texture )
|
||||
{
|
||||
// Search the Texture's sprites if the Texture asset isn't included in the "SEARCHED OBJECTS" list (i.e. user has
|
||||
// added only a Sprite sub-asset of the Texture to the list, not the Texture asset itself). Otherwise, references to
|
||||
// both the Texture and its sprites will be found which can be considered as duplicate references
|
||||
if( AssetDatabase.IsMainAsset( packedAsset ) && !assetsToSearchSet.Contains( packedAsset ) )
|
||||
{
|
||||
Object[] textureSubAssets = AssetDatabase.LoadAllAssetRepresentationsAtPath( AssetDatabase.GetAssetPath( packedAsset ) );
|
||||
for( int i = 0; i < textureSubAssets.Length; i++ )
|
||||
{
|
||||
if( textureSubAssets[i] is Sprite )
|
||||
referenceNode.AddLinkTo( SearchObject( textureSubAssets[i] ), "Packed Texture" );
|
||||
}
|
||||
}
|
||||
}
|
||||
else if( packedAsset.IsFolder() )
|
||||
{
|
||||
// Search all Sprites in the folder
|
||||
string[] texturesInFolder = AssetDatabase.FindAssets( "t:Texture2D", new string[] { AssetDatabase.GetAssetPath( packedAsset ) } );
|
||||
if( texturesInFolder != null )
|
||||
{
|
||||
for( int i = 0; i < texturesInFolder.Length; i++ )
|
||||
{
|
||||
string texturePath = AssetDatabase.GUIDToAssetPath( texturesInFolder[i] );
|
||||
TextureImporter textureImporter = AssetImporter.GetAtPath( texturePath ) as TextureImporter;
|
||||
if( textureImporter != null && textureImporter.textureType == TextureImporterType.Sprite )
|
||||
{
|
||||
// Search the Texture and its sprites
|
||||
SearchSpriteAtlas( referenceNode, AssetDatabase.LoadMainAssetAtPath( texturePath ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#if UNITY_2017_3_OR_NEWER
|
||||
@@ -711,9 +807,12 @@ namespace AssetUsageDetectorNamespace
|
||||
#else
|
||||
string assemblyPath = CompilationPipeline.GetAssemblyDefinitionFilePathFromAssemblyName( assemblyDefinitionFile.references[i] );
|
||||
#endif
|
||||
Object searchedAssemblyDefinitionFile;
|
||||
if( assemblyDefinitionFilesToSearch.TryGetValue( assemblyPath, out searchedAssemblyDefinitionFile ) )
|
||||
referenceNode.AddLinkTo( GetReferenceNode( searchedAssemblyDefinitionFile ), "Referenced Assembly" );
|
||||
if( !string.IsNullOrEmpty( assemblyPath ) )
|
||||
{
|
||||
Object searchedAssemblyDefinitionFile;
|
||||
if( assemblyDefinitionFilesToSearch.TryGetValue( assemblyPath, out searchedAssemblyDefinitionFile ) )
|
||||
referenceNode.AddLinkTo( GetReferenceNode( searchedAssemblyDefinitionFile ), "Referenced Assembly" );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -860,6 +959,9 @@ namespace AssetUsageDetectorNamespace
|
||||
for( int i = 0; i < clips.Length; i++ )
|
||||
{
|
||||
AnimationClip clip = clips[i];
|
||||
if( !clip )
|
||||
continue;
|
||||
|
||||
bool isClipUnique = true;
|
||||
for( int j = i - 1; j >= 0; j-- )
|
||||
{
|
||||
@@ -967,40 +1069,50 @@ namespace AssetUsageDetectorNamespace
|
||||
{
|
||||
if( !isInPlayMode || referenceNode.nodeObject.IsAsset() )
|
||||
{
|
||||
// Some Types can be searched with SearchVariablesWithReflection only
|
||||
Type nodeObjectType = referenceNode.nodeObject.GetType();
|
||||
bool typeSearchability;
|
||||
if( !typesSearchabilityWithSerializedObject.TryGetValue( nodeObjectType, out typeSearchability ) )
|
||||
{
|
||||
// typesSearchabilityWithSerializedObject is updated when GetFilteredVariablesForType is called
|
||||
GetFilteredVariablesForType( nodeObjectType );
|
||||
typeSearchability = typesSearchabilityWithSerializedObject[nodeObjectType];
|
||||
}
|
||||
|
||||
if( !typeSearchability )
|
||||
{
|
||||
SearchVariablesWithReflection( referenceNode );
|
||||
return;
|
||||
}
|
||||
|
||||
SerializedObject so = new SerializedObject( (Object) referenceNode.nodeObject );
|
||||
SerializedProperty iterator = so.GetIterator();
|
||||
if( iterator.NextVisible( true ) )
|
||||
SerializedProperty iteratorVisible = so.GetIterator();
|
||||
if( iterator.Next( true ) )
|
||||
{
|
||||
bool iteratingVisible = iteratorVisible.NextVisible( true );
|
||||
bool enterChildren;
|
||||
do
|
||||
{
|
||||
// Iterate over NextVisible properties AND the properties that have corresponding FieldInfos (internal Unity
|
||||
// properties don't have FieldInfos so we are skipping them, which is good because search results found in
|
||||
// those properties aren't interesting and mostly confusing)
|
||||
bool isVisible = iteratingVisible && SerializedProperty.EqualContents( iterator, iteratorVisible );
|
||||
if( isVisible )
|
||||
iteratingVisible = iteratorVisible.NextVisible( iteratorVisible.propertyType == SerializedPropertyType.Generic );
|
||||
else
|
||||
{
|
||||
Type propFieldType;
|
||||
isVisible = iterator.type == "Array" || fieldInfoGetter( iterator, out propFieldType ) != null;
|
||||
}
|
||||
|
||||
if( !isVisible )
|
||||
{
|
||||
enterChildren = false;
|
||||
continue;
|
||||
}
|
||||
|
||||
ReferenceNode searchResult;
|
||||
switch( iterator.propertyType )
|
||||
{
|
||||
case SerializedPropertyType.ObjectReference:
|
||||
searchResult = SearchObject( iterator.objectReferenceValue );
|
||||
searchResult = SearchObject( PreferablyGameObject( iterator.objectReferenceValue ) );
|
||||
enterChildren = false;
|
||||
break;
|
||||
case SerializedPropertyType.ExposedReference:
|
||||
searchResult = SearchObject( iterator.exposedReferenceValue );
|
||||
searchResult = SearchObject( PreferablyGameObject( iterator.exposedReferenceValue ) );
|
||||
enterChildren = false;
|
||||
break;
|
||||
#if UNITY_2019_3_OR_NEWER
|
||||
case SerializedPropertyType.ManagedReference:
|
||||
searchResult = SearchObject( PreferablyGameObject( GetRawSerializedPropertyValue( iterator ) ) );
|
||||
enterChildren = false;
|
||||
break;
|
||||
#endif
|
||||
case SerializedPropertyType.Generic:
|
||||
searchResult = null;
|
||||
enterChildren = true;
|
||||
@@ -1017,9 +1129,9 @@ namespace AssetUsageDetectorNamespace
|
||||
|
||||
// m_RD.texture is a redundant reference that shows up when searching sprites
|
||||
if( !propertyPath.EndsWithFast( "m_RD.texture" ) )
|
||||
referenceNode.AddLinkTo( searchResult, "Variable: " + propertyPath );
|
||||
referenceNode.AddLinkTo( searchResult, "Variable: " + propertyPath.Replace( ".Array.data[", "[" ) ); // "arrayVariable.Array.data[0]" becomes "arrayVariable[0]"
|
||||
}
|
||||
} while( iterator.NextVisible( enterChildren ) );
|
||||
} while( iterator.Next( enterChildren ) );
|
||||
|
||||
return;
|
||||
}
|
||||
@@ -1043,14 +1155,14 @@ namespace AssetUsageDetectorNamespace
|
||||
try
|
||||
{
|
||||
object variableValue = variables[i].Get( referenceNode.nodeObject );
|
||||
if( variableValue == null )
|
||||
if( variableValue == null || variableValue.Equals( null ) )
|
||||
continue;
|
||||
|
||||
// Values stored inside ICollection objects are searched using IEnumerable,
|
||||
// no need to have duplicate search entries
|
||||
if( !( variableValue is ICollection ) )
|
||||
{
|
||||
ReferenceNode searchResult = SearchObject( variableValue );
|
||||
ReferenceNode searchResult = SearchObject( PreferablyGameObject( variableValue ) );
|
||||
if( searchResult != null && searchResult != referenceNode )
|
||||
referenceNode.AddLinkTo( searchResult, ( variables[i].isProperty ? "Property: " : "Variable: " ) + variables[i].name );
|
||||
}
|
||||
@@ -1062,7 +1174,7 @@ namespace AssetUsageDetectorNamespace
|
||||
int index = 0;
|
||||
foreach( object element in (IEnumerable) variableValue )
|
||||
{
|
||||
ReferenceNode searchResult = SearchObject( element );
|
||||
ReferenceNode searchResult = SearchObject( PreferablyGameObject( element ) );
|
||||
if( searchResult != null && searchResult != referenceNode )
|
||||
referenceNode.AddLinkTo( searchResult, string.Concat( variables[i].isProperty ? "Property: " : "Variable: ", variables[i].name, "[", index + "]" ) );
|
||||
|
||||
@@ -1074,6 +1186,18 @@ namespace AssetUsageDetectorNamespace
|
||||
catch( MissingReferenceException ) { }
|
||||
catch( MissingComponentException ) { }
|
||||
catch( NotImplementedException ) { }
|
||||
catch( Exception e )
|
||||
{
|
||||
// Unknown exceptions usually occur when variableValue is an IEnumerable and its enumerator throws an unhandled exception in MoveNext or Current
|
||||
StringBuilder sb = Utilities.stringBuilder;
|
||||
sb.Length = 0;
|
||||
sb.EnsureCapacity( callStack.Count * 50 + 1000 );
|
||||
|
||||
sb.Append( "Skipped searching " ).Append( referenceNode.nodeObject.GetType().FullName ).Append( "." ).Append( variables[i].name ).AppendLine( " because it threw exception:" ).Append( e ).AppendLine();
|
||||
|
||||
Object latestUnityObjectInCallStack = AppendCallStackToStringBuilder( sb );
|
||||
Debug.LogWarning( sb.ToString(), latestUnityObjectInCallStack );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1084,10 +1208,6 @@ namespace AssetUsageDetectorNamespace
|
||||
if( typeToVariables.TryGetValue( type, out result ) )
|
||||
return result;
|
||||
|
||||
// SearchVariablesWithSerializedObject function can't iterate over fields that have HideInInspector
|
||||
// or SerializeReference attributes. Types that have such variables must be searched with reflection
|
||||
bool searchabilityWithSerializedObject = true;
|
||||
|
||||
// This is the first time this type of object is seen, filter and cache its variables
|
||||
// Variable filtering process:
|
||||
// 1- skip Obsolete variables
|
||||
@@ -1126,17 +1246,7 @@ namespace AssetUsageDetectorNamespace
|
||||
|
||||
VariableGetVal getter = field.CreateGetter( type );
|
||||
if( getter != null )
|
||||
{
|
||||
validVariables.Add( new VariableGetterHolder( field, getter, searchSerializableVariablesOnly ? field.IsSerializable() : true ) );
|
||||
|
||||
if( searchabilityWithSerializedObject && Attribute.IsDefined( field, typeof( HideInInspector ) ) )
|
||||
searchabilityWithSerializedObject = false;
|
||||
|
||||
#if UNITY_2019_3_OR_NEWER
|
||||
if( searchabilityWithSerializedObject && Attribute.IsDefined( field, typeof( SerializeReference ) ) )
|
||||
searchabilityWithSerializedObject = false;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
currType = currType.BaseType;
|
||||
@@ -1174,22 +1284,20 @@ namespace AssetUsageDetectorNamespace
|
||||
if( propertyGetter.GetBaseDefinition().DeclaringType != propertyGetter.DeclaringType )
|
||||
continue;
|
||||
|
||||
// Additional filtering for properties:
|
||||
// 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
|
||||
// 3 & 4- Prevent accessing properties of Unity that instantiate an existing resource (causing memory leak)
|
||||
string propertyName = property.Name;
|
||||
|
||||
// Ignore "gameObject", "transform", "rectTransform" and "attachedRigidbody" properties of components to get more useful results
|
||||
if( typeof( Component ).IsAssignableFrom( currType ) && ( propertyName == "gameObject" ||
|
||||
propertyName == "transform" || propertyName == "attachedRigidbody" || propertyName == "rectTransform" ) )
|
||||
continue;
|
||||
// Ignore "canvasRenderer" and "canvas" properties of Graphic components to get more useful results
|
||||
else if( typeof( Graphic ).IsAssignableFrom( currType ) &&
|
||||
( propertyName == "canvasRenderer" || propertyName == "canvas" ) )
|
||||
continue;
|
||||
// Prevent accessing properties of Unity that instantiate an existing resource (causing memory leak)
|
||||
else if( typeof( MeshFilter ).IsAssignableFrom( currType ) && propertyName == "mesh" )
|
||||
continue;
|
||||
else if( typeof( Renderer ).IsAssignableFrom( currType ) &&
|
||||
( propertyName == "sharedMaterial" || propertyName == "sharedMaterials" ) )
|
||||
continue;
|
||||
// Same as above
|
||||
else if( ( propertyName == "material" || propertyName == "materials" ) &&
|
||||
( typeof( Renderer ).IsAssignableFrom( currType ) || typeof( Collider ).IsAssignableFrom( currType ) ||
|
||||
#if !UNITY_2019_3_OR_NEWER
|
||||
@@ -1199,6 +1307,15 @@ namespace AssetUsageDetectorNamespace
|
||||
#endif
|
||||
typeof( Collider2D ).IsAssignableFrom( currType ) ) )
|
||||
continue;
|
||||
// Ignore "parameters" property of Animator since it doesn't contain any useful data and logs a warning to the console when Animator is inactive
|
||||
else if( typeof( Animator ).IsAssignableFrom( currType ) && propertyName == "parameters" )
|
||||
continue;
|
||||
// Ignore "spriteAnimator" property of TMP_Text component because this property adds a TMP_SpriteAnimator component to the object if it doesn't exist
|
||||
else if( propertyName == "spriteAnimator" && currType.Name == "TMP_Text" )
|
||||
continue;
|
||||
// Ignore "meshFilter" property of TextMeshPro and TMP_SubMesh components because this property adds a MeshFilter component to the object if it doesn't exist
|
||||
else if( propertyName == "meshFilter" && ( currType.Name == "TextMeshPro" || currType.Name == "TMP_SubMesh" ) )
|
||||
continue;
|
||||
else
|
||||
{
|
||||
VariableGetVal getter = property.CreateGetter();
|
||||
@@ -1215,11 +1332,87 @@ namespace AssetUsageDetectorNamespace
|
||||
|
||||
// Cache the filtered fields
|
||||
typeToVariables.Add( type, result );
|
||||
typesSearchabilityWithSerializedObject.Add( type, searchabilityWithSerializedObject );
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
// Credit: http://answers.unity.com/answers/425602/view.html
|
||||
// Returns the raw System.Object value of a SerializedProperty
|
||||
public object GetRawSerializedPropertyValue( SerializedProperty property )
|
||||
{
|
||||
object result = property.serializedObject.targetObject;
|
||||
string[] path = property.propertyPath.Replace( ".Array.data[", "[" ).Split( '.' );
|
||||
for( int i = 0; i < path.Length; i++ )
|
||||
{
|
||||
string pathElement = path[i];
|
||||
|
||||
int arrayStartIndex = pathElement.IndexOf( '[' );
|
||||
if( arrayStartIndex < 0 )
|
||||
result = GetFieldValue( result, pathElement );
|
||||
else
|
||||
{
|
||||
string variableName = pathElement.Substring( 0, arrayStartIndex );
|
||||
|
||||
int arrayEndIndex = pathElement.IndexOf( ']', arrayStartIndex + 1 );
|
||||
int arrayElementIndex = int.Parse( pathElement.Substring( arrayStartIndex + 1, arrayEndIndex - arrayStartIndex - 1 ) );
|
||||
result = GetFieldValue( result, variableName, arrayElementIndex );
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
// Credit: http://answers.unity.com/answers/425602/view.html
|
||||
private object GetFieldValue( object source, string fieldName )
|
||||
{
|
||||
if( source == null )
|
||||
return null;
|
||||
|
||||
FieldInfo fieldInfo = null;
|
||||
Type type = source.GetType();
|
||||
while( fieldInfo == null && type != typeof( object ) )
|
||||
{
|
||||
fieldInfo = type.GetField( fieldName, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly );
|
||||
type = type.BaseType;
|
||||
}
|
||||
|
||||
if( fieldInfo != null )
|
||||
return fieldInfo.GetValue( source );
|
||||
|
||||
PropertyInfo propertyInfo = null;
|
||||
type = source.GetType();
|
||||
while( propertyInfo == null && type != typeof( object ) )
|
||||
{
|
||||
propertyInfo = type.GetProperty( fieldName, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly | BindingFlags.IgnoreCase );
|
||||
type = type.BaseType;
|
||||
}
|
||||
|
||||
if( propertyInfo != null )
|
||||
return propertyInfo.GetValue( source, null );
|
||||
|
||||
if( fieldName.Length > 2 && fieldName.StartsWith( "m_", StringComparison.OrdinalIgnoreCase ) )
|
||||
return GetFieldValue( source, fieldName.Substring( 2 ) );
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
// Credit: http://answers.unity.com/answers/425602/view.html
|
||||
private object GetFieldValue( object source, string fieldName, int arrayIndex )
|
||||
{
|
||||
IEnumerable enumerable = GetFieldValue( source, fieldName ) as IEnumerable;
|
||||
if( enumerable == null )
|
||||
return null;
|
||||
|
||||
if( enumerable is IList )
|
||||
return ( (IList) enumerable )[arrayIndex];
|
||||
|
||||
IEnumerator enumerator = enumerable.GetEnumerator();
|
||||
for( int i = 0; i <= arrayIndex; i++ )
|
||||
enumerator.MoveNext();
|
||||
|
||||
return enumerator.Current;
|
||||
}
|
||||
|
||||
// Iterates over all occurrences of specific key-value pairs in string
|
||||
// Example1: #include "VALUE" valuePrefix=#include, valueWrapperChar="
|
||||
// Example2: "guid": "VALUE" valuePrefix="guid", valueWrapperChar="
|
||||
@@ -1245,5 +1438,12 @@ namespace AssetUsageDetectorNamespace
|
||||
valueAction( str.Substring( valueStartIndex, valueEndIndex - valueStartIndex ) );
|
||||
}
|
||||
}
|
||||
|
||||
// If obj is Component, switches to its GameObject
|
||||
private object PreferablyGameObject( object obj )
|
||||
{
|
||||
Component component = obj as Component;
|
||||
return ( component != null && !component.Equals( null ) ) ? component.gameObject : obj;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,275 @@
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace AssetUsageDetectorNamespace
|
||||
{
|
||||
public static class AssetUsageDetectorSettings
|
||||
{
|
||||
private static readonly GUILayoutOption GL_WIDTH_60 = GUILayout.Width( 60f );
|
||||
|
||||
#region Colors
|
||||
private static Color? m_settingsHeaderColor = null;
|
||||
public static Color SettingsHeaderColor
|
||||
{
|
||||
get { if( m_settingsHeaderColor == null ) m_settingsHeaderColor = GetColor( "AUD_SettingsHeaderTint", Color.cyan ); return m_settingsHeaderColor.Value; }
|
||||
set { if( m_settingsHeaderColor == value ) return; m_settingsHeaderColor = value; SetColor( "AUD_SettingsHeaderTint", value ); }
|
||||
}
|
||||
|
||||
private static Color? m_searchResultGroupHeaderColor = null;
|
||||
public static Color SearchResultGroupHeaderColor
|
||||
{
|
||||
get { if( m_searchResultGroupHeaderColor == null ) m_searchResultGroupHeaderColor = GetColor( "AUD_ResultGroupHeaderTint", Color.cyan ); return m_searchResultGroupHeaderColor.Value; }
|
||||
set { if( m_searchResultGroupHeaderColor == value ) return; m_searchResultGroupHeaderColor = value; SetColor( "AUD_ResultGroupHeaderTint", value ); }
|
||||
}
|
||||
|
||||
private static Color? m_rootRowsBackgroundColor = null;
|
||||
public static Color RootRowsBackgroundColor
|
||||
{
|
||||
get { if( m_rootRowsBackgroundColor == null ) m_rootRowsBackgroundColor = GetColor( "AUD_RootRowsTint", EditorGUIUtility.isProSkin ? new Color( 0f, 1f, 1f, 0.15f ) : new Color( 0f, 1f, 1f, 0.25f ) ); return m_rootRowsBackgroundColor.Value; }
|
||||
set { if( m_rootRowsBackgroundColor == value ) return; m_rootRowsBackgroundColor = value; SetColor( "AUD_RootRowsTint", value ); }
|
||||
}
|
||||
|
||||
private static Color? m_rootRowsBorderColor = null;
|
||||
public static Color RootRowsBorderColor
|
||||
{
|
||||
get { if( m_rootRowsBorderColor == null ) m_rootRowsBorderColor = GetColor( "AUD_RootRowsBorderColor", EditorGUIUtility.isProSkin ? new Color( 0.15f, 0.15f, 0.15f, 1f ) : new Color( 0.375f, 0.375f, 0.375f, 1f ) ); return m_rootRowsBorderColor.Value; }
|
||||
set { if( m_rootRowsBorderColor == value ) return; m_rootRowsBorderColor = value; SetColor( "AUD_RootRowsBorderColor", value ); }
|
||||
}
|
||||
|
||||
private static Color? m_mainReferencesBackgroundColor = null;
|
||||
public static Color MainReferencesBackgroundColor
|
||||
{
|
||||
get { if( m_mainReferencesBackgroundColor == null ) m_mainReferencesBackgroundColor = GetColor( "AUD_MainRefRowsTint", EditorGUIUtility.isProSkin ? new Color( 0f, 0.35f, 0f, 1f ) : new Color( 0.25f, 0.75f, 0.25f, 1f ) ); return m_mainReferencesBackgroundColor.Value; }
|
||||
set { if( m_mainReferencesBackgroundColor == value ) return; m_mainReferencesBackgroundColor = value; SetColor( "AUD_MainRefRowsTint", value ); }
|
||||
}
|
||||
|
||||
private static Color? m_selectedRowsParentTint = null;
|
||||
public static Color SelectedRowParentsTint
|
||||
{
|
||||
get { if( m_selectedRowsParentTint == null ) m_selectedRowsParentTint = GetColor( "AUD_SelectedRowParentsTint", EditorGUIUtility.isProSkin ? new Color( 0.36f, 0.36f, 0.18f, 1f ) : new Color( 0.825f, 0.825f, 0.55f, 1f ) ); return m_selectedRowsParentTint.Value; }
|
||||
set { if( m_selectedRowsParentTint == value ) return; m_selectedRowsParentTint = value; SetColor( "AUD_SelectedRowParentsTint", value ); }
|
||||
}
|
||||
|
||||
private static Color? m_selectedRowOccurrencesColor = null;
|
||||
public static Color SelectedRowOccurrencesColor
|
||||
{
|
||||
get { if( m_selectedRowOccurrencesColor == null ) m_selectedRowOccurrencesColor = GetColor( "AUD_SelectedRowOccurrencesTint", EditorGUIUtility.isProSkin ? new Color( 0f, 0.3f, 0.75f, 1f ) : new Color( 0.25f, 0.75f, 1f, 1f ) ); return m_selectedRowOccurrencesColor.Value; }
|
||||
set { if( m_selectedRowOccurrencesColor == value ) return; m_selectedRowOccurrencesColor = value; SetColor( "AUD_SelectedRowOccurrencesTint", value ); }
|
||||
}
|
||||
|
||||
private static Color? m_treeLinesColor = null;
|
||||
public static Color TreeLinesColor
|
||||
{
|
||||
get { if( m_treeLinesColor == null ) m_treeLinesColor = GetColor( "AUD_TreeLinesColor", EditorGUIUtility.isProSkin ? new Color( 0.65f, 0.65f, 0.65f, 1f ) : new Color( 0.375f, 0.375f, 0.375f, 1f ) ); return m_treeLinesColor.Value; }
|
||||
set { if( m_treeLinesColor == value ) return; m_treeLinesColor = value; SetColor( "AUD_TreeLinesColor", value ); }
|
||||
}
|
||||
|
||||
private static Color? m_highlightedTreeLinesColor = null;
|
||||
public static Color HighlightedTreeLinesColor
|
||||
{
|
||||
get { if( m_highlightedTreeLinesColor == null ) m_highlightedTreeLinesColor = GetColor( "AUD_HighlightTreeLinesColor", Color.cyan ); return m_highlightedTreeLinesColor.Value; }
|
||||
set { if( m_highlightedTreeLinesColor == value ) return; m_highlightedTreeLinesColor = value; SetColor( "AUD_HighlightTreeLinesColor", value ); }
|
||||
}
|
||||
|
||||
private static Color? m_searchMatchingTextColor = null;
|
||||
public static Color SearchMatchingTextColor
|
||||
{
|
||||
get { if( m_searchMatchingTextColor == null ) m_searchMatchingTextColor = GetColor( "AUD_SearchTextColor", Color.red ); return m_searchMatchingTextColor.Value; }
|
||||
set { if( m_searchMatchingTextColor == value ) return; m_searchMatchingTextColor = value; SetColor( "AUD_SearchTextColor", value ); ForEachAssetUsageDetectorWindow( ( window ) => window.OnSettingsChanged( highlightedSearchTextColorChanged: true ) ); }
|
||||
}
|
||||
|
||||
private static Color? m_tooltipDescriptionTextColor = null;
|
||||
public static Color TooltipDescriptionTextColor
|
||||
{
|
||||
get { if( m_tooltipDescriptionTextColor == null ) m_tooltipDescriptionTextColor = GetColor( "AUD_TooltipUsageTextColor", EditorGUIUtility.isProSkin ? new Color( 0f, 0.9f, 0.9f, 1f ) : new Color( 0.9f, 0f, 0f, 1f ) ); return m_tooltipDescriptionTextColor.Value; }
|
||||
set { if( m_tooltipDescriptionTextColor == value ) return; m_tooltipDescriptionTextColor = value; SetColor( "AUD_TooltipUsageTextColor", value ); ForEachAssetUsageDetectorWindow( ( window ) => window.OnSettingsChanged( tooltipDescriptionsColorChanged: true ) ); }
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Size Adjustments
|
||||
private static float? m_extraRowHeight = null;
|
||||
public static float ExtraRowHeight
|
||||
{
|
||||
get { if( m_extraRowHeight == null ) m_extraRowHeight = EditorPrefs.GetFloat( "AUD_ExtraRowHeight", 0f ); return m_extraRowHeight.Value; }
|
||||
set { if( m_extraRowHeight == value ) return; m_extraRowHeight = value; EditorPrefs.SetFloat( "AUD_ExtraRowHeight", value ); ForEachAssetUsageDetectorWindow( ( window ) => window.OnSettingsChanged() ); }
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Other Settings
|
||||
private static bool? m_pingClickedObjects = null;
|
||||
public static bool PingClickedObjects
|
||||
{
|
||||
get { if( m_pingClickedObjects == null ) m_pingClickedObjects = EditorPrefs.GetBool( "AUD_PingClickedObj", true ); return m_pingClickedObjects.Value; }
|
||||
set { if( m_pingClickedObjects == value ) return; m_pingClickedObjects = value; EditorPrefs.SetBool( "AUD_PingClickedObj", value ); }
|
||||
}
|
||||
|
||||
private static bool? m_selectClickedObjects = null;
|
||||
public static bool SelectClickedObjects
|
||||
{
|
||||
get { if( m_selectClickedObjects == null ) m_selectClickedObjects = EditorPrefs.GetBool( "AUD_SelectClickedObj", false ); return m_selectClickedObjects.Value; }
|
||||
set { if( m_selectClickedObjects == value ) return; m_selectClickedObjects = value; EditorPrefs.SetBool( "AUD_SelectClickedObj", value ); }
|
||||
}
|
||||
|
||||
private static bool? m_selectDoubleClickedObjects = null;
|
||||
public static bool SelectDoubleClickedObjects
|
||||
{
|
||||
get { if( m_selectDoubleClickedObjects == null ) m_selectDoubleClickedObjects = EditorPrefs.GetBool( "AUD_SelectDoubleClickedObj", true ); return m_selectDoubleClickedObjects.Value; }
|
||||
set { if( m_selectDoubleClickedObjects == value ) return; m_selectDoubleClickedObjects = value; EditorPrefs.SetBool( "AUD_SelectDoubleClickedObj", value ); }
|
||||
}
|
||||
|
||||
private static bool? m_showUnityTooltip = null;
|
||||
public static bool ShowUnityTooltip
|
||||
{
|
||||
get { if( m_showUnityTooltip == null ) m_showUnityTooltip = EditorPrefs.GetBool( "AUD_ShowUnityTooltip", false ); return m_showUnityTooltip.Value; }
|
||||
set { if( m_showUnityTooltip == value ) return; m_showUnityTooltip = value; EditorPrefs.SetBool( "AUD_ShowUnityTooltip", value ); }
|
||||
}
|
||||
|
||||
private static bool? m_showCustomTooltip = null;
|
||||
public static bool ShowCustomTooltip
|
||||
{
|
||||
get { if( m_showCustomTooltip == null ) m_showCustomTooltip = EditorPrefs.GetBool( "AUD_ShowCustomTooltip", true ); return m_showCustomTooltip.Value; }
|
||||
set { if( m_showCustomTooltip == value ) return; m_showCustomTooltip = value; EditorPrefs.SetBool( "AUD_ShowCustomTooltip", value ); ForEachAssetUsageDetectorWindow( ( window ) => window.OnSettingsChanged() ); }
|
||||
}
|
||||
|
||||
private static float? m_customTooltipDelay = null;
|
||||
public static float CustomTooltipDelay
|
||||
{
|
||||
get { if( m_customTooltipDelay == null ) m_customTooltipDelay = EditorPrefs.GetFloat( "AUD_CustomTooltipDelay", 0.7f ); return m_customTooltipDelay.Value; }
|
||||
set { if( m_customTooltipDelay == value ) return; m_customTooltipDelay = value; EditorPrefs.SetFloat( "AUD_CustomTooltipDelay", value ); }
|
||||
}
|
||||
|
||||
private static bool? m_showTreeLines = null;
|
||||
public static bool ShowTreeLines
|
||||
{
|
||||
get { if( m_showTreeLines == null ) m_showTreeLines = EditorPrefs.GetBool( "AUD_ShowTreeLines", true ); return m_showTreeLines.Value; }
|
||||
set { if( m_showTreeLines == value ) return; m_showTreeLines = value; EditorPrefs.SetBool( "AUD_ShowTreeLines", value ); }
|
||||
}
|
||||
|
||||
private static bool? m_applySelectedRowParentsTintToRootRows = null;
|
||||
public static bool ApplySelectedRowParentsTintToRootRows
|
||||
{
|
||||
get { if( m_applySelectedRowParentsTintToRootRows == null ) m_applySelectedRowParentsTintToRootRows = EditorPrefs.GetBool( "AUD_SelectedRowParentsTintAtRoot", true ); return m_applySelectedRowParentsTintToRootRows.Value; }
|
||||
set { if( m_applySelectedRowParentsTintToRootRows == value ) return; m_applySelectedRowParentsTintToRootRows = value; EditorPrefs.SetBool( "AUD_SelectedRowParentsTintAtRoot", value ); }
|
||||
}
|
||||
#endregion
|
||||
|
||||
#if UNITY_2018_3_OR_NEWER
|
||||
[SettingsProvider]
|
||||
public static SettingsProvider CreatePreferencesGUI()
|
||||
{
|
||||
return new SettingsProvider( "Project/yasirkula/Asset Usage Detector", SettingsScope.Project )
|
||||
{
|
||||
guiHandler = ( searchContext ) => PreferencesGUI(),
|
||||
keywords = new System.Collections.Generic.HashSet<string>() { "Asset", "Usage", "Detector" }
|
||||
};
|
||||
}
|
||||
#endif
|
||||
|
||||
#if !UNITY_2018_3_OR_NEWER
|
||||
[PreferenceItem( "Asset Usage Detector" )]
|
||||
#endif
|
||||
public static void PreferencesGUI()
|
||||
{
|
||||
float labelWidth = EditorGUIUtility.labelWidth;
|
||||
EditorGUIUtility.labelWidth += 60f;
|
||||
|
||||
EditorGUI.BeginChangeCheck();
|
||||
|
||||
SettingsHeaderColor = ColorField( "Settings Header Color", SettingsHeaderColor, Color.cyan );
|
||||
|
||||
EditorGUILayout.Space();
|
||||
|
||||
PingClickedObjects = EditorGUILayout.Toggle( "Ping Clicked Objects", PingClickedObjects );
|
||||
SelectClickedObjects = EditorGUILayout.Toggle( "Select Clicked Objects", SelectClickedObjects );
|
||||
SelectDoubleClickedObjects = EditorGUILayout.Toggle( "Select Double Clicked Objects", SelectDoubleClickedObjects );
|
||||
|
||||
EditorGUILayout.Space();
|
||||
|
||||
ShowUnityTooltip = EditorGUILayout.Toggle( "Show Unity Tooltip", ShowUnityTooltip );
|
||||
ShowCustomTooltip = EditorGUILayout.Toggle( "Show Custom Tooltip", ShowCustomTooltip );
|
||||
EditorGUI.indentLevel++;
|
||||
CustomTooltipDelay = FloatField( "Delay", CustomTooltipDelay, 0.7f );
|
||||
EditorGUI.indentLevel--;
|
||||
TooltipDescriptionTextColor = ColorField( "Tooltip Descriptions Text Color", TooltipDescriptionTextColor, EditorGUIUtility.isProSkin ? new Color( 0f, 0.9f, 0.9f, 1f ) : new Color( 0.9f, 0f, 0f, 1f ) );
|
||||
|
||||
EditorGUILayout.Space();
|
||||
|
||||
ExtraRowHeight = Mathf.Max( 0f, FloatField( "Extra Row Height", ExtraRowHeight, 0f ) );
|
||||
|
||||
EditorGUILayout.Space();
|
||||
|
||||
SearchResultGroupHeaderColor = ColorField( "Group Header Color", SearchResultGroupHeaderColor, Color.cyan );
|
||||
RootRowsBackgroundColor = ColorField( "Root Rows Background Color", RootRowsBackgroundColor, EditorGUIUtility.isProSkin ? new Color( 0f, 1f, 1f, 0.15f ) : new Color( 0f, 1f, 1f, 0.25f ) );
|
||||
RootRowsBorderColor = ColorField( "Root Rows Border Color", RootRowsBorderColor, EditorGUIUtility.isProSkin ? new Color( 0.15f, 0.15f, 0.15f, 1f ) : new Color( 0.375f, 0.375f, 0.375f, 1f ) );
|
||||
MainReferencesBackgroundColor = ColorField( "Main References Background Color", MainReferencesBackgroundColor, EditorGUIUtility.isProSkin ? new Color( 0f, 0.35f, 0f, 1f ) : new Color( 0.25f, 0.75f, 0.25f, 1f ) );
|
||||
SelectedRowParentsTint = ColorField( "Selected Row Parents Tint", SelectedRowParentsTint, EditorGUIUtility.isProSkin ? new Color( 0.36f, 0.36f, 0.18f, 1f ) : new Color( 0.825f, 0.825f, 0.55f, 1f ) );
|
||||
EditorGUI.indentLevel++;
|
||||
ApplySelectedRowParentsTintToRootRows = !EditorGUILayout.Toggle( "Ignore Root Rows", !ApplySelectedRowParentsTintToRootRows );
|
||||
EditorGUI.indentLevel--;
|
||||
SelectedRowOccurrencesColor = ColorField( "Selected Row All Occurrences Tint", SelectedRowOccurrencesColor, EditorGUIUtility.isProSkin ? new Color( 0f, 0.3f, 0.75f, 1f ) : new Color( 0.25f, 0.75f, 1f, 1f ) );
|
||||
SearchMatchingTextColor = ColorField( "Matching Search Text Color", SearchMatchingTextColor, Color.red );
|
||||
|
||||
ShowTreeLines = EditorGUILayout.Toggle( "Show Tree Lines", ShowTreeLines );
|
||||
EditorGUI.indentLevel++;
|
||||
TreeLinesColor = ColorField( "Normal Color", TreeLinesColor, EditorGUIUtility.isProSkin ? new Color( 0.65f, 0.65f, 0.65f, 1f ) : new Color( 0.375f, 0.375f, 0.375f, 1f ) );
|
||||
HighlightedTreeLinesColor = ColorField( "Highlighted Color", HighlightedTreeLinesColor, Color.cyan );
|
||||
EditorGUI.indentLevel--;
|
||||
|
||||
EditorGUIUtility.labelWidth = labelWidth;
|
||||
|
||||
if( EditorGUI.EndChangeCheck() )
|
||||
ForEachAssetUsageDetectorWindow( ( window ) => window.Repaint() );
|
||||
}
|
||||
|
||||
private static Color ColorField( string label, Color value, Color defaultValue )
|
||||
{
|
||||
GUILayout.BeginHorizontal();
|
||||
Color result = EditorGUILayout.ColorField( label, value );
|
||||
if( GUILayout.Button( "Reset", GL_WIDTH_60 ) )
|
||||
result = defaultValue;
|
||||
GUILayout.EndHorizontal();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private static float FloatField( string label, float value, float defaultValue )
|
||||
{
|
||||
GUILayout.BeginHorizontal();
|
||||
float result = EditorGUILayout.FloatField( label, value );
|
||||
if( GUILayout.Button( "Reset", GL_WIDTH_60 ) )
|
||||
result = defaultValue;
|
||||
GUILayout.EndHorizontal();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private static Color GetColor( string pref, Color defaultColor )
|
||||
{
|
||||
if( EditorGUIUtility.isProSkin )
|
||||
pref += "_Pro";
|
||||
|
||||
if( !EditorPrefs.HasKey( pref ) )
|
||||
return defaultColor;
|
||||
|
||||
string[] parts = EditorPrefs.GetString( pref ).Split( ';' );
|
||||
return new Color32( byte.Parse( parts[0] ), byte.Parse( parts[1] ), byte.Parse( parts[2] ), byte.Parse( parts[3] ) );
|
||||
}
|
||||
|
||||
private static void SetColor( string pref, Color32 value )
|
||||
{
|
||||
if( EditorGUIUtility.isProSkin )
|
||||
pref += "_Pro";
|
||||
|
||||
EditorPrefs.SetString( pref, string.Concat( value.r.ToString(), ";", value.g.ToString(), ";", value.b.ToString(), ";", value.a.ToString() ) );
|
||||
}
|
||||
|
||||
private static void ForEachAssetUsageDetectorWindow( System.Action<AssetUsageDetectorWindow> action )
|
||||
{
|
||||
foreach( AssetUsageDetectorWindow window in Resources.FindObjectsOfTypeAll<AssetUsageDetectorWindow>() )
|
||||
{
|
||||
if( window )
|
||||
action( window );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 13295073724765e45aa3b77486e515f4
|
||||
timeCreated: 1639982865
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -5,14 +5,18 @@ using UnityEditor;
|
||||
using System.Collections.Generic;
|
||||
using System.Reflection;
|
||||
using Object = UnityEngine.Object;
|
||||
#if UNITY_2018_3_OR_NEWER
|
||||
using PrefabStage = UnityEditor.Experimental.SceneManagement.PrefabStage;
|
||||
using PrefabStageUtility = UnityEditor.Experimental.SceneManagement.PrefabStageUtility;
|
||||
#endif
|
||||
|
||||
namespace AssetUsageDetectorNamespace
|
||||
{
|
||||
public enum Phase { Setup, Processing, Complete };
|
||||
|
||||
public class AssetUsageDetectorWindow : EditorWindow
|
||||
public class AssetUsageDetectorWindow : EditorWindow, IHasCustomMenu
|
||||
{
|
||||
private const float PLAY_MODE_REFRESH_INTERVAL = 1f; // Interval to refresh the editor window in play mode
|
||||
private enum WindowFilter { AlwaysReturnActive, ReturnActiveIfNotLocked, AlwaysReturnNew };
|
||||
|
||||
private const string PREFS_SEARCH_SCENES = "AUD_SceneSearch";
|
||||
private const string PREFS_SEARCH_ASSETS = "AUD_AssetsSearch";
|
||||
@@ -22,19 +26,40 @@ namespace AssetUsageDetectorNamespace
|
||||
private const string PREFS_SEARCH_FIELDS = "AUD_Fields";
|
||||
private const string PREFS_SEARCH_PROPERTIES = "AUD_Properties";
|
||||
private const string PREFS_SEARCH_NON_SERIALIZABLES = "AUD_NonSerializables";
|
||||
private const string PREFS_SEARCH_UNUSED_MATERIAL_PROPERTIES = "AUD_SearchUnusedMaterialProps";
|
||||
private const string PREFS_LAZY_SCENE_SEARCH = "AUD_LazySceneSearch";
|
||||
private const string PREFS_PATH_DRAWING_MODE = "AUD_PathDrawing";
|
||||
private const string PREFS_CALCULATE_UNUSED_OBJECTS = "AUD_FindUnusedObjs";
|
||||
private const string PREFS_HIDE_DUPLICATE_ROWS = "AUD_HideDuplicates";
|
||||
private const string PREFS_HIDE_REDUNDANT_PREFAB_VARIANT_LINKS = "AUD_HideRedundantPVariantLinks";
|
||||
private const string PREFS_SHOW_PROGRESS = "AUD_Progress";
|
||||
private const string PREFS_SHOW_TOOLTIPS = "AUD_Tooltips";
|
||||
|
||||
private static readonly GUIContent windowTitle = new GUIContent( "Asset Usage Detector" );
|
||||
private static readonly Vector2 windowMinSize = new Vector2( 325f, 220f );
|
||||
|
||||
private AssetUsageDetector core = new AssetUsageDetector();
|
||||
private readonly GUILayoutOption GL_WIDTH_12 = GUILayout.Width( 12f );
|
||||
|
||||
private GUIStyle lockButtonStyle;
|
||||
|
||||
private readonly AssetUsageDetector core = new AssetUsageDetector();
|
||||
private SearchResult searchResult; // Overall search results
|
||||
|
||||
// This isn't readonly so that it can be serialized
|
||||
private List<ObjectToSearch> objectsToSearch = new List<ObjectToSearch>() { new ObjectToSearch( null ) };
|
||||
|
||||
private bool m_isLocked;
|
||||
private bool IsLocked
|
||||
{
|
||||
get { return m_isLocked; }
|
||||
set
|
||||
{
|
||||
if( m_isLocked != value )
|
||||
{
|
||||
m_isLocked = value;
|
||||
titleContent = value ? new GUIContent( "[L] " + windowTitle.text, EditorGUIUtility.IconContent( "InspectorLock" ).image ) : windowTitle;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private Phase currentPhase = Phase.Setup;
|
||||
|
||||
private bool searchInOpenScenes = true; // Scenes currently open in Hierarchy view
|
||||
@@ -51,83 +76,141 @@ namespace AssetUsageDetectorNamespace
|
||||
|
||||
private int searchDepthLimit = 4; // Depth limit for recursively searching variables of objects
|
||||
|
||||
private bool restoreInitialSceneSetup = true; // Close the additively loaded scenes that were not part of the initial scene setup
|
||||
|
||||
private string errorMessage = string.Empty;
|
||||
|
||||
private bool lazySceneSearch = false;
|
||||
private bool lazySceneSearch = true;
|
||||
private bool searchNonSerializableVariables = true;
|
||||
private bool searchUnusedMaterialProperties = true;
|
||||
private bool calculateUnusedObjects = false;
|
||||
private bool hideDuplicateRows = true;
|
||||
private bool hideReduntantPrefabVariantLinks = true;
|
||||
private bool noAssetDatabaseChanges = false;
|
||||
private bool showDetailedProgressBar = false;
|
||||
private bool showDetailedProgressBar = true;
|
||||
|
||||
private BindingFlags fieldModifiers, propertyModifiers;
|
||||
|
||||
private SearchResultDrawParameters searchResultDrawParameters = new SearchResultDrawParameters( PathDrawingMode.ShortRelevantParts, false, false );
|
||||
|
||||
private double nextPlayModeRefreshTime = 0f;
|
||||
|
||||
private readonly ObjectToSearchListDrawer objectsToSearchDrawer = new ObjectToSearchListDrawer();
|
||||
private readonly ObjectListDrawer searchInAssetsSubsetDrawer = new ObjectListDrawer( "Search following asset(s) only:", false );
|
||||
private readonly ObjectListDrawer excludedAssetsDrawer = new ObjectListDrawer( "Don't search following asset(s):", false );
|
||||
private readonly ObjectListDrawer excludedScenesDrawer = new ObjectListDrawer( "Don't search in following scene(s):", false );
|
||||
|
||||
private readonly GUIContent restoreInitialSceneSetupLabel = new GUIContent( "Restore initial scene setup (Recommended)", "For example, if scene A was open when the search was started and scenes A and B are open after the search is completed, clicking the \"Reset Search\" button will automatically close scene B" );
|
||||
private readonly GUIContent showTooltipsLabel = new GUIContent( "Show tooltips", "Display nodes' contents in a tooltip when cursor hovers over them" );
|
||||
private bool drawObjectsToSearchSection = true;
|
||||
|
||||
private Vector2 scrollPosition = Vector2.zero;
|
||||
|
||||
private bool shouldRepositionSelf;
|
||||
private Rect windowTargetPosition;
|
||||
|
||||
private static AssetUsageDetectorWindow mainWindow = null;
|
||||
void IHasCustomMenu.AddItemsToMenu( GenericMenu contextMenu )
|
||||
{
|
||||
contextMenu.AddItem( new GUIContent( "Lock" ), IsLocked, () => IsLocked = !IsLocked );
|
||||
contextMenu.AddSeparator( "" );
|
||||
|
||||
#if UNITY_2018_3_OR_NEWER
|
||||
contextMenu.AddItem( new GUIContent( "Settings" ), false, () => SettingsService.OpenProjectSettings( "Project/yasirkula/Asset Usage Detector" ) );
|
||||
#else
|
||||
contextMenu.AddItem( new GUIContent( "Settings" ), false, () =>
|
||||
{
|
||||
System.Type preferencesWindowType = typeof( EditorWindow ).Assembly.GetType( "UnityEditor.PreferencesWindow" );
|
||||
preferencesWindowType.GetMethod( "ShowPreferencesWindow", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static ).Invoke( null, null );
|
||||
|
||||
EditorWindow preferencesWindow = GetWindow( preferencesWindowType );
|
||||
if( (bool) preferencesWindowType.GetField( "m_RefreshCustomPreferences", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance ).GetValue( preferencesWindow ) )
|
||||
{
|
||||
preferencesWindowType.GetMethod( "AddCustomSections", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance ).Invoke( preferencesWindow, null );
|
||||
preferencesWindowType.GetField( "m_RefreshCustomPreferences", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance ).SetValue( preferencesWindow, false );
|
||||
}
|
||||
|
||||
int targetSectionIndex = -1;
|
||||
System.Collections.IList sections = (System.Collections.IList) preferencesWindowType.GetField( "m_Sections", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance ).GetValue( preferencesWindow );
|
||||
for( int i = 0; i < sections.Count; i++ )
|
||||
{
|
||||
if( ( (GUIContent) sections[i].GetType().GetField( "content", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance ).GetValue( sections[i] ) ).text == "Asset Usage Detector" )
|
||||
{
|
||||
targetSectionIndex = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if( targetSectionIndex >= 0 )
|
||||
preferencesWindowType.GetProperty( "selectedSectionIndex", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance ).SetValue( preferencesWindow, targetSectionIndex, null );
|
||||
} );
|
||||
#endif
|
||||
|
||||
if( currentPhase == Phase.Setup )
|
||||
{
|
||||
contextMenu.AddSeparator( "" );
|
||||
contextMenu.AddItem( new GUIContent( "Refresh Sub-Assets of Searched Objects" ), false, () =>
|
||||
{
|
||||
for( int i = objectsToSearch.Count - 1; i >= 0; i-- )
|
||||
objectsToSearch[i].RefreshSubAssets();
|
||||
} );
|
||||
}
|
||||
}
|
||||
|
||||
// Shows lock button at the top-right corner
|
||||
// Credit: http://leahayes.co.uk/2013/04/30/adding-the-little-padlock-button-to-your-editorwindow.html
|
||||
private void ShowButton( Rect position )
|
||||
{
|
||||
if( lockButtonStyle == null )
|
||||
lockButtonStyle = "IN LockButton";
|
||||
|
||||
IsLocked = GUI.Toggle( position, IsLocked, GUIContent.none, lockButtonStyle );
|
||||
}
|
||||
|
||||
private static AssetUsageDetectorWindow GetWindow( WindowFilter filter )
|
||||
{
|
||||
AssetUsageDetectorWindow[] windows = Resources.FindObjectsOfTypeAll<AssetUsageDetectorWindow>();
|
||||
AssetUsageDetectorWindow window = System.Array.Find( windows, ( w ) => w && !w.IsLocked );
|
||||
if( !window )
|
||||
window = System.Array.Find( windows, ( w ) => w );
|
||||
|
||||
if( window && ( filter == WindowFilter.AlwaysReturnActive || ( !window.IsLocked && filter == WindowFilter.ReturnActiveIfNotLocked ) ) )
|
||||
{
|
||||
window.Show();
|
||||
return window;
|
||||
}
|
||||
|
||||
Rect? windowTargetPosition = null;
|
||||
if( window )
|
||||
{
|
||||
Rect position = window.position;
|
||||
position.position += new Vector2( 50f, 50f );
|
||||
windowTargetPosition = position;
|
||||
}
|
||||
|
||||
window = CreateInstance<AssetUsageDetectorWindow>();
|
||||
window.titleContent = windowTitle;
|
||||
window.minSize = windowMinSize;
|
||||
|
||||
if( windowTargetPosition.HasValue )
|
||||
{
|
||||
window.shouldRepositionSelf = true;
|
||||
window.windowTargetPosition = windowTargetPosition.Value;
|
||||
}
|
||||
|
||||
window.Show( true );
|
||||
return window;
|
||||
}
|
||||
|
||||
// Add "Asset Usage Detector" menu item to the Window menu
|
||||
[MenuItem( "Window/Asset Usage Detector/Active Window" )]
|
||||
private static void OpenActiveWindow()
|
||||
{
|
||||
if( !mainWindow )
|
||||
{
|
||||
mainWindow = GetWindow<AssetUsageDetectorWindow>();
|
||||
mainWindow.titleContent = windowTitle;
|
||||
mainWindow.minSize = windowMinSize;
|
||||
}
|
||||
|
||||
mainWindow.Show();
|
||||
GetWindow( WindowFilter.AlwaysReturnActive );
|
||||
}
|
||||
|
||||
[MenuItem( "Window/Asset Usage Detector/New Window" )]
|
||||
private static void OpenNewWindow()
|
||||
{
|
||||
Rect? windowTargetPosition = null;
|
||||
if( mainWindow )
|
||||
{
|
||||
Rect position = mainWindow.position;
|
||||
position.position += new Vector2( 50f, 50f );
|
||||
windowTargetPosition = position;
|
||||
}
|
||||
|
||||
mainWindow = CreateInstance<AssetUsageDetectorWindow>();
|
||||
mainWindow.titleContent = windowTitle;
|
||||
mainWindow.minSize = windowMinSize;
|
||||
|
||||
if( windowTargetPosition.HasValue )
|
||||
{
|
||||
mainWindow.shouldRepositionSelf = true;
|
||||
mainWindow.windowTargetPosition = windowTargetPosition.Value;
|
||||
}
|
||||
|
||||
mainWindow.Show( true );
|
||||
GetWindow( WindowFilter.AlwaysReturnNew );
|
||||
}
|
||||
|
||||
// Quickly initiate search for the selected assets
|
||||
[MenuItem( "GameObject/Search for References", priority = 49 )]
|
||||
[MenuItem( "GameObject/Search for References/This Object Only", priority = 49 )]
|
||||
[MenuItem( "Assets/Search for References", priority = 1000 )]
|
||||
private static void SearchSelectedAssetReferences( MenuCommand command )
|
||||
{
|
||||
// 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
|
||||
// the function to be called only once
|
||||
if( command.context )
|
||||
{
|
||||
EditorApplication.update -= CallSearchSelectedAssetReferencesOnce;
|
||||
@@ -137,8 +220,21 @@ namespace AssetUsageDetectorNamespace
|
||||
ShowAndSearch( Selection.objects );
|
||||
}
|
||||
|
||||
[MenuItem( "GameObject/Search for References/Include Children", priority = 49 )]
|
||||
private static void SearchSelectedAssetReferencesWithChildren( MenuCommand command )
|
||||
{
|
||||
if( command.context )
|
||||
{
|
||||
EditorApplication.update -= CallSearchSelectedAssetReferencesWithChildrenOnce;
|
||||
EditorApplication.update += CallSearchSelectedAssetReferencesWithChildrenOnce;
|
||||
}
|
||||
else
|
||||
ShowAndSearch( Selection.objects, true );
|
||||
}
|
||||
|
||||
// Show the menu item only if there is a selection in the Editor
|
||||
[MenuItem( "GameObject/Search for References", validate = true )]
|
||||
[MenuItem( "GameObject/Search for References/This Object Only", validate = true )]
|
||||
[MenuItem( "GameObject/Search for References/Include Children", validate = true )]
|
||||
[MenuItem( "Assets/Search for References", validate = true )]
|
||||
private static bool SearchSelectedAssetReferencesValidate( MenuCommand command )
|
||||
{
|
||||
@@ -146,13 +242,13 @@ namespace AssetUsageDetectorNamespace
|
||||
}
|
||||
|
||||
// Quickly show the AssetUsageDetector window and initiate a search
|
||||
public static void ShowAndSearch( IEnumerable<Object> searchObjects )
|
||||
public static void ShowAndSearch( IEnumerable<Object> searchObjects, bool? shouldSearchChildren = null )
|
||||
{
|
||||
ShowAndSearchInternal( searchObjects, null );
|
||||
GetWindow( WindowFilter.ReturnActiveIfNotLocked ).ShowAndSearchInternal( searchObjects, null, shouldSearchChildren );
|
||||
}
|
||||
|
||||
// Quickly show the AssetUsageDetector window and initiate a search
|
||||
public static void ShowAndSearch( AssetUsageDetector.Parameters searchParameters )
|
||||
public static void ShowAndSearch( AssetUsageDetector.Parameters searchParameters, bool? shouldSearchChildren = null )
|
||||
{
|
||||
if( searchParameters == null )
|
||||
{
|
||||
@@ -160,7 +256,7 @@ namespace AssetUsageDetectorNamespace
|
||||
return;
|
||||
}
|
||||
|
||||
ShowAndSearchInternal( searchParameters.objectsToSearch, searchParameters );
|
||||
GetWindow( WindowFilter.ReturnActiveIfNotLocked ).ShowAndSearchInternal( searchParameters.objectsToSearch, searchParameters, shouldSearchChildren );
|
||||
}
|
||||
|
||||
private static void CallSearchSelectedAssetReferencesOnce()
|
||||
@@ -169,61 +265,69 @@ namespace AssetUsageDetectorNamespace
|
||||
SearchSelectedAssetReferences( new MenuCommand( null ) );
|
||||
}
|
||||
|
||||
private static void ShowAndSearchInternal( IEnumerable<Object> searchObjects, AssetUsageDetector.Parameters searchParameters )
|
||||
private static void CallSearchSelectedAssetReferencesWithChildrenOnce()
|
||||
{
|
||||
if( mainWindow != null && !mainWindow.ReturnToSetupPhase( true ) )
|
||||
EditorApplication.update -= CallSearchSelectedAssetReferencesWithChildrenOnce;
|
||||
SearchSelectedAssetReferencesWithChildren( new MenuCommand( null ) );
|
||||
}
|
||||
|
||||
private void ShowAndSearchInternal( IEnumerable<Object> searchObjects, AssetUsageDetector.Parameters searchParameters, bool? shouldSearchChildren )
|
||||
{
|
||||
if( !ReturnToSetupPhase() )
|
||||
{
|
||||
Debug.LogError( "Need to reset the previous search first!" );
|
||||
return;
|
||||
}
|
||||
|
||||
OpenActiveWindow();
|
||||
|
||||
mainWindow.objectsToSearch.Clear();
|
||||
objectsToSearch.Clear();
|
||||
if( searchObjects != null )
|
||||
{
|
||||
foreach( Object obj in searchObjects )
|
||||
mainWindow.objectsToSearch.Add( new ObjectToSearch( obj ) );
|
||||
objectsToSearch.Add( new ObjectToSearch( obj, shouldSearchChildren ) );
|
||||
}
|
||||
|
||||
if( searchParameters != null )
|
||||
{
|
||||
mainWindow.ParseSceneSearchMode( searchParameters.searchInScenes );
|
||||
mainWindow.searchInAssetsFolder = searchParameters.searchInAssetsFolder;
|
||||
mainWindow.dontSearchInSourceAssets = searchParameters.dontSearchInSourceAssets;
|
||||
mainWindow.searchInProjectSettings = searchParameters.searchInProjectSettings;
|
||||
mainWindow.searchDepthLimit = searchParameters.searchDepthLimit;
|
||||
mainWindow.fieldModifiers = searchParameters.fieldModifiers;
|
||||
mainWindow.propertyModifiers = searchParameters.propertyModifiers;
|
||||
mainWindow.searchNonSerializableVariables = searchParameters.searchNonSerializableVariables;
|
||||
mainWindow.lazySceneSearch = searchParameters.lazySceneSearch;
|
||||
mainWindow.noAssetDatabaseChanges = searchParameters.noAssetDatabaseChanges;
|
||||
mainWindow.showDetailedProgressBar = searchParameters.showDetailedProgressBar;
|
||||
ParseSceneSearchMode( searchParameters.searchInScenes );
|
||||
searchInAssetsFolder = searchParameters.searchInAssetsFolder;
|
||||
dontSearchInSourceAssets = searchParameters.dontSearchInSourceAssets;
|
||||
searchInProjectSettings = searchParameters.searchInProjectSettings;
|
||||
searchDepthLimit = searchParameters.searchDepthLimit;
|
||||
fieldModifiers = searchParameters.fieldModifiers;
|
||||
propertyModifiers = searchParameters.propertyModifiers;
|
||||
searchNonSerializableVariables = searchParameters.searchNonSerializableVariables;
|
||||
searchUnusedMaterialProperties = searchParameters.searchUnusedMaterialProperties;
|
||||
lazySceneSearch = searchParameters.lazySceneSearch;
|
||||
calculateUnusedObjects = searchParameters.calculateUnusedObjects;
|
||||
hideDuplicateRows = searchParameters.hideDuplicateRows;
|
||||
hideReduntantPrefabVariantLinks = searchParameters.hideReduntantPrefabVariantLinks;
|
||||
noAssetDatabaseChanges = searchParameters.noAssetDatabaseChanges;
|
||||
showDetailedProgressBar = searchParameters.showDetailedProgressBar;
|
||||
|
||||
mainWindow.searchInAssetsSubset.Clear();
|
||||
searchInAssetsSubset.Clear();
|
||||
if( searchParameters.searchInAssetsSubset != null )
|
||||
{
|
||||
foreach( Object obj in searchParameters.searchInAssetsSubset )
|
||||
mainWindow.searchInAssetsSubset.Add( obj );
|
||||
searchInAssetsSubset.Add( obj );
|
||||
}
|
||||
|
||||
mainWindow.excludedAssets.Clear();
|
||||
excludedAssets.Clear();
|
||||
if( searchParameters.excludedAssetsFromSearch != null )
|
||||
{
|
||||
foreach( Object obj in searchParameters.excludedAssetsFromSearch )
|
||||
mainWindow.excludedAssets.Add( obj );
|
||||
excludedAssets.Add( obj );
|
||||
}
|
||||
|
||||
mainWindow.excludedScenes.Clear();
|
||||
excludedScenes.Clear();
|
||||
if( searchParameters.excludedScenesFromSearch != null )
|
||||
{
|
||||
foreach( Object obj in searchParameters.excludedScenesFromSearch )
|
||||
mainWindow.excludedScenes.Add( obj );
|
||||
excludedScenes.Add( obj );
|
||||
}
|
||||
}
|
||||
|
||||
mainWindow.InitiateSearch();
|
||||
mainWindow.Repaint();
|
||||
InitiateSearch();
|
||||
Repaint();
|
||||
}
|
||||
|
||||
private void Awake()
|
||||
@@ -233,22 +337,21 @@ namespace AssetUsageDetectorNamespace
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
mainWindow = this;
|
||||
if( currentPhase == Phase.Complete && AssetUsageDetectorSettings.ShowCustomTooltip )
|
||||
wantsMouseMove = wantsMouseEnterLeaveWindow = true; // These values aren't preserved during domain reload on Unity 2020.3.0f1
|
||||
|
||||
#if UNITY_2018_3_OR_NEWER
|
||||
UnityEditor.Experimental.SceneManagement.PrefabStage.prefabStageClosing -= ReplacePrefabStageObjectsWithAssets;
|
||||
UnityEditor.Experimental.SceneManagement.PrefabStage.prefabStageClosing += ReplacePrefabStageObjectsWithAssets;
|
||||
PrefabStage.prefabStageClosing -= ReplacePrefabStageObjectsWithAssets;
|
||||
PrefabStage.prefabStageClosing += ReplacePrefabStageObjectsWithAssets;
|
||||
#endif
|
||||
}
|
||||
|
||||
private void OnDisable()
|
||||
{
|
||||
#if UNITY_2018_3_OR_NEWER
|
||||
UnityEditor.Experimental.SceneManagement.PrefabStage.prefabStageClosing -= ReplacePrefabStageObjectsWithAssets;
|
||||
PrefabStage.prefabStageClosing -= ReplacePrefabStageObjectsWithAssets;
|
||||
#endif
|
||||
|
||||
if( mainWindow == this )
|
||||
mainWindow = null;
|
||||
SearchResultTooltip.Hide();
|
||||
}
|
||||
|
||||
private void OnDestroy()
|
||||
@@ -258,16 +361,8 @@ namespace AssetUsageDetectorNamespace
|
||||
|
||||
SavePrefs();
|
||||
|
||||
if( searchResult != null && currentPhase == Phase.Complete && !EditorApplication.isPlaying && searchResult.IsSceneSetupDifferentThanCurrentSetup() )
|
||||
{
|
||||
if( EditorUtility.DisplayDialog( "Scenes", "Restore initial scene setup?", "Yes", "Leave it as is" ) )
|
||||
searchResult.RestoreInitialSceneSetup();
|
||||
}
|
||||
}
|
||||
|
||||
private void OnFocus()
|
||||
{
|
||||
mainWindow = this;
|
||||
if( searchResult != null && currentPhase == Phase.Complete )
|
||||
searchResult.RestoreInitialSceneSetup();
|
||||
}
|
||||
|
||||
private void SavePrefs()
|
||||
@@ -279,10 +374,12 @@ namespace AssetUsageDetectorNamespace
|
||||
EditorPrefs.SetInt( PREFS_SEARCH_DEPTH_LIMIT, searchDepthLimit );
|
||||
EditorPrefs.SetInt( PREFS_SEARCH_FIELDS, (int) fieldModifiers );
|
||||
EditorPrefs.SetInt( PREFS_SEARCH_PROPERTIES, (int) propertyModifiers );
|
||||
EditorPrefs.SetInt( PREFS_PATH_DRAWING_MODE, (int) searchResultDrawParameters.pathDrawingMode );
|
||||
EditorPrefs.SetBool( PREFS_SEARCH_NON_SERIALIZABLES, searchNonSerializableVariables );
|
||||
EditorPrefs.SetBool( PREFS_SEARCH_UNUSED_MATERIAL_PROPERTIES, searchUnusedMaterialProperties );
|
||||
EditorPrefs.SetBool( PREFS_LAZY_SCENE_SEARCH, lazySceneSearch );
|
||||
EditorPrefs.SetBool( PREFS_SHOW_TOOLTIPS, searchResultDrawParameters.showTooltips );
|
||||
EditorPrefs.SetBool( PREFS_CALCULATE_UNUSED_OBJECTS, calculateUnusedObjects );
|
||||
EditorPrefs.SetBool( PREFS_HIDE_DUPLICATE_ROWS, hideDuplicateRows );
|
||||
EditorPrefs.SetBool( PREFS_HIDE_REDUNDANT_PREFAB_VARIANT_LINKS, hideReduntantPrefabVariantLinks );
|
||||
EditorPrefs.SetBool( PREFS_SHOW_PROGRESS, showDetailedProgressBar );
|
||||
}
|
||||
|
||||
@@ -294,24 +391,15 @@ namespace AssetUsageDetectorNamespace
|
||||
dontSearchInSourceAssets = EditorPrefs.GetBool( PREFS_DONT_SEARCH_SOURCE_ASSETS, true );
|
||||
searchInProjectSettings = EditorPrefs.GetBool( PREFS_SEARCH_PROJECT_SETTINGS, true );
|
||||
searchDepthLimit = EditorPrefs.GetInt( PREFS_SEARCH_DEPTH_LIMIT, 4 );
|
||||
|
||||
// Fetch public, protected and private non-static fields and properties from objects by default
|
||||
fieldModifiers = (BindingFlags) EditorPrefs.GetInt( PREFS_SEARCH_FIELDS, (int) ( BindingFlags.Public | BindingFlags.NonPublic ) );
|
||||
propertyModifiers = (BindingFlags) EditorPrefs.GetInt( PREFS_SEARCH_PROPERTIES, (int) ( BindingFlags.Public | BindingFlags.NonPublic ) );
|
||||
|
||||
try
|
||||
{
|
||||
searchResultDrawParameters.pathDrawingMode = (PathDrawingMode) EditorPrefs.GetInt( PREFS_PATH_DRAWING_MODE, (int) PathDrawingMode.ShortRelevantParts );
|
||||
}
|
||||
catch
|
||||
{
|
||||
searchResultDrawParameters.pathDrawingMode = PathDrawingMode.ShortRelevantParts;
|
||||
}
|
||||
|
||||
searchNonSerializableVariables = EditorPrefs.GetBool( PREFS_SEARCH_NON_SERIALIZABLES, true );
|
||||
lazySceneSearch = EditorPrefs.GetBool( PREFS_LAZY_SCENE_SEARCH, false );
|
||||
searchResultDrawParameters.showTooltips = EditorPrefs.GetBool( PREFS_SHOW_TOOLTIPS, false );
|
||||
showDetailedProgressBar = EditorPrefs.GetBool( PREFS_SHOW_PROGRESS, false );
|
||||
searchUnusedMaterialProperties = EditorPrefs.GetBool( PREFS_SEARCH_UNUSED_MATERIAL_PROPERTIES, true );
|
||||
lazySceneSearch = EditorPrefs.GetBool( PREFS_LAZY_SCENE_SEARCH, true );
|
||||
calculateUnusedObjects = EditorPrefs.GetBool( PREFS_CALCULATE_UNUSED_OBJECTS, false );
|
||||
hideDuplicateRows = EditorPrefs.GetBool( PREFS_HIDE_DUPLICATE_ROWS, true );
|
||||
hideReduntantPrefabVariantLinks = EditorPrefs.GetBool( PREFS_HIDE_REDUNDANT_PREFAB_VARIANT_LINKS, true );
|
||||
showDetailedProgressBar = EditorPrefs.GetBool( PREFS_SHOW_PROGRESS, true );
|
||||
}
|
||||
|
||||
private SceneSearchMode GetSceneSearchMode( bool hideOptionsInPlayMode )
|
||||
@@ -340,13 +428,6 @@ namespace AssetUsageDetectorNamespace
|
||||
|
||||
private void Update()
|
||||
{
|
||||
// Refresh the window at a regular interval in play mode to update the tooltip
|
||||
if( EditorApplication.isPlaying && currentPhase == Phase.Complete && searchResultDrawParameters.showTooltips && EditorApplication.timeSinceStartup >= nextPlayModeRefreshTime )
|
||||
{
|
||||
nextPlayModeRefreshTime = EditorApplication.timeSinceStartup + PLAY_MODE_REFRESH_INTERVAL; ;
|
||||
Repaint();
|
||||
}
|
||||
|
||||
if( shouldRepositionSelf )
|
||||
{
|
||||
shouldRepositionSelf = false;
|
||||
@@ -361,70 +442,60 @@ namespace AssetUsageDetectorNamespace
|
||||
|
||||
GUILayout.BeginVertical();
|
||||
|
||||
GUILayout.Space( 10 );
|
||||
|
||||
// Show the error message, if it is not empty
|
||||
if( errorMessage.Length > 0 )
|
||||
EditorGUILayout.HelpBox( errorMessage, MessageType.Error );
|
||||
|
||||
GUILayout.Space( 10 );
|
||||
|
||||
if( currentPhase == Phase.Processing )
|
||||
{
|
||||
// If we are stuck at this phase, then we have encountered an exception
|
||||
GUILayout.Label( ". . . Search in progress or something went wrong (check console) . . ." );
|
||||
|
||||
restoreInitialSceneSetup = EditorGUILayout.ToggleLeft( restoreInitialSceneSetupLabel, restoreInitialSceneSetup );
|
||||
|
||||
if( GUILayout.Button( "RETURN", Utilities.GL_HEIGHT_30 ) )
|
||||
ReturnToSetupPhase( restoreInitialSceneSetup );
|
||||
ReturnToSetupPhase();
|
||||
}
|
||||
else if( currentPhase == Phase.Setup )
|
||||
{
|
||||
if( objectsToSearchDrawer.Draw( objectsToSearch ) )
|
||||
errorMessage = string.Empty;
|
||||
DrawObjectsToSearchSection();
|
||||
|
||||
GUILayout.Space( 10 );
|
||||
GUILayout.Space( 10f );
|
||||
|
||||
Color c = GUI.color;
|
||||
GUI.color = Color.cyan;
|
||||
Color c = GUI.backgroundColor;
|
||||
GUI.backgroundColor = AssetUsageDetectorSettings.SettingsHeaderColor;
|
||||
GUILayout.Box( "<b>SEARCH IN</b>", Utilities.BoxGUIStyle, Utilities.GL_EXPAND_WIDTH );
|
||||
GUI.backgroundColor = c;
|
||||
|
||||
GUILayout.Box( "SEARCH IN", Utilities.BoxGUIStyle, Utilities.GL_EXPAND_WIDTH );
|
||||
|
||||
GUI.color = c;
|
||||
|
||||
searchInAssetsFolder = EditorGUILayout.ToggleLeft( "Project window (Assets folder)", searchInAssetsFolder );
|
||||
searchInAssetsFolder = WordWrappingToggleLeft( "Project window (Assets folder)", searchInAssetsFolder );
|
||||
|
||||
if( searchInAssetsFolder )
|
||||
{
|
||||
GUILayout.BeginHorizontal();
|
||||
GUILayout.Space( 35 );
|
||||
GUILayout.Space( 35f );
|
||||
GUILayout.BeginVertical();
|
||||
|
||||
searchInAssetsSubsetDrawer.Draw( searchInAssetsSubset );
|
||||
excludedAssetsDrawer.Draw( excludedAssets );
|
||||
|
||||
dontSearchInSourceAssets = EditorGUILayout.ToggleLeft( "Don't search \"Find references of\" themselves for references", dontSearchInSourceAssets );
|
||||
|
||||
GUILayout.EndVertical();
|
||||
GUILayout.EndHorizontal();
|
||||
}
|
||||
|
||||
GUILayout.Space( 5f );
|
||||
|
||||
dontSearchInSourceAssets = WordWrappingToggleLeft( "Don't search \"SEARCHED OBJECTS\" themselves for references", dontSearchInSourceAssets );
|
||||
searchUnusedMaterialProperties = WordWrappingToggleLeft( "Search unused material properties (e.g. normal map of a material that no longer uses normal mapping)", searchUnusedMaterialProperties );
|
||||
|
||||
Utilities.DrawSeparatorLine();
|
||||
|
||||
if( searchInAllScenes && !EditorApplication.isPlaying )
|
||||
GUI.enabled = false;
|
||||
|
||||
searchInOpenScenes = EditorGUILayout.ToggleLeft( "Currently open (loaded) scene(s)", searchInOpenScenes );
|
||||
searchInOpenScenes = WordWrappingToggleLeft( "Currently open (loaded) scene(s)", searchInOpenScenes );
|
||||
|
||||
if( !EditorApplication.isPlaying )
|
||||
{
|
||||
searchInScenesInBuild = EditorGUILayout.ToggleLeft( "Scenes in Build Settings", searchInScenesInBuild );
|
||||
searchInScenesInBuild = WordWrappingToggleLeft( "Scenes in Build Settings", searchInScenesInBuild );
|
||||
|
||||
if( searchInScenesInBuild )
|
||||
{
|
||||
GUILayout.BeginHorizontal();
|
||||
GUILayout.Space( 35 );
|
||||
GUILayout.Space( 35f );
|
||||
|
||||
searchInScenesInBuildTickedOnly = EditorGUILayout.ToggleLeft( "Ticked only", searchInScenesInBuildTickedOnly, Utilities.GL_WIDTH_100 );
|
||||
searchInScenesInBuildTickedOnly = !EditorGUILayout.ToggleLeft( "All", !searchInScenesInBuildTickedOnly, Utilities.GL_WIDTH_100 );
|
||||
@@ -434,11 +505,11 @@ namespace AssetUsageDetectorNamespace
|
||||
|
||||
GUI.enabled = true;
|
||||
|
||||
searchInAllScenes = EditorGUILayout.ToggleLeft( "All scenes in the project", searchInAllScenes );
|
||||
searchInAllScenes = WordWrappingToggleLeft( "All scenes in the project", searchInAllScenes );
|
||||
}
|
||||
|
||||
GUILayout.BeginHorizontal();
|
||||
GUILayout.Space( 35 );
|
||||
GUILayout.Space( 35f );
|
||||
GUILayout.BeginVertical();
|
||||
|
||||
excludedScenesDrawer.Draw( excludedScenes );
|
||||
@@ -448,73 +519,24 @@ namespace AssetUsageDetectorNamespace
|
||||
|
||||
Utilities.DrawSeparatorLine();
|
||||
|
||||
searchInProjectSettings = EditorGUILayout.ToggleLeft( "Project Settings (Player Settings, Graphics Settings etc.)", searchInProjectSettings );
|
||||
searchInProjectSettings = WordWrappingToggleLeft( "Project Settings (Player Settings, Graphics Settings etc.)", searchInProjectSettings );
|
||||
|
||||
GUILayout.Space( 10 );
|
||||
GUILayout.Space( 10f );
|
||||
|
||||
//GUILayout.Box( "SEARCH SETTINGS", Utilities.BoxGUIStyle, Utilities.GL_EXPAND_WIDTH );
|
||||
GUI.backgroundColor = AssetUsageDetectorSettings.SettingsHeaderColor;
|
||||
GUILayout.Box( "<b>SETTINGS</b>", Utilities.BoxGUIStyle, Utilities.GL_EXPAND_WIDTH );
|
||||
GUI.backgroundColor = c;
|
||||
|
||||
//GUILayout.BeginHorizontal();
|
||||
lazySceneSearch = WordWrappingToggleLeft( "Lazy scene search: scenes are searched in detail only when they are manually refreshed (faster search)", lazySceneSearch );
|
||||
calculateUnusedObjects = WordWrappingToggleLeft( "Calculate unused objects", calculateUnusedObjects );
|
||||
hideDuplicateRows = WordWrappingToggleLeft( "Hide duplicate rows in search results", hideDuplicateRows );
|
||||
#if UNITY_2018_3_OR_NEWER
|
||||
hideReduntantPrefabVariantLinks = WordWrappingToggleLeft( "Hide redundant prefab variant links (when the same value is assigned to the same Component of a prefab and its variant(s))", hideReduntantPrefabVariantLinks );
|
||||
#endif
|
||||
noAssetDatabaseChanges = WordWrappingToggleLeft( "I haven't modified any assets/scenes since the last search (faster search)", noAssetDatabaseChanges );
|
||||
showDetailedProgressBar = WordWrappingToggleLeft( "Update search progress bar more often (cancelable search) (slower search)", showDetailedProgressBar );
|
||||
|
||||
//GUILayout.Label( new GUIContent( "> Search depth: " + searchDepthLimit, "Depth limit for recursively searching variables of objects" ), Utilities.GL_WIDTH_250 );
|
||||
|
||||
//searchDepthLimit = (int) GUILayout.HorizontalSlider( searchDepthLimit, 0, 4 );
|
||||
|
||||
//GUILayout.EndHorizontal();
|
||||
|
||||
//GUILayout.Label( "> Search variables:" );
|
||||
|
||||
//GUILayout.BeginHorizontal();
|
||||
|
||||
//GUILayout.Space( 35 );
|
||||
|
||||
//if( EditorGUILayout.ToggleLeft( "Public", ( fieldModifiers & BindingFlags.Public ) == BindingFlags.Public, Utilities.GL_WIDTH_100 ) )
|
||||
// fieldModifiers |= BindingFlags.Public;
|
||||
//else
|
||||
// fieldModifiers &= ~BindingFlags.Public;
|
||||
|
||||
//if( EditorGUILayout.ToggleLeft( "Non-public", ( fieldModifiers & BindingFlags.NonPublic ) == BindingFlags.NonPublic, Utilities.GL_WIDTH_100 ) )
|
||||
// fieldModifiers |= BindingFlags.NonPublic;
|
||||
//else
|
||||
// fieldModifiers &= ~BindingFlags.NonPublic;
|
||||
|
||||
//GUILayout.EndHorizontal();
|
||||
|
||||
//GUILayout.Label( "> Search properties:" );
|
||||
|
||||
//GUILayout.BeginHorizontal();
|
||||
|
||||
//GUILayout.Space( 35 );
|
||||
|
||||
//if( EditorGUILayout.ToggleLeft( "Public", ( propertyModifiers & BindingFlags.Public ) == BindingFlags.Public, Utilities.GL_WIDTH_100 ) )
|
||||
// propertyModifiers |= BindingFlags.Public;
|
||||
//else
|
||||
// propertyModifiers &= ~BindingFlags.Public;
|
||||
|
||||
//if( EditorGUILayout.ToggleLeft( "Non-public", ( propertyModifiers & BindingFlags.NonPublic ) == BindingFlags.NonPublic, Utilities.GL_WIDTH_100 ) )
|
||||
// propertyModifiers |= BindingFlags.NonPublic;
|
||||
//else
|
||||
// propertyModifiers &= ~BindingFlags.NonPublic;
|
||||
|
||||
//GUILayout.EndHorizontal();
|
||||
|
||||
//GUILayout.Space( 10 );
|
||||
|
||||
//searchNonSerializableVariables = EditorGUILayout.ToggleLeft( "Search non-serializable fields and properties", searchNonSerializableVariables );
|
||||
|
||||
//GUILayout.Space( 10 );
|
||||
|
||||
GUI.color = Color.cyan;
|
||||
|
||||
GUILayout.Box( "SETTINGS", Utilities.BoxGUIStyle, Utilities.GL_EXPAND_WIDTH );
|
||||
|
||||
GUI.color = c;
|
||||
|
||||
lazySceneSearch = EditorGUILayout.ToggleLeft( "Lazy scene search: scenes are searched in detail only when they are manually refreshed (faster search)", lazySceneSearch );
|
||||
noAssetDatabaseChanges = EditorGUILayout.ToggleLeft( "I haven't modified any assets/scenes since the last search (faster search)", noAssetDatabaseChanges );
|
||||
showDetailedProgressBar = EditorGUILayout.ToggleLeft( "Show detailed progress bar (slower search)", showDetailedProgressBar );
|
||||
|
||||
GUILayout.Space( 10 );
|
||||
GUILayout.Space( 10f );
|
||||
|
||||
// Don't let the user press the GO button without any valid search location
|
||||
if( !searchInAllScenes && !searchInOpenScenes && !searchInScenesInBuild && !searchInAssetsFolder && !searchInProjectSettings )
|
||||
@@ -525,21 +547,23 @@ namespace AssetUsageDetectorNamespace
|
||||
InitiateSearch();
|
||||
GUIUtility.ExitGUI();
|
||||
}
|
||||
|
||||
GUILayout.Space( 5f );
|
||||
}
|
||||
else if( currentPhase == Phase.Complete )
|
||||
{
|
||||
// Draw the results of the search
|
||||
GUI.enabled = false;
|
||||
|
||||
objectsToSearchDrawer.Draw( objectsToSearch );
|
||||
DrawObjectsToSearchSection();
|
||||
|
||||
if( drawObjectsToSearchSection )
|
||||
GUILayout.Space( 10f );
|
||||
|
||||
GUILayout.Space( 10 );
|
||||
GUI.enabled = true;
|
||||
|
||||
restoreInitialSceneSetup = EditorGUILayout.ToggleLeft( restoreInitialSceneSetupLabel, restoreInitialSceneSetup );
|
||||
|
||||
if( GUILayout.Button( "Reset Search", Utilities.GL_HEIGHT_30 ) )
|
||||
ReturnToSetupPhase( restoreInitialSceneSetup );
|
||||
ReturnToSetupPhase();
|
||||
|
||||
if( searchResult == null )
|
||||
{
|
||||
@@ -549,140 +573,119 @@ namespace AssetUsageDetectorNamespace
|
||||
else if( !searchResult.SearchCompletedSuccessfully )
|
||||
EditorGUILayout.HelpBox( "ERROR: search was interrupted, check the logs for more info", MessageType.Error );
|
||||
|
||||
Color c = GUI.color;
|
||||
GUI.color = Color.green;
|
||||
GUILayout.Box( "Don't forget to save scene(s) if you made any changes!", Utilities.BoxGUIStyle, Utilities.GL_EXPAND_WIDTH );
|
||||
GUI.color = c;
|
||||
|
||||
if( searchResult.NumberOfGroups == 0 )
|
||||
{
|
||||
GUILayout.Space( 10 );
|
||||
GUILayout.Space( 10f );
|
||||
GUILayout.Box( "No references found...", Utilities.BoxGUIStyle, Utilities.GL_EXPAND_WIDTH );
|
||||
}
|
||||
else
|
||||
{
|
||||
//GUILayout.Space( 10 );
|
||||
//GUILayout.BeginHorizontal();
|
||||
noAssetDatabaseChanges = WordWrappingToggleLeft( "I haven't modified any assets/scenes since the last search (faster Refresh)", noAssetDatabaseChanges );
|
||||
|
||||
//// Select all the references after filtering them (select only the GameObject's)
|
||||
//if( GUILayout.Button( "Select All\n(GameObject-wise)", Utilities.GL_HEIGHT_35 ) )
|
||||
//{
|
||||
// GameObject[] objects = searchResult.SelectAllAsGameObjects();
|
||||
// if( objects != null && objects.Length > 0 )
|
||||
// Selection.objects = objects;
|
||||
//}
|
||||
EditorGUILayout.Space();
|
||||
|
||||
//// Select all the references without filtering them
|
||||
//if( GUILayout.Button( "Select All\n(Object-wise)", Utilities.GL_HEIGHT_35 ) )
|
||||
//{
|
||||
// Object[] objects = searchResult.SelectAllAsObjects();
|
||||
// if( objects != null && objects.Length > 0 )
|
||||
// Selection.objects = objects;
|
||||
//}
|
||||
|
||||
//GUILayout.EndHorizontal();
|
||||
|
||||
//GUILayout.Space( 10 );
|
||||
|
||||
searchResultDrawParameters.showTooltips = EditorGUILayout.ToggleLeft( showTooltipsLabel, searchResultDrawParameters.showTooltips );
|
||||
noAssetDatabaseChanges = EditorGUILayout.ToggleLeft( "I haven't modified any assets/scenes since the last search (faster Refresh)", noAssetDatabaseChanges );
|
||||
searchResultDrawParameters.noAssetDatabaseChanges = noAssetDatabaseChanges;
|
||||
|
||||
Utilities.DrawSeparatorLine();
|
||||
|
||||
GUILayout.Label( "Path drawing mode:" );
|
||||
|
||||
GUILayout.BeginHorizontal();
|
||||
|
||||
GUILayout.Space( 35 );
|
||||
|
||||
if( EditorGUILayout.ToggleLeft( "Full: Draw the complete paths to the references", searchResultDrawParameters.pathDrawingMode == PathDrawingMode.Full ) )
|
||||
searchResultDrawParameters.pathDrawingMode = PathDrawingMode.Full;
|
||||
|
||||
GUILayout.EndHorizontal();
|
||||
|
||||
GUILayout.BeginHorizontal();
|
||||
|
||||
GUILayout.Space( 35 );
|
||||
|
||||
if( EditorGUILayout.ToggleLeft( "Shorter: Draw only the most relevant parts (that start with a UnityEngine.Object) of the complete paths", searchResultDrawParameters.pathDrawingMode == PathDrawingMode.ShortRelevantParts ) )
|
||||
searchResultDrawParameters.pathDrawingMode = PathDrawingMode.ShortRelevantParts;
|
||||
|
||||
GUILayout.EndHorizontal();
|
||||
|
||||
GUILayout.BeginHorizontal();
|
||||
|
||||
GUILayout.Space( 35 );
|
||||
|
||||
if( EditorGUILayout.ToggleLeft( "Shortest: Draw only the last two nodes of the complete paths", searchResultDrawParameters.pathDrawingMode == PathDrawingMode.Shortest ) )
|
||||
searchResultDrawParameters.pathDrawingMode = PathDrawingMode.Shortest;
|
||||
|
||||
GUILayout.EndHorizontal();
|
||||
|
||||
searchResult.DrawOnGUI( searchResultDrawParameters );
|
||||
scrollPosition.y = searchResult.DrawOnGUI( this, scrollPosition.y, noAssetDatabaseChanges );
|
||||
}
|
||||
}
|
||||
|
||||
GUILayout.Space( 10 );
|
||||
if( Event.current.type == EventType.MouseLeaveWindow )
|
||||
{
|
||||
SearchResultTooltip.Hide();
|
||||
|
||||
if( searchResult != null )
|
||||
searchResult.CancelDelayedTreeViewTooltip();
|
||||
}
|
||||
|
||||
GUILayout.EndVertical();
|
||||
|
||||
EditorGUILayout.EndScrollView();
|
||||
}
|
||||
|
||||
private void DrawObjectsToSearchSection()
|
||||
{
|
||||
Color c = GUI.backgroundColor;
|
||||
GUI.backgroundColor = AssetUsageDetectorSettings.SettingsHeaderColor;
|
||||
GUILayout.Box( "<b>SEARCHED OBJECTS</b>", Utilities.BoxGUIStyle, Utilities.GL_EXPAND_WIDTH );
|
||||
GUI.backgroundColor = c;
|
||||
|
||||
Rect searchedObjectsHeaderRect = GUILayoutUtility.GetLastRect();
|
||||
searchedObjectsHeaderRect.x += 5f;
|
||||
searchedObjectsHeaderRect.yMin += ( searchedObjectsHeaderRect.height - EditorGUIUtility.singleLineHeight ) * 0.5f;
|
||||
searchedObjectsHeaderRect.height = EditorGUIUtility.singleLineHeight;
|
||||
|
||||
drawObjectsToSearchSection = EditorGUI.Foldout( searchedObjectsHeaderRect, drawObjectsToSearchSection, GUIContent.none, true );
|
||||
|
||||
if( drawObjectsToSearchSection )
|
||||
objectsToSearchDrawer.Draw( objectsToSearch );
|
||||
}
|
||||
|
||||
private bool WordWrappingToggleLeft( string label, bool value )
|
||||
{
|
||||
GUILayout.BeginHorizontal();
|
||||
bool result = EditorGUILayout.ToggleLeft( GUIContent.none, value, GL_WIDTH_12 );
|
||||
if( GUILayout.Button( label, EditorStyles.wordWrappedLabel ) )
|
||||
{
|
||||
GUI.FocusControl( null );
|
||||
result = !value;
|
||||
}
|
||||
GUILayout.EndHorizontal();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private void InitiateSearch()
|
||||
{
|
||||
if( objectsToSearch.IsEmpty() )
|
||||
errorMessage = "ADD AN ASSET TO THE LIST FIRST!";
|
||||
else if( !EditorApplication.isPlaying && !Utilities.AreScenesSaved() )
|
||||
{
|
||||
// Don't start the search if at least one scene is currently dirty (not saved)
|
||||
errorMessage = "SAVE OPEN SCENES FIRST!";
|
||||
}
|
||||
else
|
||||
{
|
||||
errorMessage = string.Empty;
|
||||
currentPhase = Phase.Processing;
|
||||
currentPhase = Phase.Processing;
|
||||
|
||||
SavePrefs();
|
||||
SavePrefs();
|
||||
|
||||
#if UNITY_2018_3_OR_NEWER
|
||||
ReplacePrefabStageObjectsWithAssets( UnityEditor.Experimental.SceneManagement.PrefabStageUtility.GetCurrentPrefabStage() );
|
||||
ReplacePrefabStageObjectsWithAssets( PrefabStageUtility.GetCurrentPrefabStage() );
|
||||
#endif
|
||||
|
||||
// Start searching
|
||||
searchResult = core.Run( new AssetUsageDetector.Parameters()
|
||||
{
|
||||
objectsToSearch = new ObjectToSearchEnumerator( objectsToSearch ).ToArray(),
|
||||
searchInScenes = GetSceneSearchMode( true ),
|
||||
searchInAssetsFolder = searchInAssetsFolder,
|
||||
searchInAssetsSubset = !searchInAssetsSubset.IsEmpty() ? searchInAssetsSubset.ToArray() : null,
|
||||
excludedAssetsFromSearch = !excludedAssets.IsEmpty() ? excludedAssets.ToArray() : null,
|
||||
dontSearchInSourceAssets = dontSearchInSourceAssets,
|
||||
excludedScenesFromSearch = !excludedScenes.IsEmpty() ? excludedScenes.ToArray() : null,
|
||||
searchInProjectSettings = searchInProjectSettings,
|
||||
//fieldModifiers = fieldModifiers,
|
||||
//propertyModifiers = propertyModifiers,
|
||||
//searchDepthLimit = searchDepthLimit,
|
||||
//searchNonSerializableVariables = searchNonSerializableVariables,
|
||||
lazySceneSearch = lazySceneSearch,
|
||||
noAssetDatabaseChanges = noAssetDatabaseChanges,
|
||||
showDetailedProgressBar = showDetailedProgressBar
|
||||
} );
|
||||
// Start searching
|
||||
searchResult = core.Run( new AssetUsageDetector.Parameters()
|
||||
{
|
||||
objectsToSearch = !objectsToSearch.IsEmpty() ? new ObjectToSearchEnumerator( objectsToSearch ).ToArray() : null,
|
||||
searchInScenes = GetSceneSearchMode( true ),
|
||||
searchInAssetsFolder = searchInAssetsFolder,
|
||||
searchInAssetsSubset = !searchInAssetsSubset.IsEmpty() ? searchInAssetsSubset.ToArray() : null,
|
||||
excludedAssetsFromSearch = !excludedAssets.IsEmpty() ? excludedAssets.ToArray() : null,
|
||||
dontSearchInSourceAssets = dontSearchInSourceAssets,
|
||||
excludedScenesFromSearch = !excludedScenes.IsEmpty() ? excludedScenes.ToArray() : null,
|
||||
searchInProjectSettings = searchInProjectSettings,
|
||||
//fieldModifiers = fieldModifiers,
|
||||
//propertyModifiers = propertyModifiers,
|
||||
//searchDepthLimit = searchDepthLimit,
|
||||
//searchNonSerializableVariables = searchNonSerializableVariables,
|
||||
searchUnusedMaterialProperties = searchUnusedMaterialProperties,
|
||||
lazySceneSearch = lazySceneSearch,
|
||||
calculateUnusedObjects = calculateUnusedObjects,
|
||||
hideDuplicateRows = hideDuplicateRows,
|
||||
hideReduntantPrefabVariantLinks = hideReduntantPrefabVariantLinks,
|
||||
noAssetDatabaseChanges = noAssetDatabaseChanges,
|
||||
showDetailedProgressBar = showDetailedProgressBar
|
||||
} );
|
||||
|
||||
currentPhase = Phase.Complete;
|
||||
}
|
||||
currentPhase = Phase.Complete;
|
||||
|
||||
if( AssetUsageDetectorSettings.ShowCustomTooltip )
|
||||
wantsMouseMove = wantsMouseEnterLeaveWindow = true;
|
||||
}
|
||||
|
||||
#if UNITY_2018_3_OR_NEWER
|
||||
// Try replacing searched objects who are part of currently open prefab stage with their corresponding prefab assets
|
||||
public void ReplacePrefabStageObjectsWithAssets( UnityEditor.Experimental.SceneManagement.PrefabStage prefabStage )
|
||||
public void ReplacePrefabStageObjectsWithAssets( PrefabStage prefabStage )
|
||||
{
|
||||
if( prefabStage == null || !prefabStage.stageHandle.IsValid() )
|
||||
return;
|
||||
|
||||
#if UNITY_2020_1_OR_NEWER
|
||||
GameObject prefabAsset = AssetDatabase.LoadAssetAtPath<GameObject>( prefabStage.assetPath );
|
||||
#else
|
||||
GameObject prefabAsset = AssetDatabase.LoadAssetAtPath<GameObject>( prefabStage.prefabAssetPath );
|
||||
if( prefabAsset == null )
|
||||
#endif
|
||||
if( prefabAsset == null || prefabAsset.Equals( null ) )
|
||||
return;
|
||||
|
||||
for( int i = 0; i < objectsToSearch.Count; i++ )
|
||||
@@ -710,17 +713,35 @@ namespace AssetUsageDetectorNamespace
|
||||
}
|
||||
#endif
|
||||
|
||||
private bool ReturnToSetupPhase( bool restoreInitialSceneSetup )
|
||||
private bool ReturnToSetupPhase()
|
||||
{
|
||||
if( searchResult != null && restoreInitialSceneSetup && !EditorApplication.isPlaying && !searchResult.RestoreInitialSceneSetup() )
|
||||
if( searchResult != null && !EditorApplication.isPlaying && !searchResult.RestoreInitialSceneSetup() )
|
||||
return false;
|
||||
|
||||
searchResult = null;
|
||||
|
||||
errorMessage = string.Empty;
|
||||
currentPhase = Phase.Setup;
|
||||
wantsMouseMove = wantsMouseEnterLeaveWindow = false;
|
||||
|
||||
SearchResultTooltip.Hide();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
internal void OnSettingsChanged( bool highlightedSearchTextColorChanged = false, bool tooltipDescriptionsColorChanged = false )
|
||||
{
|
||||
if( searchResult == null )
|
||||
return;
|
||||
|
||||
wantsMouseMove = wantsMouseEnterLeaveWindow = AssetUsageDetectorSettings.ShowCustomTooltip;
|
||||
|
||||
for( int i = searchResult.NumberOfGroups - 1; i >= 0; i-- )
|
||||
{
|
||||
if( searchResult[i].treeView != null )
|
||||
{
|
||||
searchResult[i].treeView.rowHeight = EditorGUIUtility.singleLineHeight + AssetUsageDetectorSettings.ExtraRowHeight;
|
||||
searchResult[i].treeView.OnSettingsChanged( highlightedSearchTextColorChanged, tooltipDescriptionsColorChanged );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -31,8 +31,7 @@ namespace AssetUsageDetectorNamespace
|
||||
{
|
||||
// Handle drag & drop references to array
|
||||
// Credit: https://answers.unity.com/answers/657877/view.html
|
||||
if( ( ev.type == EventType.DragPerform || ev.type == EventType.DragUpdated ) &&
|
||||
GUILayoutUtility.GetLastRect().Contains( ev.mousePosition ) )
|
||||
if( ( ev.type == EventType.DragPerform || ev.type == EventType.DragUpdated ) && GUILayoutUtility.GetLastRect().Contains( ev.mousePosition ) )
|
||||
{
|
||||
DragAndDrop.visualMode = DragAndDropVisualMode.Copy;
|
||||
if( ev.type == EventType.DragPerform )
|
||||
@@ -69,6 +68,18 @@ namespace AssetUsageDetectorNamespace
|
||||
|
||||
ev.Use();
|
||||
}
|
||||
else if( ev.type == EventType.ContextClick && GUILayoutUtility.GetLastRect().Contains( ev.mousePosition ) )
|
||||
{
|
||||
GenericMenu contextMenu = new GenericMenu();
|
||||
contextMenu.AddItem( new GUIContent( "Clear" ), false, () =>
|
||||
{
|
||||
list.Clear();
|
||||
list.Add( CreateElement( null ) );
|
||||
} );
|
||||
contextMenu.ShowAsContext();
|
||||
|
||||
ev.Use();
|
||||
}
|
||||
|
||||
if( GUILayout.Button( "+", Utilities.GL_WIDTH_25 ) )
|
||||
list.Insert( 0, CreateElement( null ) );
|
||||
@@ -86,7 +97,7 @@ namespace AssetUsageDetectorNamespace
|
||||
Object prevObject = GetObjectFromElement( element );
|
||||
Object newObject = EditorGUILayout.ObjectField( "", prevObject, typeof( Object ), acceptSceneObjects );
|
||||
|
||||
if( GUI.changed && prevObject != newObject )
|
||||
if( GUI.changed )
|
||||
{
|
||||
hasChanged = true;
|
||||
SetObjectOfElement( list, i, newObject );
|
||||
|
||||
@@ -26,16 +26,15 @@ namespace AssetUsageDetectorNamespace
|
||||
public List<SubAsset> subAssets;
|
||||
public bool showSubAssetsFoldout;
|
||||
|
||||
private static MonoScript[] monoScriptsInProject;
|
||||
private static HashSet<Object> currentSubAssets;
|
||||
|
||||
public ObjectToSearch( Object obj )
|
||||
public ObjectToSearch( Object obj, bool? shouldSearchChildren = null )
|
||||
{
|
||||
this.obj = obj;
|
||||
RefreshSubAssets();
|
||||
RefreshSubAssets( shouldSearchChildren );
|
||||
}
|
||||
|
||||
public void RefreshSubAssets()
|
||||
public void RefreshSubAssets( bool? shouldSearchChildren = null )
|
||||
{
|
||||
if( subAssets == null )
|
||||
subAssets = new List<SubAsset>();
|
||||
@@ -47,11 +46,11 @@ namespace AssetUsageDetectorNamespace
|
||||
else
|
||||
currentSubAssets.Clear();
|
||||
|
||||
AddSubAssets( obj, false );
|
||||
AddSubAssets( obj, false, shouldSearchChildren );
|
||||
currentSubAssets.Clear();
|
||||
}
|
||||
|
||||
private void AddSubAssets( Object target, bool includeTarget )
|
||||
private void AddSubAssets( Object target, bool includeTarget, bool? shouldSearchChildren )
|
||||
{
|
||||
if( target == null || target.Equals( null ) )
|
||||
return;
|
||||
@@ -65,13 +64,13 @@ namespace AssetUsageDetectorNamespace
|
||||
// If this is a scene object, add its child objects to the sub-assets list
|
||||
// but don't include them in the search by default
|
||||
Transform goTransform = go.transform;
|
||||
Transform[] children = go.GetComponentsInChildren<Transform>();
|
||||
Transform[] children = go.GetComponentsInChildren<Transform>( true );
|
||||
for( int i = 0; i < children.Length; i++ )
|
||||
{
|
||||
if( ReferenceEquals( children[i], goTransform ) )
|
||||
continue;
|
||||
|
||||
subAssets.Add( new SubAsset( children[i].gameObject, false ) );
|
||||
subAssets.Add( new SubAsset( children[i].gameObject, shouldSearchChildren ?? false ) );
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -81,11 +80,8 @@ namespace AssetUsageDetectorNamespace
|
||||
|
||||
if( includeTarget )
|
||||
{
|
||||
if( !currentSubAssets.Contains( target ) )
|
||||
{
|
||||
subAssets.Add( new SubAsset( target, true ) );
|
||||
currentSubAssets.Add( target );
|
||||
}
|
||||
if( currentSubAssets.Add( target ) )
|
||||
subAssets.Add( new SubAsset( target, shouldSearchChildren ?? true ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -93,7 +89,7 @@ namespace AssetUsageDetectorNamespace
|
||||
if( target.IsFolder() )
|
||||
{
|
||||
foreach( string filePath in Utilities.EnumerateFolderContents( target ) )
|
||||
AddSubAssets( AssetDatabase.LoadAssetAtPath<Object>( filePath ), true );
|
||||
AddSubAssets( AssetDatabase.LoadAssetAtPath<Object>( filePath ), true, shouldSearchChildren );
|
||||
|
||||
return;
|
||||
}
|
||||
@@ -104,49 +100,19 @@ namespace AssetUsageDetectorNamespace
|
||||
for( int i = 0; i < assets.Length; i++ )
|
||||
{
|
||||
Object asset = assets[i];
|
||||
if( asset == null || asset.Equals( null ) || asset is Component )
|
||||
if( asset == null || asset.Equals( null ) || asset is Component || asset == target )
|
||||
continue;
|
||||
|
||||
if( currentSubAssets.Contains( asset ) )
|
||||
#if UNITY_2018_3_OR_NEWER
|
||||
// Nested prefabs in prefab assets add an additional native object of type 'UnityEngine.PrefabInstance' to the prefab. Managed type of that native type
|
||||
// is UnityEngine.Object (i.e. GetType() returns UnityEngine.Object, not UnityEngine.PrefabInstance). There are no possible references to these native
|
||||
// objects so skip them (we're checking for UnityEngine.Prefab because it includes other native types like UnityEngine.PrefabCreation, as well)
|
||||
if( target is GameObject && asset.GetType() == typeof( Object ) && asset.ToString().Contains( "(UnityEngine.Prefab" ) )
|
||||
continue;
|
||||
#endif
|
||||
|
||||
if( asset != target )
|
||||
{
|
||||
subAssets.Add( new SubAsset( asset, true ) );
|
||||
currentSubAssets.Add( asset );
|
||||
}
|
||||
|
||||
// MonoScripts are a special case such that other MonoScript objects
|
||||
// that extend this MonoScript are also considered a sub-asset
|
||||
if( asset is MonoScript )
|
||||
{
|
||||
Type monoScriptType = ( (MonoScript) asset ).GetClass();
|
||||
if( monoScriptType == null || ( !monoScriptType.IsInterface && !typeof( Component ).IsAssignableFrom( monoScriptType ) ) )
|
||||
continue;
|
||||
|
||||
// Find all MonoScript objects in the project
|
||||
if( monoScriptsInProject == null )
|
||||
{
|
||||
string[] monoScriptGuids = AssetDatabase.FindAssets( "t:MonoScript" );
|
||||
monoScriptsInProject = new MonoScript[monoScriptGuids.Length];
|
||||
for( int k = 0; k < monoScriptGuids.Length; k++ )
|
||||
monoScriptsInProject[k] = AssetDatabase.LoadAssetAtPath<MonoScript>( AssetDatabase.GUIDToAssetPath( monoScriptGuids[k] ) );
|
||||
}
|
||||
|
||||
// Add any MonoScript objects that extend this MonoScript as a sub-asset
|
||||
for( int j = 0; j < monoScriptsInProject.Length; j++ )
|
||||
{
|
||||
Type otherMonoScriptType = monoScriptsInProject[j].GetClass();
|
||||
if( otherMonoScriptType == null || monoScriptType == otherMonoScriptType || !monoScriptType.IsAssignableFrom( otherMonoScriptType ) )
|
||||
continue;
|
||||
|
||||
if( !currentSubAssets.Contains( monoScriptsInProject[j] ) )
|
||||
{
|
||||
subAssets.Add( new SubAsset( monoScriptsInProject[j], true ) );
|
||||
currentSubAssets.Add( monoScriptsInProject[j] );
|
||||
}
|
||||
}
|
||||
}
|
||||
if( currentSubAssets.Add( asset ) )
|
||||
subAssets.Add( new SubAsset( asset, shouldSearchChildren ?? true ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,91 @@
|
||||
using System.Reflection;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace AssetUsageDetectorNamespace
|
||||
{
|
||||
public class SearchResultTooltip : EditorWindow
|
||||
{
|
||||
private static SearchResultTooltip mainWindow;
|
||||
private static string tooltip;
|
||||
|
||||
private static GUIStyle m_style;
|
||||
internal static GUIStyle Style
|
||||
{
|
||||
get
|
||||
{
|
||||
if( m_style == null )
|
||||
{
|
||||
m_style = (GUIStyle) typeof( EditorStyles ).GetProperty( "tooltip", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static ).GetValue( null, null );
|
||||
m_style.richText = true;
|
||||
}
|
||||
|
||||
return m_style;
|
||||
}
|
||||
}
|
||||
|
||||
public static void Show( Rect sourcePosition, string tooltip )
|
||||
{
|
||||
Vector2 preferredSize = Style.CalcSize( new GUIContent( tooltip ) ) + Style.contentOffset + new Vector2( Style.padding.horizontal + Style.margin.horizontal, Style.padding.vertical + Style.margin.vertical );
|
||||
Rect preferredPosition;
|
||||
|
||||
Rect positionLeft = new Rect( sourcePosition.position - new Vector2( preferredSize.x, 0f ), preferredSize );
|
||||
Rect screenFittedPositionLeft = Utilities.GetScreenFittedRect( positionLeft );
|
||||
|
||||
Vector2 positionOffset = positionLeft.position - screenFittedPositionLeft.position;
|
||||
Vector2 sizeOffset = positionLeft.size - screenFittedPositionLeft.size;
|
||||
if( positionOffset.sqrMagnitude <= 400f && sizeOffset.sqrMagnitude <= 400f )
|
||||
preferredPosition = screenFittedPositionLeft;
|
||||
else
|
||||
{
|
||||
Rect positionRight = new Rect( sourcePosition.position + new Vector2( sourcePosition.width, 0f ), preferredSize );
|
||||
Rect screenFittedPositionRight = Utilities.GetScreenFittedRect( positionRight );
|
||||
|
||||
Vector2 positionOffset2 = positionRight.position - screenFittedPositionRight.position;
|
||||
Vector2 sizeOffset2 = positionRight.size - screenFittedPositionRight.size;
|
||||
if( positionOffset2.magnitude + sizeOffset2.magnitude < positionOffset.magnitude + sizeOffset.magnitude )
|
||||
preferredPosition = screenFittedPositionRight;
|
||||
else
|
||||
preferredPosition = screenFittedPositionLeft;
|
||||
}
|
||||
|
||||
// Don't lose focus to the previous window
|
||||
EditorWindow prevFocusedWindow = focusedWindow;
|
||||
|
||||
if( !mainWindow )
|
||||
{
|
||||
mainWindow = CreateInstance<SearchResultTooltip>();
|
||||
mainWindow.ShowPopup();
|
||||
}
|
||||
|
||||
SearchResultTooltip.tooltip = tooltip;
|
||||
mainWindow.minSize = preferredPosition.size;
|
||||
mainWindow.position = preferredPosition;
|
||||
mainWindow.Repaint();
|
||||
|
||||
if( prevFocusedWindow )
|
||||
prevFocusedWindow.Focus();
|
||||
}
|
||||
|
||||
public static void Hide()
|
||||
{
|
||||
if( mainWindow )
|
||||
{
|
||||
mainWindow.Close();
|
||||
mainWindow = null;
|
||||
}
|
||||
}
|
||||
|
||||
private void OnGUI()
|
||||
{
|
||||
// If somehow the tooltip isn't automatically closed, allow closing it by clicking on it
|
||||
if( Event.current.type == EventType.MouseDown )
|
||||
{
|
||||
Hide();
|
||||
GUIUtility.ExitGUI();
|
||||
}
|
||||
|
||||
GUI.Label( new Rect( Vector2.zero, position.size ), tooltip, Style );
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c8bd4351b5024324ca5974ebcad1dde3
|
||||
timeCreated: 1639247551
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b3903f1d3149e9b4990e49206f8255c8
|
||||
timeCreated: 1638690728
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -10,6 +10,10 @@ using UnityEditor.SceneManagement;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
using Object = UnityEngine.Object;
|
||||
#if UNITY_2018_3_OR_NEWER
|
||||
using PrefabStage = UnityEditor.Experimental.SceneManagement.PrefabStage;
|
||||
using PrefabStageUtility = UnityEditor.Experimental.SceneManagement.PrefabStageUtility;
|
||||
#endif
|
||||
|
||||
namespace AssetUsageDetectorNamespace
|
||||
{
|
||||
@@ -45,14 +49,11 @@ namespace AssetUsageDetectorNamespace
|
||||
private static readonly string nativeCollectionsNamespace = typeof( NativeArray<int> ).Namespace;
|
||||
#endif
|
||||
|
||||
private static MethodInfo screenFittedRectGetter;
|
||||
|
||||
private static readonly HashSet<string> folderContentsSet = new HashSet<string>();
|
||||
|
||||
private static readonly StringBuilder stringBuilder = new StringBuilder( 10 );
|
||||
|
||||
#if UNITY_2018_3_OR_NEWER
|
||||
private static int previousPingedPrefabInstanceId;
|
||||
private static double previousPingedPrefabPingTime;
|
||||
#endif
|
||||
internal static readonly StringBuilder stringBuilder = new StringBuilder( 400 );
|
||||
|
||||
public static readonly GUILayoutOption GL_EXPAND_WIDTH = GUILayout.ExpandWidth( true );
|
||||
public static readonly GUILayoutOption GL_EXPAND_HEIGHT = GUILayout.ExpandHeight( true );
|
||||
@@ -75,66 +76,38 @@ namespace AssetUsageDetectorNamespace
|
||||
m_boxGUIStyle = new GUIStyle( EditorStyles.helpBox )
|
||||
{
|
||||
alignment = TextAnchor.MiddleCenter,
|
||||
font = EditorStyles.label.font
|
||||
font = EditorStyles.label.font,
|
||||
richText = true
|
||||
};
|
||||
|
||||
Color textColor = GUI.skin.button.normal.textColor;
|
||||
m_boxGUIStyle.normal.textColor = textColor;
|
||||
m_boxGUIStyle.hover.textColor = textColor;
|
||||
m_boxGUIStyle.focused.textColor = textColor;
|
||||
m_boxGUIStyle.active.textColor = textColor;
|
||||
|
||||
#if !UNITY_2019_1_OR_NEWER || UNITY_2019_3_OR_NEWER
|
||||
// On 2019.1 and 2019.2 versions, GUI.skin.button.fontSize returns 0 on some devices
|
||||
// https://forum.unity.com/threads/asset-usage-detector-find-references-to-an-asset-object-open-source.408134/page-3#post-7285954
|
||||
m_boxGUIStyle.fontSize = ( m_boxGUIStyle.fontSize + GUI.skin.button.fontSize ) / 2;
|
||||
#endif
|
||||
}
|
||||
|
||||
return m_boxGUIStyle;
|
||||
}
|
||||
}
|
||||
|
||||
private static GUIStyle m_tooltipGUIStyle; // GUIStyle used to draw the tooltip
|
||||
public static GUIStyle TooltipGUIStyle
|
||||
{
|
||||
get
|
||||
{
|
||||
GUIStyleState normalState;
|
||||
|
||||
if( m_tooltipGUIStyle != null )
|
||||
normalState = m_tooltipGUIStyle.normal;
|
||||
else
|
||||
{
|
||||
m_tooltipGUIStyle = new GUIStyle( EditorStyles.helpBox )
|
||||
{
|
||||
alignment = TextAnchor.MiddleCenter,
|
||||
font = EditorStyles.label.font
|
||||
};
|
||||
|
||||
normalState = m_tooltipGUIStyle.normal;
|
||||
|
||||
normalState.background = null;
|
||||
normalState.scaledBackgrounds = new Texture2D[0];
|
||||
normalState.textColor = Color.black;
|
||||
}
|
||||
|
||||
if( normalState.background == null || normalState.background.Equals( null ) )
|
||||
{
|
||||
Texture2D backgroundTexture = new Texture2D( 1, 1 ) { hideFlags = HideFlags.HideAndDontSave };
|
||||
backgroundTexture.SetPixel( 0, 0, new Color( 0.88f, 0.88f, 0.88f, 0.85f ) );
|
||||
backgroundTexture.Apply();
|
||||
|
||||
normalState.background = backgroundTexture;
|
||||
}
|
||||
|
||||
return m_tooltipGUIStyle;
|
||||
}
|
||||
}
|
||||
|
||||
// Get a unique-ish string hash code for an object
|
||||
public static string Hash( this object obj )
|
||||
{
|
||||
if( obj is Object )
|
||||
return obj.GetHashCode().ToString();
|
||||
|
||||
return obj.GetHashCode() + obj.GetType().Name;
|
||||
}
|
||||
|
||||
// Check if object is an asset or a Scene object
|
||||
public static bool IsAsset( this object obj )
|
||||
{
|
||||
return obj is Object && AssetDatabase.Contains( (Object) obj );
|
||||
}
|
||||
|
||||
public static bool IsAsset( this Object obj )
|
||||
{
|
||||
return AssetDatabase.Contains( obj );
|
||||
}
|
||||
|
||||
// Check if object is a folder asset
|
||||
public static bool IsFolder( this Object obj )
|
||||
{
|
||||
@@ -159,126 +132,65 @@ namespace AssetUsageDetectorNamespace
|
||||
return folderContentsSet;
|
||||
}
|
||||
|
||||
// Select an object in the editor
|
||||
public static void SelectInEditor( this Object obj )
|
||||
public static void GetObjectsToSelectAndPing( this Object obj, out Object selection, out Object pingTarget )
|
||||
{
|
||||
if( obj == null )
|
||||
return;
|
||||
|
||||
Event e = Event.current;
|
||||
|
||||
// If CTRL or Shift keys are pressed, do a multi-select;
|
||||
// otherwise select only the clicked object and ping it in editor
|
||||
if( !e.control && !e.shift )
|
||||
Selection.activeObject = obj.PingInEditor();
|
||||
else
|
||||
if( obj == null || obj.Equals( null ) )
|
||||
{
|
||||
Component objAsComp = obj as Component;
|
||||
GameObject objAsGO = obj as GameObject;
|
||||
int selectionIndex = -1;
|
||||
|
||||
Object[] selection = Selection.objects;
|
||||
for( int i = 0; i < selection.Length; i++ )
|
||||
{
|
||||
Object selected = selection[i];
|
||||
|
||||
// Don't allow including both a gameobject and one of its components in the selection
|
||||
if( selected == obj || ( objAsComp != null && selected == objAsComp.gameObject ) ||
|
||||
( objAsGO != null && selected is Component && ( (Component) selected ).gameObject == objAsGO ) )
|
||||
{
|
||||
selectionIndex = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
Object[] newSelection;
|
||||
if( selectionIndex == -1 )
|
||||
{
|
||||
// Include object in selection
|
||||
newSelection = new Object[selection.Length + 1];
|
||||
selection.CopyTo( newSelection, 0 );
|
||||
newSelection[selection.Length] = obj;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Remove object from selection
|
||||
newSelection = new Object[selection.Length - 1];
|
||||
int j = 0;
|
||||
for( int i = 0; i < selectionIndex; i++, j++ )
|
||||
newSelection[j] = selection[i];
|
||||
for( int i = selectionIndex + 1; i < selection.Length; i++, j++ )
|
||||
newSelection[j] = selection[i];
|
||||
}
|
||||
|
||||
Selection.objects = newSelection;
|
||||
selection = pingTarget = null;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Ping an object in either Project view or Hierarchy view
|
||||
public static Object PingInEditor( this Object obj )
|
||||
{
|
||||
if( obj is Component )
|
||||
obj = ( (Component) obj ).gameObject;
|
||||
|
||||
Object selection = obj;
|
||||
selection = pingTarget = obj;
|
||||
|
||||
// Pinging a prefab only works if the pinged object is the root of the prefab
|
||||
// or a direct child of it. Pinging any grandchildren of the prefab
|
||||
// does not work; in which case, traverse the parent hierarchy until
|
||||
// a pingable parent is reached
|
||||
if( obj.IsAsset() && obj is GameObject )
|
||||
if( obj.IsAsset() )
|
||||
{
|
||||
#if UNITY_2018_3_OR_NEWER
|
||||
Transform objTR = ( (GameObject) obj ).transform.root;
|
||||
|
||||
PrefabAssetType prefabAssetType = PrefabUtility.GetPrefabAssetType( objTR.gameObject );
|
||||
if( prefabAssetType == PrefabAssetType.Regular || prefabAssetType == PrefabAssetType.Variant )
|
||||
if( obj is GameObject )
|
||||
{
|
||||
string assetPath = AssetDatabase.GetAssetPath( objTR.gameObject );
|
||||
var openPrefabStage = UnityEditor.Experimental.SceneManagement.PrefabStageUtility.GetCurrentPrefabStage();
|
||||
// Pinging a prefab only works if the pinged object is the root of the prefab or a direct child of it. Pinging any grandchildren
|
||||
// of the prefab doesn't work; in which case, traverse the parent hierarchy until a pingable parent is reached
|
||||
#if UNITY_2018_3_OR_NEWER
|
||||
Transform objTR = ( (GameObject) obj ).transform.root;
|
||||
|
||||
// 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 ) )
|
||||
PrefabAssetType prefabAssetType = PrefabUtility.GetPrefabAssetType( objTR.gameObject );
|
||||
if( prefabAssetType == PrefabAssetType.Regular || prefabAssetType == PrefabAssetType.Variant )
|
||||
{
|
||||
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 )
|
||||
{
|
||||
GameObject prefabStageGO = FollowSymmetricHierarchy( (GameObject) obj, ( (GameObject) obj ).transform.root.gameObject, openPrefabStage.prefabContentsRoot );
|
||||
if( prefabStageGO != null )
|
||||
string assetPath = AssetDatabase.GetAssetPath( objTR.gameObject );
|
||||
PrefabStage openPrefabStage = PrefabStageUtility.GetCurrentPrefabStage();
|
||||
#if UNITY_2020_1_OR_NEWER
|
||||
if( openPrefabStage != null && openPrefabStage.stageHandle.IsValid() && assetPath == openPrefabStage.assetPath )
|
||||
#else
|
||||
if( openPrefabStage != null && openPrefabStage.stageHandle.IsValid() && assetPath == openPrefabStage.prefabAssetPath )
|
||||
#endif
|
||||
{
|
||||
objTR = prefabStageGO.transform;
|
||||
selection = objTR.gameObject;
|
||||
GameObject prefabStageGO = FollowSymmetricHierarchy( (GameObject) obj, ( (GameObject) obj ).transform.root.gameObject, openPrefabStage.prefabContentsRoot );
|
||||
if( prefabStageGO != null )
|
||||
{
|
||||
objTR = prefabStageGO.transform;
|
||||
selection = objTR.gameObject;
|
||||
}
|
||||
}
|
||||
}
|
||||
#if UNITY_2019_1_OR_NEWER
|
||||
else if( obj != objTR.gameObject )
|
||||
{
|
||||
Debug.Log( "Open " + assetPath + " in prefab mode to select and edit " + obj.name );
|
||||
selection = objTR.gameObject;
|
||||
else if( obj != objTR.gameObject )
|
||||
selection = objTR.gameObject;
|
||||
#endif
|
||||
}
|
||||
#else
|
||||
else
|
||||
Debug.Log( "Open " + assetPath + " in prefab mode to select and edit " + obj.name );
|
||||
Transform objTR = ( (GameObject) obj ).transform;
|
||||
while( objTR.parent != null && objTR.parent.parent != null )
|
||||
objTR = objTR.parent;
|
||||
#endif
|
||||
|
||||
pingTarget = objTR.gameObject;
|
||||
}
|
||||
else if( ( obj.hideFlags & ( HideFlags.HideInInspector | HideFlags.HideInHierarchy ) ) != HideFlags.None )
|
||||
{
|
||||
// Can't ping assets that are hidden from Project window (e.g. animator states of AnimatorController), ping the main asset at that path instead
|
||||
pingTarget = AssetDatabase.LoadMainAssetAtPath( AssetDatabase.GetAssetPath( obj ) );
|
||||
}
|
||||
#else
|
||||
Transform objTR = ( (GameObject) obj ).transform;
|
||||
while( objTR.parent != null && objTR.parent.parent != null )
|
||||
objTR = objTR.parent;
|
||||
#endif
|
||||
|
||||
obj = objTR.gameObject;
|
||||
}
|
||||
|
||||
EditorGUIUtility.PingObject( obj );
|
||||
return selection;
|
||||
}
|
||||
|
||||
// We are passing "go"s root Transform to thisRoot parameter. If we use go.transform.root instead, when we are in prefab mode on
|
||||
@@ -315,12 +227,57 @@ namespace AssetUsageDetectorNamespace
|
||||
return root2.gameObject;
|
||||
}
|
||||
|
||||
// Returns -1 if t1 is above t2 in Hierarchy, 1 if t1 is below t2 in Hierarchy and 0 if they are the same object
|
||||
public static int CompareHierarchySiblingIndices( Transform t1, Transform t2 )
|
||||
{
|
||||
Transform parent1 = t1.parent;
|
||||
Transform parent2 = t2.parent;
|
||||
|
||||
if( parent1 == parent2 )
|
||||
return t1.GetSiblingIndex() - t2.GetSiblingIndex();
|
||||
|
||||
int deltaHierarchyDepth = 0;
|
||||
for( ; parent1; parent1 = parent1.parent )
|
||||
deltaHierarchyDepth++;
|
||||
for( ; parent2; parent2 = parent2.parent )
|
||||
deltaHierarchyDepth--;
|
||||
|
||||
for( ; deltaHierarchyDepth > 0; deltaHierarchyDepth-- )
|
||||
{
|
||||
t1 = t1.parent;
|
||||
if( t1 == t2 )
|
||||
return 1;
|
||||
}
|
||||
for( ; deltaHierarchyDepth < 0; deltaHierarchyDepth++ )
|
||||
{
|
||||
t2 = t2.parent;
|
||||
if( t1 == t2 )
|
||||
return -1;
|
||||
}
|
||||
|
||||
while( t1.parent != t2.parent )
|
||||
{
|
||||
t1 = t1.parent;
|
||||
t2 = t2.parent;
|
||||
}
|
||||
|
||||
return t1.GetSiblingIndex() - t2.GetSiblingIndex();
|
||||
}
|
||||
|
||||
// Check if the field is serializable
|
||||
public static bool IsSerializable( this FieldInfo fieldInfo )
|
||||
{
|
||||
// see Serialization Rules: https://docs.unity3d.com/Manual/script-Serialization.html
|
||||
if( fieldInfo.IsInitOnly || ( ( !fieldInfo.IsPublic || fieldInfo.IsNotSerialized ) &&
|
||||
!Attribute.IsDefined( fieldInfo, typeof( SerializeField ) ) ) )
|
||||
// See Serialization Rules: https://docs.unity3d.com/Manual/script-Serialization.html
|
||||
if( fieldInfo.IsInitOnly )
|
||||
return false;
|
||||
|
||||
#if UNITY_2019_3_OR_NEWER
|
||||
// SerializeReference makes even System.Object fields serializable
|
||||
if( Attribute.IsDefined( fieldInfo, typeof( SerializeReference ) ) )
|
||||
return true;
|
||||
#endif
|
||||
|
||||
if( ( !fieldInfo.IsPublic || fieldInfo.IsNotSerialized ) && !Attribute.IsDefined( fieldInfo, typeof( SerializeField ) ) )
|
||||
return false;
|
||||
|
||||
return IsTypeSerializable( fieldInfo.FieldType );
|
||||
@@ -351,6 +308,16 @@ namespace AssetUsageDetectorNamespace
|
||||
}
|
||||
else if( type.IsGenericType )
|
||||
{
|
||||
// Generic types are allowed on 2020.1 and later
|
||||
#if UNITY_2020_1_OR_NEWER
|
||||
if( type.GetGenericTypeDefinition() == typeof( List<> ) )
|
||||
{
|
||||
type = type.GetGenericArguments()[0];
|
||||
|
||||
if( typeof( Object ).IsAssignableFrom( type ) )
|
||||
return true;
|
||||
}
|
||||
#else
|
||||
if( type.GetGenericTypeDefinition() != typeof( List<> ) )
|
||||
return false;
|
||||
|
||||
@@ -358,10 +325,13 @@ namespace AssetUsageDetectorNamespace
|
||||
|
||||
if( typeof( Object ).IsAssignableFrom( type ) )
|
||||
return true;
|
||||
#endif
|
||||
}
|
||||
|
||||
#if !UNITY_2020_1_OR_NEWER
|
||||
if( type.IsGenericType )
|
||||
return false;
|
||||
#endif
|
||||
|
||||
return Attribute.IsDefined( type, typeof( SerializableAttribute ), false );
|
||||
}
|
||||
@@ -382,8 +352,8 @@ namespace AssetUsageDetectorNamespace
|
||||
if( typeof( Type ).IsAssignableFrom( type ) || type.Namespace == reflectionNamespace )
|
||||
return true;
|
||||
|
||||
// Searching pointer variables for reference throws ArgumentException
|
||||
if( type.IsPointer )
|
||||
// Searching pointers or ref variables for reference throws ArgumentException
|
||||
if( type.IsPointer || type.IsByRef )
|
||||
return true;
|
||||
|
||||
return false;
|
||||
@@ -413,7 +383,20 @@ namespace AssetUsageDetectorNamespace
|
||||
{
|
||||
// Can't use PropertyWrapper (which uses CreateDelegate) for property getters of structs
|
||||
if( propertyInfo.DeclaringType.IsValueType )
|
||||
return propertyInfo.CanRead ? ( ( obj ) => propertyInfo.GetValue( obj, null ) ) : (VariableGetVal) null;
|
||||
{
|
||||
return !propertyInfo.CanRead ? (VariableGetVal) null : ( obj ) =>
|
||||
{
|
||||
try
|
||||
{
|
||||
return propertyInfo.GetValue( obj, null );
|
||||
}
|
||||
catch
|
||||
{
|
||||
// Property getters may return various kinds of exceptions if their backing fields are not initialized (yet)
|
||||
return null;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
Type GenType = typeof( PropertyWrapper<,> ).MakeGenericType( propertyInfo.DeclaringType, propertyInfo.PropertyType );
|
||||
return ( (IPropertyAccessor) Activator.CreateInstance( GenType, propertyInfo.GetGetMethod( true ) ) ).GetValue;
|
||||
@@ -455,9 +438,18 @@ namespace AssetUsageDetectorNamespace
|
||||
// Draw horizontal line inside OnGUI
|
||||
public static void DrawSeparatorLine()
|
||||
{
|
||||
GUILayout.Space( 4 );
|
||||
GUILayout.Space( 4f );
|
||||
GUILayout.Box( "", GL_HEIGHT_2, GL_EXPAND_WIDTH );
|
||||
GUILayout.Space( 4 );
|
||||
GUILayout.Space( 4f );
|
||||
}
|
||||
|
||||
// Restricts the given Rect within the screen's bounds
|
||||
public static Rect GetScreenFittedRect( Rect originalRect )
|
||||
{
|
||||
if( screenFittedRectGetter == null )
|
||||
screenFittedRectGetter = typeof( EditorWindow ).Assembly.GetType( "UnityEditor.ContainerWindow" ).GetMethod( "FitRectToScreen", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static );
|
||||
|
||||
return (Rect) screenFittedRectGetter.Invoke( null, new object[3] { originalRect, true, true } );
|
||||
}
|
||||
|
||||
// Check if all the objects inside the list are null
|
||||
@@ -558,13 +550,5 @@ namespace AssetUsageDetectorNamespace
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public static void RemoveAtFast<T>( this List<T> list, int index )
|
||||
{
|
||||
int lastElementIndex = list.Count - 1;
|
||||
|
||||
list[index] = list[lastElementIndex];
|
||||
list.RemoveAt( lastElementIndex );
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -69,8 +69,7 @@ namespace AssetUsageDetectorNamespace
|
||||
}
|
||||
catch
|
||||
{
|
||||
// Property getters may return various kinds of exceptions
|
||||
// if their backing fields are not initialized (yet)
|
||||
// Property getters may return various kinds of exceptions if their backing fields are not initialized (yet)
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,17 +3,43 @@
|
||||
Online documentation available at: https://github.com/yasirkula/UnityAssetUsageDetector
|
||||
E-mail: yasirkula@gmail.com
|
||||
|
||||
1. ABOUT
|
||||
This tool helps you find usages of the selected asset(s) and/or Object(s) in your Unity project, i.e. lists the objects that refer to them.
|
||||
|
||||
2. HOW TO
|
||||
Open "Window-Asset Usage Detector" window, configure the settings and hit GO! You can also right click an object and select "Search For References".
|
||||
### ABOUT
|
||||
This tool helps you find usages of the selected asset(s) and/or scene object(s), i.e. lists the objects that refer to them.
|
||||
|
||||
In the search results page, each row represents a reference to the searched Object(s). Rows can be traversed from left to right to see how the
|
||||
references are formed. If a node's label contains text inside square brackets (e.g. [Child object]), then that text describes how that node is
|
||||
connected to the node to its left.
|
||||
|
||||
3. KNOWN LIMITATIONS
|
||||
- static variables are not searched
|
||||
- GUIText materials are not searched
|
||||
- Textures in Lens Flare's can not be searched
|
||||
### HOW TO
|
||||
- Open "Window-Asset Usage Detector" window, configure the settings and hit "GO!". You can also right click an object and select "Search For References"
|
||||
|
||||
- Asset Usage Detector window can be locked via the "Lock" button in its context menu (or via the lock icon at the top-right corner). If all the
|
||||
open windows are locked, "Search For References" opens a new window
|
||||
|
||||
- Seach results are split into different groups (scenes, assets, Project Settings) and each group displays its search results in its own tree view.
|
||||
Tree views support multi-selection and keyboard navigation. It's possible to hide groups or rows via their context menu (right click)
|
||||
|
||||
- Each root row in a group's tree view represents a different searched object and is drawn with an outline. Usage(s) of a searched object are listed under it as
|
||||
child rows (with indentation). If a child row's label contains bold text inside square brackets (e.g. "[Variable: m_Shader]"), then that text describes how
|
||||
its parent row is connected to that row (i.e. the value assigned to the m_Shader variable of that row is its parent row). Child rows can have their own children
|
||||
as some references involve multiple steps (e.g. when a Texture reference is found in a material which is used in a prefab which is referenced by a scene object)
|
||||
|
||||
- Rows with green tint to their left are the main references. For example, main references in a scene are the GameObjects that belong to that scene
|
||||
|
||||
- Rows with yellow tint are the parent rows of the selected row(s). To see a row's connection to the searched object, the yellow tinted rows can be traversed
|
||||
from bottom to top (or, you can hover the cursor over a row and see its connection to the searched object in a tooltip)
|
||||
|
||||
- Rows with gradient blue tint are the other occurrences of the selected row(s) (a row can appear multiple times in the tree view, right clicking the row and
|
||||
selecting "Expand All Occurrences" will reveal them all)
|
||||
|
||||
- When "Hide duplicate rows" option is enabled and a row's label starts with "[D]", then it means that the row has appeared in the tree view before and its children
|
||||
were omitted to simplify the search results (because otherwise the same child rows would be displayed for each occurrence of that row). Only the first occurrence
|
||||
of a row will display its children when "Hide duplicate rows" is enabled. To find a row's first occurrence, you can right click it and select "Select First Occurrence"
|
||||
|
||||
- Inside "Unused Objects" group, if a row's label starts with "[!]", then it means that some of its children are used in the project and it isn't safe to delete
|
||||
that object. Right clicking the row and selecting "Show Used Children" will reveal the used children
|
||||
|
||||
- When a prefab's row is double clicked, that prefab is automatically opened in Prefab Mode
|
||||
|
||||
- Selections in tree views are completely independent from each other, it isn't possible to multi-select objects in different tree views. Likewise, selected rows in
|
||||
a tree view won't be highlighted in other tree views. "Hide duplicate rows" also works independently for each tree view
|
||||
|
||||
- You can tweak most settings/colors via "Project Settings/yasirkula/Asset Usage Detector" page (on older versions, this menu is located at "Preferences" window)
|
||||
@@ -1,6 +1,9 @@
|
||||
{
|
||||
"name": "com.yasirkula.assetusagedetector",
|
||||
"displayName": "Asset Usage Detector",
|
||||
"version": "1.8.2",
|
||||
"description": "This editor extension helps you figure out at which places an asset or GameObject is used, i.e. lists the objects that refer to the asset. It is possible to search for references in the Assets folder (Project view) and/or in the scene(s) of your project. You can also search for references while in Play mode!"
|
||||
"version": "2.1.0",
|
||||
"documentationUrl": "https://github.com/yasirkula/UnityAssetUsageDetector",
|
||||
"changelogUrl": "https://github.com/yasirkula/UnityAssetUsageDetector/releases",
|
||||
"licensesUrl": "https://github.com/yasirkula/UnityAssetUsageDetector/blob/master/LICENSE.txt",
|
||||
"description": "This tool helps you find usages of the selected asset(s) and/or scene object(s), i.e. lists the objects that refer to them. It is possible to search for references in the Assets folder (Project view) and/or in the scene(s) of your project. You can also search for references while in Play mode!"
|
||||
}
|
||||
|
||||