mirror of
https://github.com/yasirkula/UnityAssetUsageDetector.git
synced 2026-11-19 22:42:37 +08:00
Compare commits
20 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 8f8316266c | |||
| 6edf344ebc | |||
| e80ad3b905 | |||
| 0342ab20c9 | |||
| 6a158cba7e | |||
| 652dbe2171 | |||
| a1b66ced77 | |||
| 2bd6a02504 | |||
| 790a508dcd | |||
| d6a03aa8f2 | |||
| 177db66fbd | |||
| 4415d4b6f4 | |||
| 5104901c5d | |||
| 962f6e04d4 | |||
| 204de979ba | |||
| 50ce6f56c9 | |||
| 0f872ef04d | |||
| f68c8a1375 | |||
| ecfb1adf88 | |||
| e63ebd7f85 |
+2
-2
@@ -21,8 +21,8 @@ There are 5 ways to install this plugin:
|
||||
- import [AssetUsageDetector.unitypackage](https://github.com/yasirkula/UnityAssetUsageDetector/releases) via *Assets-Import Package*
|
||||
- clone/[download](https://github.com/yasirkula/UnityAssetUsageDetector/archive/master.zip) this repository and move the *Plugins* folder to your Unity project's *Assets* folder
|
||||
- import it from [Asset Store](https://assetstore.unity.com/packages/tools/utilities/asset-usage-detector-112837)
|
||||
- *(via Package Manager)* add the following line to *Packages/manifest.json*:
|
||||
- `"com.yasirkula.assetusagedetector": "https://github.com/yasirkula/UnityAssetUsageDetector.git",`
|
||||
- *(via Package Manager)* click the + button and install the package from the following git URL:
|
||||
- `https://github.com/yasirkula/UnityAssetUsageDetector.git`
|
||||
- *(via [OpenUPM](https://openupm.com))* after installing [openupm-cli](https://github.com/openupm/openupm-cli), run the following command:
|
||||
- `openupm add com.yasirkula.assetusagedetector`
|
||||
|
||||
|
||||
@@ -2,7 +2,8 @@
|
||||
"name": "AssetUsageDetector.Editor",
|
||||
"rootNamespace": "",
|
||||
"references": [
|
||||
"Unity.Addressables"
|
||||
"Unity.Addressables",
|
||||
"Unity.Addressables.Editor"
|
||||
],
|
||||
"includePlatforms": [
|
||||
"Editor"
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
// Asset Usage Detector - by Suleyman Yasir KULA (yasirkula@gmail.com)
|
||||
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
using UnityEngine.SceneManagement;
|
||||
@@ -10,9 +8,10 @@ using System;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using Object = UnityEngine.Object;
|
||||
#if UNITY_2018_3_OR_NEWER && !UNITY_2021_2_OR_NEWER
|
||||
using PrefabStage = UnityEditor.Experimental.SceneManagement.PrefabStage;
|
||||
using PrefabStageUtility = UnityEditor.Experimental.SceneManagement.PrefabStageUtility;
|
||||
#if UNITY_6000_3_OR_NEWER
|
||||
using EntityId = UnityEngine.EntityId;
|
||||
#else
|
||||
using EntityId = System.Int32;
|
||||
#endif
|
||||
|
||||
namespace AssetUsageDetectorNamespace
|
||||
@@ -38,10 +37,7 @@ namespace AssetUsageDetectorNamespace
|
||||
public bool dontSearchInSourceAssets = true;
|
||||
public bool searchInProjectSettings = true;
|
||||
|
||||
public int searchDepthLimit = 4;
|
||||
public BindingFlags fieldModifiers = BindingFlags.Public | BindingFlags.NonPublic;
|
||||
public BindingFlags propertyModifiers = BindingFlags.Public | BindingFlags.NonPublic;
|
||||
public bool searchNonSerializableVariables = true;
|
||||
public int searchDepthLimit = 32;
|
||||
|
||||
public bool searchUnusedMaterialProperties = true;
|
||||
|
||||
@@ -53,8 +49,8 @@ namespace AssetUsageDetectorNamespace
|
||||
#endif
|
||||
public bool calculateUnusedObjects = false;
|
||||
public bool hideDuplicateRows = true;
|
||||
public bool hideNonOverriddenPrefabVariablesInAssets = true;
|
||||
public bool hideNonOverriddenPrefabVariablesInScenes = false;
|
||||
public bool hideRedundantPrefabReferencesInAssets = false;
|
||||
public bool hideRedundantPrefabReferencesInScenes = false;
|
||||
public bool noAssetDatabaseChanges = false;
|
||||
public bool showDetailedProgressBar = true;
|
||||
}
|
||||
@@ -82,24 +78,19 @@ namespace AssetUsageDetectorNamespace
|
||||
|
||||
// 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>( 4096 );
|
||||
private readonly Dictionary<int, ReferenceNode> searchedUnityObjects = new Dictionary<int, ReferenceNode>( 32768 ); // Unity objects use their instanceIDs as key which is more performant
|
||||
private readonly Dictionary<EntityId, ReferenceNode> searchedUnityObjects = new(32768); // Unity objects use their EntityIds as key
|
||||
|
||||
// Stack of SearchObject function parameters to avoid infinite loops (which happens when same object is passed as parameter to function)
|
||||
private readonly List<object> callStack = new List<object>( 64 );
|
||||
|
||||
private Object currentSearchedObject;
|
||||
private int currentDepth;
|
||||
|
||||
private bool searchingSourceAssets;
|
||||
private bool isInPlayMode;
|
||||
|
||||
#if UNITY_2018_3_OR_NEWER
|
||||
private PrefabStage openPrefabStage;
|
||||
private GameObject openPrefabStagePrefabAsset;
|
||||
#if UNITY_2020_1_OR_NEWER
|
||||
private GameObject openPrefabStageContextObject;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
private int searchedObjectsCount; // Number of searched objects
|
||||
private double searchStartTime;
|
||||
@@ -121,7 +112,6 @@ namespace AssetUsageDetectorNamespace
|
||||
return new SearchResult( false, null, null, null, this, searchParameters );
|
||||
}
|
||||
|
||||
#if UNITY_2018_3_OR_NEWER
|
||||
openPrefabStagePrefabAsset = null;
|
||||
string openPrefabStageAssetPath = null;
|
||||
openPrefabStage = PrefabStageUtility.GetCurrentPrefabStage();
|
||||
@@ -138,20 +128,12 @@ namespace AssetUsageDetectorNamespace
|
||||
return new SearchResult( false, null, null, null, this, searchParameters );
|
||||
}
|
||||
|
||||
#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;
|
||||
@@ -177,7 +159,6 @@ namespace AssetUsageDetectorNamespace
|
||||
searchResult = new List<SearchResultGroup>(); // Overall search results
|
||||
|
||||
currentSearchedObject = null;
|
||||
currentDepth = 0;
|
||||
searchedObjectsCount = 0;
|
||||
searchStartTime = EditorApplication.timeSinceStartup;
|
||||
|
||||
@@ -193,9 +174,7 @@ namespace AssetUsageDetectorNamespace
|
||||
excludedAssetsPathsSet.Clear();
|
||||
alwaysSearchedExtensionsSet.Clear();
|
||||
shaderIncludesToSearchSet.Clear();
|
||||
#if UNITY_2017_3_OR_NEWER
|
||||
assemblyDefinitionFilesToSearch.Clear();
|
||||
#endif
|
||||
|
||||
if( assetDependencyCache == null )
|
||||
{
|
||||
@@ -351,9 +330,9 @@ namespace AssetUsageDetectorNamespace
|
||||
// Initialize data used by search functions
|
||||
InitializeSearchFunctionsData( searchParameters );
|
||||
|
||||
// Initialize the nodes of searched asset(s)
|
||||
foreach( Object obj in objectsToSearchSet )
|
||||
searchedUnityObjects.Add( obj.GetInstanceID(), PopReferenceNode( obj ) );
|
||||
// Initialize the nodes of searched asset(s)
|
||||
foreach (Object obj in objectsToSearchSet)
|
||||
searchedUnityObjects.Add(obj.GetEntityId(), PopReferenceNode(obj));
|
||||
|
||||
// Progressbar values
|
||||
int searchProgress = 0;
|
||||
@@ -454,7 +433,7 @@ namespace AssetUsageDetectorNamespace
|
||||
}
|
||||
|
||||
// If a reference is found in the Project view, save the results
|
||||
if( currentSearchResultGroup.NumberOfReferences > 0 )
|
||||
if( currentSearchResultGroup.AnyReferencesFound )
|
||||
searchResult.Add( currentSearchResultGroup );
|
||||
}
|
||||
|
||||
@@ -479,14 +458,10 @@ namespace AssetUsageDetectorNamespace
|
||||
}
|
||||
}
|
||||
|
||||
if( currentSearchResultGroup.NumberOfReferences > 0 )
|
||||
if( currentSearchResultGroup.AnyReferencesFound )
|
||||
searchResult.Add( currentSearchResultGroup );
|
||||
}
|
||||
|
||||
// Search non-serializable variables for references while searching a scene in play mode
|
||||
if( isInPlayMode )
|
||||
searchSerializableVariablesOnly = false;
|
||||
|
||||
if( scenesToSearch.Count > 0 )
|
||||
{
|
||||
// Calculate the path(s) of the scenes that won't be searched for references
|
||||
@@ -527,7 +502,6 @@ namespace AssetUsageDetectorNamespace
|
||||
if( excludedScenesPathsSet.Contains( scenePath ) )
|
||||
continue;
|
||||
|
||||
#if UNITY_2019_2_OR_NEWER
|
||||
// Skip scenes in read-only packages (Issue #36)
|
||||
// Credit: https://forum.unity.com/threads/check-if-asset-inside-package-is-readonly.900902/#post-5990822
|
||||
if( !scenePath.StartsWithFast( "Assets/" ) )
|
||||
@@ -536,7 +510,6 @@ namespace AssetUsageDetectorNamespace
|
||||
if( packageInfo != null && packageInfo.source != UnityEditor.PackageManager.PackageSource.Embedded && packageInfo.source != UnityEditor.PackageManager.PackageSource.Local )
|
||||
continue;
|
||||
}
|
||||
#endif
|
||||
|
||||
SearchScene( scenePath, searchResult, searchParameters, initialSceneSetup );
|
||||
}
|
||||
@@ -554,7 +527,7 @@ namespace AssetUsageDetectorNamespace
|
||||
for( int i = 0; i < rootGameObjects.Length; i++ )
|
||||
SearchGameObjectRecursively( rootGameObjects[i] );
|
||||
|
||||
if( currentSearchResultGroup.NumberOfReferences > 0 )
|
||||
if( currentSearchResultGroup.AnyReferencesFound )
|
||||
searchResult.Add( currentSearchResultGroup );
|
||||
}
|
||||
|
||||
@@ -625,11 +598,9 @@ namespace AssetUsageDetectorNamespace
|
||||
if( EditorSceneManager.GetActiveScene() != activeScene )
|
||||
EditorSceneManager.SetActiveScene( activeScene );
|
||||
|
||||
#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 ) )
|
||||
{
|
||||
#if UNITY_2020_1_OR_NEWER
|
||||
bool shouldOpenPrefabStageWithoutContext = true;
|
||||
if( openPrefabStageContextObject != null && !openPrefabStageContextObject.Equals( null ) )
|
||||
{
|
||||
@@ -647,12 +618,8 @@ namespace AssetUsageDetectorNamespace
|
||||
}
|
||||
|
||||
if( shouldOpenPrefabStageWithoutContext )
|
||||
#endif
|
||||
{
|
||||
AssetDatabase.OpenAsset( AssetDatabase.LoadAssetAtPath<GameObject>( openPrefabStageAssetPath ) );
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
@@ -663,7 +630,7 @@ namespace AssetUsageDetectorNamespace
|
||||
searchResult[i].InitializeNodes( objectsToSearchSet );
|
||||
|
||||
// Remove empty search result groups
|
||||
if( !searchResult[i].PendingSearch && searchResult[i].NumberOfReferences == 0 )
|
||||
if( !searchResult[i].PendingSearch && !searchResult[i].AnyReferencesFound )
|
||||
searchResult.RemoveAt( i-- );
|
||||
}
|
||||
}
|
||||
@@ -689,8 +656,8 @@ namespace AssetUsageDetectorNamespace
|
||||
usedObjectPathsSet.Add( assetPath );
|
||||
else
|
||||
{
|
||||
for( Transform parent = ( (GameObject) obj ).transform.parent; parent != null; parent = parent.parent )
|
||||
usedObjectPathsSet.Add( parent.gameObject.GetInstanceID().ToString() );
|
||||
for (Transform parent = ((GameObject)obj).transform.parent; parent != null; parent = parent.parent)
|
||||
usedObjectPathsSet.Add(parent.gameObject.GetEntityId().ToString());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -761,14 +728,14 @@ namespace AssetUsageDetectorNamespace
|
||||
{
|
||||
if( !searchedTopmostGameObject )
|
||||
{
|
||||
if( obj is GameObject )
|
||||
unusedMainObjectNodes[obj.GetInstanceID().ToString()] = node;
|
||||
else
|
||||
currentSearchResultGroup.AddReference( node );
|
||||
if (obj is GameObject)
|
||||
unusedMainObjectNodes[obj.GetEntityId().ToString()] = node;
|
||||
else
|
||||
currentSearchResultGroup.AddReference(node);
|
||||
}
|
||||
else // List child GameObject scene objects under their parent GameObject
|
||||
{
|
||||
string dictionaryKey = searchedTopmostGameObject.GetInstanceID().ToString();
|
||||
string dictionaryKey = searchedTopmostGameObject.GetEntityId().ToString();
|
||||
List<ReferenceNode> unusedSubObjectNodesAtPath;
|
||||
if( !unusedSubObjectNodes.TryGetValue( dictionaryKey, out unusedSubObjectNodesAtPath ) )
|
||||
unusedSubObjectNodes[dictionaryKey] = unusedSubObjectNodesAtPath = new List<ReferenceNode>( 2 );
|
||||
@@ -837,7 +804,6 @@ namespace AssetUsageDetectorNamespace
|
||||
|
||||
objectsToSearchSet.Add( obj );
|
||||
|
||||
#if UNITY_2018_3_OR_NEWER
|
||||
// When searching for references of a prefab stage object, try adding its corresponding prefab asset to the searched assets, as well
|
||||
if( openPrefabStage != null && openPrefabStagePrefabAsset != null && obj is GameObject && openPrefabStage.IsPartOfPrefabContents( (GameObject) obj ) )
|
||||
{
|
||||
@@ -845,7 +811,6 @@ namespace AssetUsageDetectorNamespace
|
||||
if( prefabStageObjectSource != null )
|
||||
AddSearchedObjectToFilteredSets( prefabStageObjectSource, expandGameObjects );
|
||||
}
|
||||
#endif
|
||||
|
||||
bool isAsset = obj.IsAsset();
|
||||
if( isAsset )
|
||||
@@ -982,11 +947,9 @@ namespace AssetUsageDetectorNamespace
|
||||
EditorSceneManager.CloseScene( scene, true );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Some references are found in this scene, save the results
|
||||
|
||||
if( currentSearchResultGroup.AnyReferencesFound )
|
||||
searchResult.Add( currentSearchResultGroup );
|
||||
}
|
||||
}
|
||||
|
||||
// Search a GameObject and its children for references recursively
|
||||
@@ -1037,6 +1000,10 @@ namespace AssetUsageDetectorNamespace
|
||||
return cachedResult;
|
||||
}
|
||||
|
||||
// Comply with the recursive search limit
|
||||
if (callStack.Count >= searchParameters.searchDepthLimit)
|
||||
return null;
|
||||
|
||||
searchedObjectsCount++;
|
||||
|
||||
ReferenceNode result;
|
||||
@@ -1049,14 +1016,14 @@ namespace AssetUsageDetectorNamespace
|
||||
{
|
||||
if( assetsToSearchSet.Count == 0 )
|
||||
{
|
||||
searchedUnityObjects.Add( unityObject.GetInstanceID(), null );
|
||||
searchedUnityObjects.Add(unityObject.GetEntityId(), null);
|
||||
return null;
|
||||
}
|
||||
|
||||
assetPath = AssetDatabase.GetAssetPath( unityObject );
|
||||
if( excludedAssetsPathsSet.Contains( assetPath ) || !AssetHasAnyReference( assetPath ) )
|
||||
{
|
||||
searchedUnityObjects.Add( unityObject.GetInstanceID(), null );
|
||||
searchedUnityObjects.Add(unityObject.GetEntityId(), null);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -1098,17 +1065,11 @@ namespace AssetUsageDetectorNamespace
|
||||
}
|
||||
else
|
||||
{
|
||||
// Comply with the recursive search limit
|
||||
if( currentDepth >= searchParameters.searchDepthLimit )
|
||||
return null;
|
||||
|
||||
callStack.Add( obj );
|
||||
currentDepth++;
|
||||
|
||||
result = PopReferenceNode( obj );
|
||||
SearchVariablesWithReflection( result );
|
||||
|
||||
currentDepth--;
|
||||
callStack.RemoveAt( callStack.Count - 1 );
|
||||
}
|
||||
|
||||
@@ -1118,24 +1079,23 @@ namespace AssetUsageDetectorNamespace
|
||||
result = null;
|
||||
}
|
||||
|
||||
// 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( !( obj is ValueType ) && ( result != null || unityObject != null || currentDepth == 0 ) )
|
||||
{
|
||||
if( !searchingSourceAsset )
|
||||
{
|
||||
if( obj is Object )
|
||||
searchedUnityObjects.Add( unityObject.GetInstanceID(), result );
|
||||
else
|
||||
searchedObjects.Add( GetNodeObjectHash( obj ), result );
|
||||
}
|
||||
else if( result != null )
|
||||
{
|
||||
result.CopyReferencesTo( searchedUnityObjects[unityObject.GetInstanceID()] );
|
||||
PoolReferenceNode( result );
|
||||
}
|
||||
}
|
||||
// Cache the search result if we are skimming through a class (not a struct) 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. callStack.Count == 0)
|
||||
if (obj is not ValueType && (result != null || unityObject != null || callStack.Count == 0))
|
||||
{
|
||||
if (!searchingSourceAsset)
|
||||
{
|
||||
if (obj is Object)
|
||||
searchedUnityObjects.Add(unityObject.GetEntityId(), result);
|
||||
else
|
||||
searchedObjects.Add(GetNodeObjectHash(obj), result);
|
||||
}
|
||||
else if (result != null)
|
||||
{
|
||||
result.CopyReferencesTo(searchedUnityObjects[unityObject.GetEntityId()]);
|
||||
PoolReferenceNode(result);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
@@ -1261,46 +1221,46 @@ 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( ( (Object) nodeObject ).GetInstanceID(), out referenceNode ) )
|
||||
return true;
|
||||
}
|
||||
else if( searchedObjects.TryGetValue( GetNodeObjectHash( nodeObject ), out referenceNode ) )
|
||||
return true;
|
||||
// If object was already searched, return its ReferenceNode
|
||||
private bool TryGetReferenceNode(object nodeObject, out ReferenceNode referenceNode)
|
||||
{
|
||||
if (nodeObject is Object unityObject)
|
||||
{
|
||||
if (searchedUnityObjects.TryGetValue(unityObject.GetEntityId(), out referenceNode))
|
||||
return true;
|
||||
}
|
||||
else if (searchedObjects.TryGetValue(GetNodeObjectHash(nodeObject), out referenceNode))
|
||||
return true;
|
||||
|
||||
referenceNode = null;
|
||||
return false;
|
||||
}
|
||||
referenceNode = null;
|
||||
return false;
|
||||
}
|
||||
|
||||
// Get reference node for object
|
||||
private ReferenceNode GetReferenceNode( object nodeObject )
|
||||
{
|
||||
ReferenceNode result;
|
||||
if( nodeObject is Object )
|
||||
{
|
||||
int hash = ( (Object) nodeObject ).GetInstanceID();
|
||||
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;
|
||||
}
|
||||
}
|
||||
// Get reference node for object
|
||||
private ReferenceNode GetReferenceNode(object nodeObject)
|
||||
{
|
||||
ReferenceNode result;
|
||||
if (nodeObject is Object unityObject)
|
||||
{
|
||||
EntityId hash = unityObject.GetEntityId();
|
||||
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;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
// Fetch a reference node from pool
|
||||
private ReferenceNode PopReferenceNode( object nodeObject )
|
||||
|
||||
@@ -5,22 +5,18 @@ using System.IO;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
using UnityEditor;
|
||||
#if ASSET_USAGE_ADDRESSABLES
|
||||
using UnityEditor.AddressableAssets.Settings;
|
||||
#endif
|
||||
using UnityEditor.Animations;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
#if UNITY_2017_1_OR_NEWER
|
||||
using UnityEngine.U2D;
|
||||
using UnityEngine.Playables;
|
||||
#endif
|
||||
#if UNITY_2018_2_OR_NEWER
|
||||
using UnityEditor.U2D;
|
||||
#endif
|
||||
#if UNITY_2017_3_OR_NEWER
|
||||
using UnityEditor.Compilation;
|
||||
#endif
|
||||
#if UNITY_2017_2_OR_NEWER
|
||||
using UnityEngine.Rendering;
|
||||
using UnityEngine.Tilemaps;
|
||||
#endif
|
||||
#if ASSET_USAGE_ADDRESSABLES
|
||||
using UnityEngine.AddressableAssets;
|
||||
#endif
|
||||
@@ -31,19 +27,14 @@ namespace AssetUsageDetectorNamespace
|
||||
public partial class AssetUsageDetector
|
||||
{
|
||||
#region Helper Classes
|
||||
#if UNITY_2017_3_OR_NEWER
|
||||
#pragma warning disable 0649 // The fields' values are assigned via JsonUtility
|
||||
#pragma warning disable 0649
|
||||
[Serializable]
|
||||
private struct AssemblyDefinitionReferences
|
||||
{
|
||||
public string reference; // Used by AssemblyDefinitionReferenceAssets
|
||||
public List<string> references; // Used by AssemblyDefinitionAssets
|
||||
}
|
||||
#pragma warning restore 0649
|
||||
#endif
|
||||
|
||||
#if UNITY_2018_1_OR_NEWER
|
||||
#pragma warning disable 0649 // The fields' values are assigned via JsonUtility
|
||||
[Serializable]
|
||||
private struct ShaderGraphReferences // Used by old Shader Graph serialization format
|
||||
{
|
||||
@@ -157,7 +148,6 @@ namespace AssetUsageDetectorNamespace
|
||||
}
|
||||
}
|
||||
#pragma warning restore 0649
|
||||
#endif
|
||||
#endregion
|
||||
|
||||
// Dictionary to quickly find the function to search a specific type with
|
||||
@@ -176,10 +166,8 @@ namespace AssetUsageDetectorNamespace
|
||||
// Path(s) of .cginc, .cg, .hlsl and .glslinc assets in assetsToSearchSet
|
||||
private readonly HashSet<string> shaderIncludesToSearchSet = new HashSet<string>();
|
||||
|
||||
#if UNITY_2017_3_OR_NEWER
|
||||
// Path(s) of the Assembly Definition Files in objectsToSearchSet (Value: files themselves)
|
||||
private readonly Dictionary<string, Object> assemblyDefinitionFilesToSearch = new Dictionary<string, Object>( 8 );
|
||||
#endif
|
||||
|
||||
// An optimization to fetch an animation clip's curve bindings only once
|
||||
private readonly Dictionary<AnimationClip, EditorCurveBinding[]> animationClipUniqueBindings = new Dictionary<AnimationClip, EditorCurveBinding[]>( 256 );
|
||||
@@ -187,33 +175,20 @@ namespace AssetUsageDetectorNamespace
|
||||
private bool searchPrefabConnections;
|
||||
private bool searchMonoBehavioursForScript;
|
||||
private bool searchTextureReferences;
|
||||
#if UNITY_2018_1_OR_NEWER
|
||||
private bool searchShaderGraphsForSubGraphs;
|
||||
#endif
|
||||
|
||||
private bool searchSerializableVariablesOnly;
|
||||
private bool prevSearchSerializableVariablesOnly;
|
||||
|
||||
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 );
|
||||
#if UNITY_2019_3_OR_NEWER
|
||||
private readonly FieldInfoGetter fieldInfoGetter = (FieldInfoGetter) Delegate.CreateDelegate( typeof( FieldInfoGetter ), typeof( Editor ).Assembly.GetType( "UnityEditor.ScriptAttributeUtility" ).GetMethod( "GetFieldInfoAndStaticTypeFromProperty", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static ) );
|
||||
#else
|
||||
private readonly FieldInfoGetter fieldInfoGetter = (FieldInfoGetter) Delegate.CreateDelegate( typeof( FieldInfoGetter ), typeof( Editor ).Assembly.GetType( "UnityEditor.ScriptAttributeUtility" ).GetMethod( "GetFieldInfoFromProperty", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static ) );
|
||||
#endif
|
||||
|
||||
private readonly Func<Object> lightmapSettingsGetter = (Func<Object>) Delegate.CreateDelegate( typeof( Func<Object> ), typeof( LightmapEditorSettings ).GetMethod( "GetLightmapSettings", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static ) );
|
||||
private readonly Func<Object> renderSettingsGetter = (Func<Object>) Delegate.CreateDelegate( typeof( Func<Object> ), typeof( RenderSettings ).GetMethod( "GetRenderSettings", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static ) );
|
||||
#if UNITY_2021_2_OR_NEWER
|
||||
private readonly Func<Cubemap> defaultReflectionProbeGetter = (Func<Cubemap>) Delegate.CreateDelegate( typeof( Func<Cubemap> ), typeof( RenderSettings ).GetProperty( "defaultReflection", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static ).GetGetMethod( true ) );
|
||||
#endif
|
||||
|
||||
internal static readonly Func<SpriteAtlas, Sprite[]> spriteAtlasPackedSpritesGetter = (Func<SpriteAtlas, Sprite[]>) Delegate.CreateDelegate( typeof( Func<SpriteAtlas, Sprite[]> ), typeof( SpriteAtlasExtensions ).GetMethod( "GetPackedSprites", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static ) );
|
||||
#if ASSET_USAGE_ADDRESSABLES
|
||||
private readonly Func<SpriteAtlas, Sprite[]> spriteAtlasPackedSpritesGetter = (Func<SpriteAtlas, Sprite[]>) Delegate.CreateDelegate( typeof( Func<SpriteAtlas, Sprite[]> ), typeof( SpriteAtlasExtensions ).GetMethod( "GetPackedSprites", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static ) );
|
||||
private readonly PropertyInfo assetReferenceSubObjectTypeGetter = typeof( AssetReference ).GetProperty( "SubOjbectType", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance );
|
||||
private readonly PropertyInfo assetReferenceSubObjectTypeGetter =
|
||||
typeof( AssetReference ).GetProperty( "SubObjectType", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance )
|
||||
?? typeof( AssetReference ).GetProperty( "SubOjbectType", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance );
|
||||
#endif
|
||||
|
||||
#if ASSET_USAGE_VFX_GRAPH
|
||||
@@ -244,8 +219,9 @@ namespace AssetUsageDetectorNamespace
|
||||
{ typeof( TerrainData ), SearchTerrainData },
|
||||
{ typeof( LightmapSettings ), SearchLightmapSettings },
|
||||
{ typeof( RenderSettings ), SearchRenderSettings },
|
||||
#if UNITY_2017_1_OR_NEWER
|
||||
{ typeof( SpriteAtlas ), SearchSpriteAtlas },
|
||||
#if ASSET_USAGE_ADDRESSABLES
|
||||
{ typeof(AddressableAssetSettings), SearchAddressableAssetSettings },
|
||||
#endif
|
||||
};
|
||||
}
|
||||
@@ -259,16 +235,10 @@ namespace AssetUsageDetectorNamespace
|
||||
{ "cg", SearchShaderSecondaryAsset },
|
||||
{ "glslinc", SearchShaderSecondaryAsset },
|
||||
{ "hlsl", SearchShaderSecondaryAsset },
|
||||
#if UNITY_2017_3_OR_NEWER
|
||||
{ "asmdef", SearchAssemblyDefinitionFile },
|
||||
#endif
|
||||
#if UNITY_2019_2_OR_NEWER
|
||||
{ "asmref", SearchAssemblyDefinitionFile },
|
||||
#endif
|
||||
#if UNITY_2018_1_OR_NEWER
|
||||
{ "shadergraph", SearchShaderGraph },
|
||||
{ "shadersubgraph", SearchShaderGraph },
|
||||
#endif
|
||||
#if ASSET_USAGE_VFX_GRAPH
|
||||
{ "vfx", SearchVFXGraphAsset },
|
||||
{ "vfxoperator", SearchVFXGraphAsset },
|
||||
@@ -277,23 +247,10 @@ namespace AssetUsageDetectorNamespace
|
||||
};
|
||||
}
|
||||
|
||||
fieldModifiers = searchParameters.fieldModifiers | BindingFlags.Instance | BindingFlags.DeclaredOnly;
|
||||
propertyModifiers = searchParameters.propertyModifiers | BindingFlags.Instance | BindingFlags.DeclaredOnly;
|
||||
searchSerializableVariablesOnly = !searchParameters.searchNonSerializableVariables;
|
||||
|
||||
if( prevFieldModifiers != fieldModifiers || prevPropertyModifiers != propertyModifiers || prevSearchSerializableVariablesOnly != searchSerializableVariablesOnly )
|
||||
typeToVariables.Clear();
|
||||
|
||||
prevFieldModifiers = fieldModifiers;
|
||||
prevPropertyModifiers = propertyModifiers;
|
||||
prevSearchSerializableVariablesOnly = searchSerializableVariablesOnly;
|
||||
|
||||
searchPrefabConnections = false;
|
||||
searchMonoBehavioursForScript = false;
|
||||
searchTextureReferences = false;
|
||||
#if UNITY_2018_1_OR_NEWER
|
||||
searchShaderGraphsForSubGraphs = false;
|
||||
#endif
|
||||
#if ASSET_USAGE_VFX_GRAPH
|
||||
bool searchVFXGraphs = false;
|
||||
#endif
|
||||
@@ -315,10 +272,8 @@ namespace AssetUsageDetectorNamespace
|
||||
}
|
||||
else if( obj is GameObject )
|
||||
searchPrefabConnections = true;
|
||||
#if UNITY_2017_3_OR_NEWER
|
||||
else if( obj is UnityEditorInternal.AssemblyDefinitionAsset )
|
||||
assemblyDefinitionFilesToSearch[AssetDatabase.GetAssetPath( obj )] = obj;
|
||||
#endif
|
||||
#if ASSET_USAGE_VFX_GRAPH
|
||||
else if( !searchVFXGraphs && ( obj is Shader || obj is Mesh || obj.GetType().Name.StartsWithFast( "PointCache" ) || obj.GetType().Name == "ShaderGraphVfxAsset" ) )
|
||||
searchVFXGraphs = true;
|
||||
@@ -337,10 +292,8 @@ namespace AssetUsageDetectorNamespace
|
||||
string extension = Utilities.GetFileExtension( path );
|
||||
if( extension == "hlsl" || extension == "cginc" || extension == "cg" || extension == "glslinc" )
|
||||
shaderIncludesToSearchSet.Add( path );
|
||||
#if UNITY_2018_1_OR_NEWER
|
||||
else if( extension == "shadersubgraph" )
|
||||
searchShaderGraphsForSubGraphs = true;
|
||||
#endif
|
||||
}
|
||||
|
||||
// AssetDatabase.GetDependencies doesn't take #include lines in shader source codes into consideration. If we are searching for references
|
||||
@@ -355,19 +308,14 @@ namespace AssetUsageDetectorNamespace
|
||||
alwaysSearchedExtensionsSet.Add( "hlsl" );
|
||||
}
|
||||
|
||||
#if UNITY_2017_3_OR_NEWER
|
||||
// AssetDatabase.GetDependencies doesn't return references from Assembly Definition Files to their Assembly Definition References,
|
||||
// so if we are searching for an Assembly Definition File's usages, we must search all Assembly Definition Files' references manually.
|
||||
if( assemblyDefinitionFilesToSearch.Count > 0 )
|
||||
{
|
||||
alwaysSearchedExtensionsSet.Add( "asmdef" );
|
||||
#if UNITY_2019_2_OR_NEWER
|
||||
alwaysSearchedExtensionsSet.Add( "asmref" );
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
#if UNITY_2018_1_OR_NEWER
|
||||
// AssetDatabase.GetDependencies doesn't work with Shader Graph assets. We must search all Shader Graph assets in the following cases:
|
||||
// searchTextureReferences: to find Texture references used in various nodes and properties
|
||||
// searchShaderGraphsForSubGraphs: to find Shader Sub-graph references in other Shader Graph assets
|
||||
@@ -377,7 +325,6 @@ namespace AssetUsageDetectorNamespace
|
||||
alwaysSearchedExtensionsSet.Add( "shadergraph" );
|
||||
alwaysSearchedExtensionsSet.Add( "shadersubgraph" );
|
||||
}
|
||||
#endif
|
||||
|
||||
#if ASSET_USAGE_VFX_GRAPH
|
||||
if( searchTextureReferences || searchVFXGraphs )
|
||||
@@ -397,16 +344,21 @@ namespace AssetUsageDetectorNamespace
|
||||
// Check if this GameObject's prefab is one of the selected assets
|
||||
if( searchPrefabConnections )
|
||||
{
|
||||
#if UNITY_2018_3_OR_NEWER
|
||||
Object prefab = go;
|
||||
while( prefab = PrefabUtility.GetCorrespondingObjectFromSource( prefab ) )
|
||||
#else
|
||||
Object prefab = PrefabUtility.GetPrefabParent( go );
|
||||
if( prefab )
|
||||
#endif
|
||||
bool? skipFurtherPrefabReferences = null;
|
||||
for( GameObject goPrefab = go.GetPrefabParent(), prefab = goPrefab; prefab != null; prefab = prefab.GetPrefabParent() )
|
||||
{
|
||||
if( objectsToSearchSet.Contains( prefab ) && assetsToSearchRootPrefabs.ContainsFast( prefab as GameObject ) )
|
||||
if( objectsToSearchSet.Contains( prefab ) && assetsToSearchRootPrefabs.ContainsFast( prefab ) )
|
||||
{
|
||||
if( goPrefab != prefab && !skipFurtherPrefabReferences.HasValue )
|
||||
{
|
||||
skipFurtherPrefabReferences = ShouldExcludeRedundantPrefabReferences( go ) && !go.HasAnyPrefabOverrides();
|
||||
if( skipFurtherPrefabReferences.Value )
|
||||
{
|
||||
currentSearchResultGroup.NumberOfRedundantReferences++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
referenceNode.AddLinkTo( GetReferenceNode( prefab ), "Prefab object" );
|
||||
|
||||
if( searchParameters.searchRefactoring != null )
|
||||
@@ -440,10 +392,15 @@ namespace AssetUsageDetectorNamespace
|
||||
MonoScript script = MonoScript.FromMonoBehaviour( (MonoBehaviour) component );
|
||||
if( objectsToSearchSet.Contains( script ) )
|
||||
{
|
||||
referenceNode.AddLinkTo( GetReferenceNode( script ) );
|
||||
if( ShouldExcludeRedundantPrefabReferences( component ) && !component.HasAnyPrefabOverrides() )
|
||||
currentSearchResultGroup.NumberOfRedundantReferences++;
|
||||
else
|
||||
{
|
||||
referenceNode.AddLinkTo( GetReferenceNode( script ) );
|
||||
|
||||
if( searchParameters.searchRefactoring != null )
|
||||
searchParameters.searchRefactoring( new BehaviourUsageMatch( component.gameObject, script, component ) );
|
||||
if( searchParameters.searchRefactoring != null )
|
||||
searchParameters.searchRefactoring( new BehaviourUsageMatch( component.gameObject, script, component ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -492,7 +449,6 @@ namespace AssetUsageDetectorNamespace
|
||||
// Search the objects that are animated by this Animator component for references
|
||||
SearchAnimatedObjects( referenceNode );
|
||||
}
|
||||
#if UNITY_2017_2_OR_NEWER
|
||||
else if( component is Tilemap )
|
||||
{
|
||||
// Search the tiles for references
|
||||
@@ -510,8 +466,6 @@ namespace AssetUsageDetectorNamespace
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#if UNITY_2017_1_OR_NEWER
|
||||
else if( component is PlayableDirector )
|
||||
{
|
||||
// Search the PlayableAsset's scene bindings for references
|
||||
@@ -528,7 +482,6 @@ namespace AssetUsageDetectorNamespace
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
else if( component is ParticleSystemRenderer )
|
||||
{
|
||||
// Search ParticleSystemRenderer's custom meshes for references (at runtime, they can't be searched with reflection, unfortunately)
|
||||
@@ -565,11 +518,7 @@ namespace AssetUsageDetectorNamespace
|
||||
try
|
||||
{
|
||||
ParticleSystem.CollisionModule collisionModule = particleSystem.collision;
|
||||
#if UNITY_2020_2_OR_NEWER
|
||||
for( int i = 0, j = collisionModule.planeCount; i < j; i++ )
|
||||
#else
|
||||
for( int i = 0, j = collisionModule.maxPlaneCount; i < j; i++ )
|
||||
#endif
|
||||
{
|
||||
Transform plane = collisionModule.GetPlane( i );
|
||||
referenceNode.AddLinkTo( SearchObject( plane ), "Collision Module: Plane" );
|
||||
@@ -583,11 +532,7 @@ namespace AssetUsageDetectorNamespace
|
||||
try
|
||||
{
|
||||
ParticleSystem.TriggerModule triggerModule = particleSystem.trigger;
|
||||
#if UNITY_2020_2_OR_NEWER
|
||||
for( int i = 0, j = triggerModule.colliderCount; i < j; i++ )
|
||||
#else
|
||||
for( int i = 0, j = triggerModule.maxColliderCount; i < j; i++ )
|
||||
#endif
|
||||
{
|
||||
Component collider = triggerModule.GetCollider( i );
|
||||
referenceNode.AddLinkTo( SearchObject( collider ), "Trigger Module: Collider" );
|
||||
@@ -598,7 +543,6 @@ namespace AssetUsageDetectorNamespace
|
||||
}
|
||||
catch { }
|
||||
|
||||
#if UNITY_2017_1_OR_NEWER
|
||||
try
|
||||
{
|
||||
ParticleSystem.TextureSheetAnimationModule textureSheetAnimationModule = particleSystem.textureSheetAnimation;
|
||||
@@ -612,9 +556,7 @@ namespace AssetUsageDetectorNamespace
|
||||
}
|
||||
}
|
||||
catch { }
|
||||
#endif
|
||||
|
||||
#if UNITY_5_5_OR_NEWER
|
||||
try
|
||||
{
|
||||
ParticleSystem.SubEmittersModule subEmittersModule = particleSystem.subEmitters;
|
||||
@@ -628,7 +570,6 @@ namespace AssetUsageDetectorNamespace
|
||||
}
|
||||
}
|
||||
catch { }
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
@@ -693,12 +634,12 @@ namespace AssetUsageDetectorNamespace
|
||||
if( searchTextureReferences && isInPlayMode && !AssetDatabase.Contains( material ) )
|
||||
{
|
||||
Shader shader = material.shader;
|
||||
int shaderPropertyCount = ShaderUtil.GetPropertyCount( shader );
|
||||
int shaderPropertyCount = shader.GetPropertyCount();
|
||||
for( int i = 0; i < shaderPropertyCount; i++ )
|
||||
{
|
||||
if( ShaderUtil.GetPropertyType( shader, i ) == ShaderUtil.ShaderPropertyType.TexEnv )
|
||||
if (shader.GetPropertyType(i) == ShaderPropertyType.Texture)
|
||||
{
|
||||
string propertyName = ShaderUtil.GetPropertyName( shader, i );
|
||||
string propertyName = shader.GetPropertyName(i);
|
||||
Texture assignedTexture = material.GetTexture( propertyName );
|
||||
if( objectsToSearchSet.Contains( assignedTexture ) )
|
||||
{
|
||||
@@ -725,17 +666,15 @@ namespace AssetUsageDetectorNamespace
|
||||
ShaderImporter shaderImporter = AssetImporter.GetAtPath( AssetDatabase.GetAssetPath( shader ) ) as ShaderImporter;
|
||||
if( shaderImporter != null )
|
||||
{
|
||||
int shaderPropertyCount = ShaderUtil.GetPropertyCount( shader );
|
||||
int shaderPropertyCount = shader.GetPropertyCount();
|
||||
for( int i = 0; i < shaderPropertyCount; i++ )
|
||||
{
|
||||
if( ShaderUtil.GetPropertyType( shader, i ) == ShaderUtil.ShaderPropertyType.TexEnv )
|
||||
if (shader.GetPropertyType(i) == ShaderPropertyType.Texture)
|
||||
{
|
||||
string propertyName = ShaderUtil.GetPropertyName( shader, i );
|
||||
string propertyName = shader.GetPropertyName(i);
|
||||
Texture defaultTexture = shaderImporter.GetDefaultTexture( propertyName );
|
||||
#if UNITY_2018_1_OR_NEWER
|
||||
if( !defaultTexture )
|
||||
defaultTexture = shaderImporter.GetNonModifiableTexture( propertyName );
|
||||
#endif
|
||||
|
||||
if( objectsToSearchSet.Contains( defaultTexture ) )
|
||||
{
|
||||
@@ -790,7 +729,7 @@ namespace AssetUsageDetectorNamespace
|
||||
VariableGetterHolder[] variables = GetFilteredVariablesForType( scriptType );
|
||||
for( int i = 0; i < variables.Length; i++ )
|
||||
{
|
||||
if( variables[i].isSerializable && !variables[i].IsProperty )
|
||||
if (!variables[i].IsProperty)
|
||||
{
|
||||
Object defaultValue = scriptImporter.GetDefaultReference( variables[i].Name );
|
||||
if( objectsToSearchSet.Contains( defaultValue ) )
|
||||
@@ -1037,16 +976,11 @@ namespace AssetUsageDetectorNamespace
|
||||
{
|
||||
ReferenceNode referenceNode = PopReferenceNode( obj );
|
||||
|
||||
#if UNITY_2021_2_OR_NEWER
|
||||
referenceNode.AddLinkTo( SearchObject( defaultReflectionProbeGetter() ), "Default Reflection Probe" );
|
||||
#else
|
||||
referenceNode.AddLinkTo( SearchObject( ReflectionProbe.defaultTexture ), "Default Reflection Probe" );
|
||||
#endif
|
||||
SearchVariablesWithSerializedObject( referenceNode, true );
|
||||
return referenceNode;
|
||||
}
|
||||
|
||||
#if UNITY_2017_1_OR_NEWER
|
||||
private ReferenceNode SearchSpriteAtlas( object obj )
|
||||
{
|
||||
SpriteAtlas spriteAtlas = (SpriteAtlas) obj;
|
||||
@@ -1079,7 +1013,6 @@ namespace AssetUsageDetectorNamespace
|
||||
searchParameters.searchRefactoring( new SerializedPropertyMatch( spriteAtlas, packedSprite, packedSpriteProperty ) );
|
||||
}
|
||||
}
|
||||
#if UNITY_2018_2_OR_NEWER
|
||||
else
|
||||
{
|
||||
Object[] _packables = spriteAtlas.GetPackables();
|
||||
@@ -1089,7 +1022,6 @@ namespace AssetUsageDetectorNamespace
|
||||
SearchSpriteAtlas( referenceNode, _packables[i] );
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
return referenceNode;
|
||||
}
|
||||
@@ -1135,9 +1067,30 @@ namespace AssetUsageDetectorNamespace
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#if ASSET_USAGE_ADDRESSABLES
|
||||
private ReferenceNode SearchAddressableAssetSettings(object obj)
|
||||
{
|
||||
AddressableAssetSettings addressableSettings = (AddressableAssetSettings)obj;
|
||||
ReferenceNode referenceNode = PopReferenceNode(addressableSettings);
|
||||
|
||||
// Search Addressable groups
|
||||
foreach (Object asset in assetsToSearchSet)
|
||||
{
|
||||
// Don't check redundant prefab objects
|
||||
if (asset is Component)
|
||||
continue;
|
||||
if (asset is GameObject gameObject && gameObject.transform.parent != null)
|
||||
continue;
|
||||
|
||||
if (AssetDatabase.TryGetGUIDAndLocalFileIdentifier(asset, out string guid, out long _) && addressableSettings.FindAssetEntry(guid, true) is AddressableAssetEntry addressableEntry)
|
||||
referenceNode.AddLinkTo(GetReferenceNode(asset), $"Addressable: \"{addressableEntry.parentGroup.Name}\" -> \"{addressableEntry.address}\"");
|
||||
}
|
||||
|
||||
return referenceNode;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if UNITY_2017_3_OR_NEWER
|
||||
// Find references from an Assembly Definition File to its Assembly Definition References
|
||||
private ReferenceNode SearchAssemblyDefinitionFile( object obj )
|
||||
{
|
||||
@@ -1159,11 +1112,7 @@ namespace AssetUsageDetectorNamespace
|
||||
{
|
||||
for( int i = 0; i < assemblyDefinitionFile.references.Count; i++ )
|
||||
{
|
||||
#if UNITY_2019_1_OR_NEWER
|
||||
string assemblyPath = CompilationPipeline.GetAssemblyDefinitionFilePathFromAssemblyReference( assemblyDefinitionFile.references[i] );
|
||||
#else
|
||||
string assemblyPath = CompilationPipeline.GetAssemblyDefinitionFilePathFromAssemblyName( assemblyDefinitionFile.references[i] );
|
||||
#endif
|
||||
if( !string.IsNullOrEmpty( assemblyPath ) )
|
||||
{
|
||||
Object searchedAssemblyDefinitionFile;
|
||||
@@ -1175,9 +1124,7 @@ namespace AssetUsageDetectorNamespace
|
||||
|
||||
return referenceNode;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if UNITY_2018_1_OR_NEWER
|
||||
// Searches Shader Graph assets for references
|
||||
private ReferenceNode SearchShaderGraph( object obj )
|
||||
{
|
||||
@@ -1306,7 +1253,6 @@ namespace AssetUsageDetectorNamespace
|
||||
|
||||
return referenceNode;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if ASSET_USAGE_VFX_GRAPH
|
||||
private ReferenceNode SearchVFXGraphAsset( object obj )
|
||||
@@ -1452,9 +1398,8 @@ namespace AssetUsageDetectorNamespace
|
||||
if( iterator.Next( true ) )
|
||||
{
|
||||
bool iteratingVisible = iteratorVisible.NextVisible( true );
|
||||
#if UNITY_2018_3_OR_NEWER
|
||||
bool searchPrefabOverridesOnly = ( ( searchParameters.hideNonOverriddenPrefabVariablesInAssets && unityObject.IsAsset() ) || ( searchParameters.hideNonOverriddenPrefabVariablesInScenes && !unityObject.IsAsset() ) ) && PrefabUtility.GetCorrespondingObjectFromSource( unityObject ) != null;
|
||||
#endif
|
||||
bool searchPrefabOverridesOnly = ShouldExcludeRedundantPrefabReferences( unityObject );
|
||||
GameObject unityObjectPrefabInstanceRoot = searchPrefabOverridesOnly ? PrefabUtility.GetOutermostPrefabInstanceRoot(unityObject) : null;
|
||||
bool enterChildren;
|
||||
do
|
||||
{
|
||||
@@ -1471,10 +1416,6 @@ namespace AssetUsageDetectorNamespace
|
||||
|
||||
if( !isVisible )
|
||||
enterChildren = false;
|
||||
#if UNITY_2018_3_OR_NEWER
|
||||
else if( searchPrefabOverridesOnly && !iterator.prefabOverride )
|
||||
enterChildren = false;
|
||||
#endif
|
||||
else
|
||||
{
|
||||
Object propertyValue;
|
||||
@@ -1491,15 +1432,14 @@ namespace AssetUsageDetectorNamespace
|
||||
searchResult = SearchObject( PreferablyGameObject( propertyValue ) );
|
||||
enterChildren = false;
|
||||
break;
|
||||
#if UNITY_2019_3_OR_NEWER
|
||||
case SerializedPropertyType.ManagedReference:
|
||||
object managedReferenceValue = GetRawSerializedPropertyValue( iterator );
|
||||
propertyValue = managedReferenceValue as Object;
|
||||
searchResult = SearchObject( PreferablyGameObject( managedReferenceValue ) );
|
||||
enterChildren = false;
|
||||
break;
|
||||
#endif
|
||||
case SerializedPropertyType.Generic:
|
||||
{
|
||||
#if ASSET_USAGE_ADDRESSABLES
|
||||
if( searchParameters.addressablesSupport && iterator.type.StartsWithFast( "AssetReference" ) && GetRawSerializedPropertyValue( iterator ) is AssetReference assetReference )
|
||||
{
|
||||
@@ -1526,6 +1466,7 @@ namespace AssetUsageDetectorNamespace
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
default:
|
||||
propertyValue = null;
|
||||
searchResult = null;
|
||||
@@ -1540,10 +1481,34 @@ 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.Replace( ".Array.data[", "[" ) ); // "arrayVariable.Array.data[0]" becomes "arrayVariable[0]"
|
||||
if (searchPrefabOverridesOnly && !iterator.prefabOverride && ObjectBelongsToDifferentPrefabInstance(propertyValue, unityObjectPrefabInstanceRoot))
|
||||
{
|
||||
currentSearchResultGroup.NumberOfRedundantReferences++;
|
||||
enterChildren = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
referenceNode.AddLinkTo( searchResult, "Variable: " + propertyPath.Replace( ".Array.data[", "[" ) ); // "arrayVariable.Array.data[0]" becomes "arrayVariable[0]"
|
||||
|
||||
if( searchParameters.searchRefactoring != null && objectsToSearchSet.Contains( propertyValue ) )
|
||||
searchParameters.searchRefactoring( new SerializedPropertyMatch( unityObject, propertyValue, iterator ) );
|
||||
if( searchParameters.searchRefactoring != null && objectsToSearchSet.Contains( propertyValue ) )
|
||||
searchParameters.searchRefactoring( new SerializedPropertyMatch( unityObject, propertyValue, iterator ) );
|
||||
}
|
||||
|
||||
/// Searching for references of a prefab instance's child object in either a scene or prefab mode should show the references coming from
|
||||
/// that prefab instance to the child object. That's because even though <see cref="SerializedProperty.prefabOverride"/> returns
|
||||
/// false for the variable that points to the child GameObject, that child GameObject is essentially different than its counterpart
|
||||
/// in the prefab asset (it's an instance/clone of it after all). So no references will be reported unless we intervene.
|
||||
bool ObjectBelongsToDifferentPrefabInstance(Object obj, GameObject prefabInstanceRoot)
|
||||
{
|
||||
if (obj == null)
|
||||
return true;
|
||||
|
||||
GameObject objPrefabInstanceRoot = PrefabUtility.GetOutermostPrefabInstanceRoot(obj);
|
||||
if (objPrefabInstanceRoot == null)
|
||||
return true;
|
||||
|
||||
return objPrefabInstanceRoot != prefabInstanceRoot;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1567,10 +1532,6 @@ namespace AssetUsageDetectorNamespace
|
||||
VariableGetterHolder[] variables = GetFilteredVariablesForType( referenceNode.nodeObject.GetType() );
|
||||
for( int i = 0; i < variables.Length; i++ )
|
||||
{
|
||||
// When possible, don't search non-serializable variables
|
||||
if( searchSerializableVariablesOnly && !variables[i].isSerializable )
|
||||
continue;
|
||||
|
||||
try
|
||||
{
|
||||
object variableValue = variables[i].Get( referenceNode.nodeObject );
|
||||
@@ -1668,135 +1629,107 @@ namespace AssetUsageDetectorNamespace
|
||||
|
||||
validVariables.Clear();
|
||||
|
||||
// Filter the fields
|
||||
if( fieldModifiers != ( BindingFlags.Instance | BindingFlags.DeclaredOnly ) )
|
||||
Type currType = type;
|
||||
while( currType != typeof( object ) )
|
||||
{
|
||||
Type currType = type;
|
||||
while( currType != typeof( object ) )
|
||||
foreach (FieldInfo field in currType.GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly))
|
||||
{
|
||||
FieldInfo[] fields = currType.GetFields( fieldModifiers );
|
||||
for( int i = 0; i < fields.Length; i++ )
|
||||
{
|
||||
FieldInfo field = fields[i];
|
||||
// Skip obsolete fields
|
||||
if( Attribute.IsDefined( field, typeof( ObsoleteAttribute ) ) )
|
||||
continue;
|
||||
|
||||
// Skip obsolete fields
|
||||
if( Attribute.IsDefined( field, typeof( ObsoleteAttribute ) ) )
|
||||
continue;
|
||||
// Skip primitive types
|
||||
if( field.FieldType.IsIgnoredUnityType() )
|
||||
continue;
|
||||
|
||||
// Skip primitive types
|
||||
if( field.FieldType.IsIgnoredUnityType() )
|
||||
continue;
|
||||
// "ref struct"s can't be accessed via reflection
|
||||
if( field.FieldType.IsByRefLike )
|
||||
continue;
|
||||
|
||||
#if UNITY_2021_2_OR_NEWER
|
||||
// "ref struct"s can't be accessed via reflection
|
||||
if( field.FieldType.IsByRefLike )
|
||||
continue;
|
||||
#endif
|
||||
// Additional filtering for fields:
|
||||
// 1- Ignore "m_RectTransform", "m_CanvasRenderer" and "m_Canvas" fields of Graphic components
|
||||
string fieldName = field.Name;
|
||||
if( typeof( Graphic ).IsAssignableFrom( currType ) &&
|
||||
( fieldName == "m_RectTransform" || fieldName == "m_CanvasRenderer" || fieldName == "m_Canvas" ) )
|
||||
continue;
|
||||
|
||||
// Additional filtering for fields:
|
||||
// 1- Ignore "m_RectTransform", "m_CanvasRenderer" and "m_Canvas" fields of Graphic components
|
||||
string fieldName = field.Name;
|
||||
if( typeof( Graphic ).IsAssignableFrom( currType ) &&
|
||||
( fieldName == "m_RectTransform" || fieldName == "m_CanvasRenderer" || fieldName == "m_Canvas" ) )
|
||||
continue;
|
||||
|
||||
VariableGetVal getter = field.CreateGetter( type );
|
||||
if( getter != null )
|
||||
validVariables.Add( new VariableGetterHolder( field, getter, searchSerializableVariablesOnly ? field.IsSerializable() : true ) );
|
||||
}
|
||||
|
||||
currType = currType.BaseType;
|
||||
VariableGetVal getter = field.CreateGetter( type );
|
||||
if (getter != null)
|
||||
validVariables.Add(new VariableGetterHolder(field, getter));
|
||||
}
|
||||
}
|
||||
|
||||
if( propertyModifiers != ( BindingFlags.Instance | BindingFlags.DeclaredOnly ) )
|
||||
{
|
||||
Type currType = type;
|
||||
while( currType != typeof( object ) )
|
||||
foreach (PropertyInfo property in currType.GetProperties(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly))
|
||||
{
|
||||
PropertyInfo[] properties = currType.GetProperties( propertyModifiers );
|
||||
for( int i = 0; i < properties.Length; i++ )
|
||||
// Skip obsolete properties
|
||||
if( Attribute.IsDefined( property, typeof( ObsoleteAttribute ) ) )
|
||||
continue;
|
||||
|
||||
// Skip primitive types
|
||||
if( property.PropertyType.IsIgnoredUnityType() )
|
||||
continue;
|
||||
|
||||
// "ref struct"s can't be accessed via reflection
|
||||
if( property.PropertyType.IsByRefLike )
|
||||
continue;
|
||||
|
||||
// Skip properties without a getter function
|
||||
MethodInfo propertyGetter = property.GetGetMethod( true );
|
||||
if( propertyGetter == null )
|
||||
continue;
|
||||
|
||||
// Skip indexer properties
|
||||
if( property.GetIndexParameters().Length > 0 )
|
||||
continue;
|
||||
|
||||
// No need to check properties with 'override' keyword
|
||||
if( propertyGetter.GetBaseDefinition().DeclaringType != propertyGetter.DeclaringType )
|
||||
continue;
|
||||
|
||||
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;
|
||||
// Same as above
|
||||
else if( ( propertyName == "material" || propertyName == "materials" ) &&
|
||||
( typeof( Renderer ).IsAssignableFrom( currType ) || typeof( Collider ).IsAssignableFrom( currType ) ||
|
||||
typeof( Collider2D ).IsAssignableFrom( currType ) ) )
|
||||
continue;
|
||||
// Ignore certain Material properties that are already searched via SearchMaterial function (also, if a material doesn't have a _Color or _BaseColor
|
||||
// property and its "color" property is called, it logs an error to the console, so this rule helps avoid that scenario, as well)
|
||||
else if( ( propertyName == "color" || propertyName == "mainTexture" ) && typeof( Material ).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;
|
||||
// Ignore "users" property of TerrainData because it returns the Terrains in the scene that use that TerrainData. This causes issues with callStack because TerrainData
|
||||
// is already in callStack when Terrains are searched via "users" property of it and hence, Terrain->TerrainData references for that TerrainData can't be found in scenes
|
||||
// (this is how callStack works, it prevents searching an object if it's already in callStack to avoid infinite recursion)
|
||||
else if( propertyName == "users" && typeof( TerrainData ).IsAssignableFrom( currType ) )
|
||||
continue;
|
||||
else
|
||||
{
|
||||
PropertyInfo property = properties[i];
|
||||
|
||||
// Skip obsolete properties
|
||||
if( Attribute.IsDefined( property, typeof( ObsoleteAttribute ) ) )
|
||||
continue;
|
||||
|
||||
// Skip primitive types
|
||||
if( property.PropertyType.IsIgnoredUnityType() )
|
||||
continue;
|
||||
|
||||
#if UNITY_2021_2_OR_NEWER
|
||||
// "ref struct"s can't be accessed via reflection
|
||||
if( property.PropertyType.IsByRefLike )
|
||||
continue;
|
||||
#endif
|
||||
|
||||
// Skip properties without a getter function
|
||||
MethodInfo propertyGetter = property.GetGetMethod( true );
|
||||
if( propertyGetter == null )
|
||||
continue;
|
||||
|
||||
// Skip indexer properties
|
||||
if( property.GetIndexParameters().Length > 0 )
|
||||
continue;
|
||||
|
||||
// No need to check properties with 'override' keyword
|
||||
if( propertyGetter.GetBaseDefinition().DeclaringType != propertyGetter.DeclaringType )
|
||||
continue;
|
||||
|
||||
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;
|
||||
// Same as above
|
||||
else if( ( propertyName == "material" || propertyName == "materials" ) &&
|
||||
( typeof( Renderer ).IsAssignableFrom( currType ) || typeof( Collider ).IsAssignableFrom( currType ) ||
|
||||
#if !UNITY_2019_3_OR_NEWER
|
||||
#pragma warning disable 0618
|
||||
typeof( GUIText ).IsAssignableFrom( currType ) ||
|
||||
#pragma warning restore 0618
|
||||
#endif
|
||||
typeof( Collider2D ).IsAssignableFrom( currType ) ) )
|
||||
continue;
|
||||
// Ignore certain Material properties that are already searched via SearchMaterial function (also, if a material doesn't have a _Color or _BaseColor
|
||||
// property and its "color" property is called, it logs an error to the console, so this rule helps avoid that scenario, as well)
|
||||
else if( ( propertyName == "color" || propertyName == "mainTexture" ) && typeof( Material ).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;
|
||||
// Ignore "users" property of TerrainData because it returns the Terrains in the scene that use that TerrainData. This causes issues with callStack because TerrainData
|
||||
// is already in callStack when Terrains are searched via "users" property of it and hence, Terrain->TerrainData references for that TerrainData can't be found in scenes
|
||||
// (this is how callStack works, it prevents searching an object if it's already in callStack to avoid infinite recursion)
|
||||
else if( propertyName == "users" && typeof( TerrainData ).IsAssignableFrom( currType ) )
|
||||
continue;
|
||||
else
|
||||
{
|
||||
VariableGetVal getter = property.CreateGetter();
|
||||
if( getter != null )
|
||||
validVariables.Add( new VariableGetterHolder( property, getter, searchSerializableVariablesOnly ? property.IsSerializable() : true ) );
|
||||
}
|
||||
VariableGetVal getter = property.CreateGetter();
|
||||
if (getter != null)
|
||||
validVariables.Add(new VariableGetterHolder(property, getter));
|
||||
}
|
||||
|
||||
currType = currType.BaseType;
|
||||
}
|
||||
|
||||
currType = currType.BaseType;
|
||||
}
|
||||
|
||||
result = validVariables.ToArray();
|
||||
@@ -1922,6 +1855,11 @@ namespace AssetUsageDetectorNamespace
|
||||
}
|
||||
#endif
|
||||
|
||||
private bool ShouldExcludeRedundantPrefabReferences( Object obj )
|
||||
{
|
||||
return ( ( searchParameters.hideRedundantPrefabReferencesInAssets && obj.IsAsset() ) || ( searchParameters.hideRedundantPrefabReferencesInScenes && !obj.IsAsset() ) ) && obj.GetPrefabParent() != null;
|
||||
}
|
||||
|
||||
// Iterates over all occurrences of specific key-value pairs in string
|
||||
// Example1: #include "VALUE" valuePrefix=#include, valueWrapperChar="
|
||||
// Example2: "guid": "VALUE" valuePrefix="guid", valueWrapperChar="
|
||||
|
||||
@@ -167,7 +167,6 @@ namespace AssetUsageDetectorNamespace
|
||||
}
|
||||
#endregion
|
||||
|
||||
#if UNITY_2018_3_OR_NEWER
|
||||
[SettingsProvider]
|
||||
public static SettingsProvider CreatePreferencesGUI()
|
||||
{
|
||||
@@ -177,19 +176,11 @@ namespace AssetUsageDetectorNamespace
|
||||
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;
|
||||
#if UNITY_2018_3_OR_NEWER
|
||||
EditorGUIUtility.labelWidth += 60f;
|
||||
#else
|
||||
EditorGUIUtility.labelWidth += 20f;
|
||||
#endif
|
||||
|
||||
EditorGUI.BeginChangeCheck();
|
||||
|
||||
|
||||
@@ -1,17 +1,9 @@
|
||||
// Asset Usage Detector - by Suleyman Yasir KULA (yasirkula@gmail.com)
|
||||
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
using UnityEditor.SceneManagement;
|
||||
using System.Collections.Generic;
|
||||
using System.Reflection;
|
||||
using Object = UnityEngine.Object;
|
||||
#if UNITY_2021_2_OR_NEWER
|
||||
using PrefabStage = UnityEditor.SceneManagement.PrefabStage;
|
||||
using PrefabStageUtility = UnityEditor.SceneManagement.PrefabStageUtility;
|
||||
#elif UNITY_2018_3_OR_NEWER
|
||||
using PrefabStage = UnityEditor.Experimental.SceneManagement.PrefabStage;
|
||||
using PrefabStageUtility = UnityEditor.Experimental.SceneManagement.PrefabStageUtility;
|
||||
#endif
|
||||
|
||||
namespace AssetUsageDetectorNamespace
|
||||
{
|
||||
@@ -26,17 +18,15 @@ namespace AssetUsageDetectorNamespace
|
||||
private const string PREFS_SEARCH_ASSETS = "AUD_AssetsSearch";
|
||||
private const string PREFS_SEARCH_PROJECT_SETTINGS = "AUD_ProjectSettingsSearch";
|
||||
private const string PREFS_DONT_SEARCH_SOURCE_ASSETS = "AUD_AssetsExcludeSrc";
|
||||
private const string PREFS_SEARCH_DEPTH_LIMIT = "AUD_Depth";
|
||||
private const string PREFS_SEARCH_FIELDS = "AUD_Fields";
|
||||
private const string PREFS_SEARCH_PROPERTIES = "AUD_Properties";
|
||||
private const string PREFS_SEARCH_NON_SERIALIZABLES = "AUD_NonSerializables";
|
||||
private const string PREFS_SEARCH_UNUSED_MATERIAL_PROPERTIES = "AUD_SearchUnusedMaterialProps";
|
||||
private const string PREFS_LAZY_SCENE_SEARCH = "AUD_LazySceneSearch";
|
||||
#if ASSET_USAGE_ADDRESSABLES
|
||||
private const string PREFS_ADDRESSABLES_SUPPORT = "AUD_AddressablesSupport";
|
||||
#endif
|
||||
private const string PREFS_CALCULATE_UNUSED_OBJECTS = "AUD_FindUnusedObjs";
|
||||
private const string PREFS_HIDE_DUPLICATE_ROWS = "AUD_HideDuplicates";
|
||||
private const string PREFS_HIDE_NON_OVERRIDDEN_PREFAB_VARIABLES_IN_ASSETS = "AUD_HideRedundantPVariantLinks";
|
||||
private const string PREFS_HIDE_NON_OVERRIDDEN_PREFAB_VARIABLES_IN_SCENES = "AUD_HideRedundantPVarsInScenes";
|
||||
private const string PREFS_HIDE_REDUNDANT_PREFAB_REFERENCES_IN_ASSETS = "AUD_HideRedundantPRefsInAssets";
|
||||
private const string PREFS_HIDE_REDUNDANT_PREFAB_REFERENCES_IN_SCENES = "AUD_HideRedundantPRefsInScenes";
|
||||
private const string PREFS_SHOW_PROGRESS = "AUD_Progress";
|
||||
|
||||
private static readonly GUIContent windowTitle = new GUIContent( "Asset Usage Detector" );
|
||||
@@ -44,6 +34,16 @@ namespace AssetUsageDetectorNamespace
|
||||
|
||||
private static readonly GUILayoutOption GL_WIDTH_12 = GUILayout.Width( 12f );
|
||||
|
||||
private static readonly GUIContent sharedGUIContent = new GUIContent();
|
||||
|
||||
private readonly GUIContent hideRedundantPrefabReferencesInAssetsLabel = new GUIContent( "Hide redundant prefab references in Assets", "Hides redundant/non-overridden references in prefab variants and nested prefabs. " +
|
||||
"This will help focus on only the references that actually matter. For example:\n\n" +
|
||||
"- Material CloudMat is assigned to prefab Cloud and its variant CloudBig. Since changing Cloud's material will also affect CloudBig, search results won't show CloudBig's reference" );
|
||||
private readonly GUIContent hideRedundantPrefabReferencesInScenesLabel = new GUIContent( "Hide redundant prefab references in Scenes", "Hides redundant/non-overridden references in prefab instances. " +
|
||||
"This will help focus on only the references that actually matter. For example:\n\n" +
|
||||
"- Prefab Healthbar is nested inside prefab Player. An instance of Player exists in the current scene and its Healthbar isn't modified. Since modifying Healthbar in Player prefab will also affect " +
|
||||
"the instance in the scene, search results won't show the instance in the scene while searching for Healthbar's references" );
|
||||
|
||||
private GUIStyle lockButtonStyle;
|
||||
|
||||
private readonly AssetUsageDetector core = new AssetUsageDetector();
|
||||
@@ -52,7 +52,6 @@ namespace AssetUsageDetectorNamespace
|
||||
// This isn't readonly so that it can be serialized
|
||||
private List<ObjectToSearch> objectsToSearch = new List<ObjectToSearch>() { new ObjectToSearch( null ) };
|
||||
|
||||
#pragma warning disable 0649
|
||||
[SerializeField] // Since titleContent persists between Editor sessions, so should the IsLocked property because otherwise, "[L]" in title becomes confusing when the EditorWindow isn't actually locked
|
||||
private bool m_isLocked;
|
||||
private bool IsLocked
|
||||
@@ -67,7 +66,6 @@ namespace AssetUsageDetectorNamespace
|
||||
}
|
||||
}
|
||||
}
|
||||
#pragma warning restore 0649
|
||||
|
||||
private Phase currentPhase = Phase.Setup;
|
||||
|
||||
@@ -84,23 +82,18 @@ namespace AssetUsageDetectorNamespace
|
||||
private List<Object> excludedAssets = new List<Object>() { null }; // These assets won't be searched for references
|
||||
private List<Object> excludedScenes = new List<Object>() { null }; // These scenes won't be searched for references
|
||||
|
||||
private int searchDepthLimit = 4; // Depth limit for recursively searching variables of objects
|
||||
|
||||
private bool lazySceneSearch = true;
|
||||
#if ASSET_USAGE_ADDRESSABLES
|
||||
private bool addressablesSupport = false;
|
||||
#endif
|
||||
private bool searchNonSerializableVariables = true;
|
||||
private bool searchUnusedMaterialProperties = true;
|
||||
private bool calculateUnusedObjects = false;
|
||||
private bool hideDuplicateRows = true;
|
||||
private bool hideNonOverriddenPrefabVariablesInAssets = true;
|
||||
private bool hideNonOverriddenPrefabVariablesInScenes = false;
|
||||
private bool hideRedundantPrefabReferencesInAssets = false;
|
||||
private bool hideRedundantPrefabReferencesInScenes = false;
|
||||
private bool noAssetDatabaseChanges = false;
|
||||
private bool showDetailedProgressBar = true;
|
||||
|
||||
private BindingFlags fieldModifiers, propertyModifiers;
|
||||
|
||||
private SearchRefactoring searchRefactoring = null; // Its value can be assigned via ShowAndSearch
|
||||
|
||||
private readonly ObjectToSearchListDrawer objectsToSearchDrawer = new ObjectToSearchListDrawer();
|
||||
@@ -119,37 +112,7 @@ namespace AssetUsageDetectorNamespace
|
||||
{
|
||||
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 )
|
||||
{
|
||||
@@ -321,10 +284,6 @@ namespace AssetUsageDetectorNamespace
|
||||
searchInAssetsFolder = searchParameters.searchInAssetsFolder;
|
||||
dontSearchInSourceAssets = searchParameters.dontSearchInSourceAssets;
|
||||
searchInProjectSettings = searchParameters.searchInProjectSettings;
|
||||
searchDepthLimit = searchParameters.searchDepthLimit;
|
||||
fieldModifiers = searchParameters.fieldModifiers;
|
||||
propertyModifiers = searchParameters.propertyModifiers;
|
||||
searchNonSerializableVariables = searchParameters.searchNonSerializableVariables;
|
||||
searchUnusedMaterialProperties = searchParameters.searchUnusedMaterialProperties;
|
||||
searchRefactoring = searchParameters.searchRefactoring;
|
||||
lazySceneSearch = searchParameters.lazySceneSearch;
|
||||
@@ -333,8 +292,8 @@ namespace AssetUsageDetectorNamespace
|
||||
#endif
|
||||
calculateUnusedObjects = searchParameters.calculateUnusedObjects;
|
||||
hideDuplicateRows = searchParameters.hideDuplicateRows;
|
||||
hideNonOverriddenPrefabVariablesInAssets = searchParameters.hideNonOverriddenPrefabVariablesInAssets;
|
||||
hideNonOverriddenPrefabVariablesInScenes = searchParameters.hideNonOverriddenPrefabVariablesInScenes;
|
||||
hideRedundantPrefabReferencesInAssets = searchParameters.hideRedundantPrefabReferencesInAssets;
|
||||
hideRedundantPrefabReferencesInScenes = searchParameters.hideRedundantPrefabReferencesInScenes;
|
||||
noAssetDatabaseChanges = searchParameters.noAssetDatabaseChanges;
|
||||
showDetailedProgressBar = searchParameters.showDetailedProgressBar;
|
||||
|
||||
@@ -374,17 +333,12 @@ namespace AssetUsageDetectorNamespace
|
||||
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
|
||||
PrefabStage.prefabStageClosing -= ReplacePrefabStageObjectsWithAssets;
|
||||
PrefabStage.prefabStageClosing += ReplacePrefabStageObjectsWithAssets;
|
||||
#endif
|
||||
}
|
||||
|
||||
private void OnDisable()
|
||||
{
|
||||
#if UNITY_2018_3_OR_NEWER
|
||||
PrefabStage.prefabStageClosing -= ReplacePrefabStageObjectsWithAssets;
|
||||
#endif
|
||||
SearchResultTooltip.Hide();
|
||||
}
|
||||
|
||||
@@ -406,10 +360,6 @@ namespace AssetUsageDetectorNamespace
|
||||
EditorPrefs.SetBool( PREFS_SEARCH_ASSETS, searchInAssetsFolder );
|
||||
EditorPrefs.SetBool( PREFS_DONT_SEARCH_SOURCE_ASSETS, dontSearchInSourceAssets );
|
||||
EditorPrefs.SetBool( PREFS_SEARCH_PROJECT_SETTINGS, searchInProjectSettings );
|
||||
EditorPrefs.SetInt( PREFS_SEARCH_DEPTH_LIMIT, searchDepthLimit );
|
||||
EditorPrefs.SetInt( PREFS_SEARCH_FIELDS, (int) fieldModifiers );
|
||||
EditorPrefs.SetInt( PREFS_SEARCH_PROPERTIES, (int) propertyModifiers );
|
||||
EditorPrefs.SetBool( PREFS_SEARCH_NON_SERIALIZABLES, searchNonSerializableVariables );
|
||||
EditorPrefs.SetBool( PREFS_SEARCH_UNUSED_MATERIAL_PROPERTIES, searchUnusedMaterialProperties );
|
||||
EditorPrefs.SetBool( PREFS_LAZY_SCENE_SEARCH, lazySceneSearch );
|
||||
#if ASSET_USAGE_ADDRESSABLES
|
||||
@@ -417,8 +367,8 @@ namespace AssetUsageDetectorNamespace
|
||||
#endif
|
||||
EditorPrefs.SetBool( PREFS_CALCULATE_UNUSED_OBJECTS, calculateUnusedObjects );
|
||||
EditorPrefs.SetBool( PREFS_HIDE_DUPLICATE_ROWS, hideDuplicateRows );
|
||||
EditorPrefs.SetBool( PREFS_HIDE_NON_OVERRIDDEN_PREFAB_VARIABLES_IN_ASSETS, hideNonOverriddenPrefabVariablesInAssets );
|
||||
EditorPrefs.SetBool( PREFS_HIDE_NON_OVERRIDDEN_PREFAB_VARIABLES_IN_SCENES, hideNonOverriddenPrefabVariablesInScenes );
|
||||
EditorPrefs.SetBool( PREFS_HIDE_REDUNDANT_PREFAB_REFERENCES_IN_ASSETS, hideRedundantPrefabReferencesInAssets );
|
||||
EditorPrefs.SetBool( PREFS_HIDE_REDUNDANT_PREFAB_REFERENCES_IN_SCENES, hideRedundantPrefabReferencesInScenes );
|
||||
EditorPrefs.SetBool( PREFS_SHOW_PROGRESS, showDetailedProgressBar );
|
||||
}
|
||||
|
||||
@@ -429,10 +379,6 @@ namespace AssetUsageDetectorNamespace
|
||||
searchInAssetsFolder = EditorPrefs.GetBool( PREFS_SEARCH_ASSETS, true );
|
||||
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 );
|
||||
fieldModifiers = (BindingFlags) EditorPrefs.GetInt( PREFS_SEARCH_FIELDS, (int) ( BindingFlags.Public | BindingFlags.NonPublic ) );
|
||||
propertyModifiers = (BindingFlags) EditorPrefs.GetInt( PREFS_SEARCH_PROPERTIES, (int) ( BindingFlags.Public | BindingFlags.NonPublic ) );
|
||||
searchNonSerializableVariables = EditorPrefs.GetBool( PREFS_SEARCH_NON_SERIALIZABLES, true );
|
||||
searchUnusedMaterialProperties = EditorPrefs.GetBool( PREFS_SEARCH_UNUSED_MATERIAL_PROPERTIES, true );
|
||||
lazySceneSearch = EditorPrefs.GetBool( PREFS_LAZY_SCENE_SEARCH, true );
|
||||
#if ASSET_USAGE_ADDRESSABLES
|
||||
@@ -440,8 +386,8 @@ namespace AssetUsageDetectorNamespace
|
||||
#endif
|
||||
calculateUnusedObjects = EditorPrefs.GetBool( PREFS_CALCULATE_UNUSED_OBJECTS, false );
|
||||
hideDuplicateRows = EditorPrefs.GetBool( PREFS_HIDE_DUPLICATE_ROWS, true );
|
||||
hideNonOverriddenPrefabVariablesInAssets = EditorPrefs.GetBool( PREFS_HIDE_NON_OVERRIDDEN_PREFAB_VARIABLES_IN_ASSETS, true );
|
||||
hideNonOverriddenPrefabVariablesInScenes = EditorPrefs.GetBool( PREFS_HIDE_NON_OVERRIDDEN_PREFAB_VARIABLES_IN_SCENES, false );
|
||||
hideRedundantPrefabReferencesInAssets = EditorPrefs.GetBool( PREFS_HIDE_REDUNDANT_PREFAB_REFERENCES_IN_ASSETS, hideRedundantPrefabReferencesInAssets );
|
||||
hideRedundantPrefabReferencesInScenes = EditorPrefs.GetBool( PREFS_HIDE_REDUNDANT_PREFAB_REFERENCES_IN_SCENES, hideRedundantPrefabReferencesInScenes );
|
||||
showDetailedProgressBar = EditorPrefs.GetBool( PREFS_SHOW_PROGRESS, true );
|
||||
}
|
||||
|
||||
@@ -502,24 +448,16 @@ namespace AssetUsageDetectorNamespace
|
||||
|
||||
GUILayout.Space( 10f );
|
||||
|
||||
Color c = GUI.backgroundColor;
|
||||
GUI.backgroundColor = AssetUsageDetectorSettings.SettingsHeaderColor;
|
||||
GUILayout.Box( "<b>SEARCH IN</b>", Utilities.BoxGUIStyle, Utilities.GL_EXPAND_WIDTH );
|
||||
GUI.backgroundColor = c;
|
||||
Utilities.DrawHeader( "<b>SEARCH IN</b>" );
|
||||
|
||||
searchInAssetsFolder = WordWrappingToggleLeft( "Project window (Assets folder)", searchInAssetsFolder );
|
||||
|
||||
if( searchInAssetsFolder )
|
||||
{
|
||||
GUILayout.BeginHorizontal();
|
||||
GUILayout.Space( 35f );
|
||||
GUILayout.BeginVertical();
|
||||
|
||||
BeginIndentedGUI();
|
||||
searchInAssetsSubsetDrawer.Draw( searchInAssetsSubset );
|
||||
excludedAssetsDrawer.Draw( excludedAssets );
|
||||
|
||||
GUILayout.EndVertical();
|
||||
GUILayout.EndHorizontal();
|
||||
EndIndentedGUI();
|
||||
}
|
||||
|
||||
GUILayout.Space( 5f );
|
||||
@@ -540,13 +478,10 @@ namespace AssetUsageDetectorNamespace
|
||||
|
||||
if( searchInScenesInBuild )
|
||||
{
|
||||
GUILayout.BeginHorizontal();
|
||||
GUILayout.Space( 35f );
|
||||
|
||||
BeginIndentedGUI( false );
|
||||
searchInScenesInBuildTickedOnly = EditorGUILayout.ToggleLeft( "Ticked only", searchInScenesInBuildTickedOnly, Utilities.GL_WIDTH_100 );
|
||||
searchInScenesInBuildTickedOnly = !EditorGUILayout.ToggleLeft( "All", !searchInScenesInBuildTickedOnly, Utilities.GL_WIDTH_100 );
|
||||
|
||||
GUILayout.EndHorizontal();
|
||||
EndIndentedGUI( false );
|
||||
}
|
||||
|
||||
GUI.enabled = true;
|
||||
@@ -554,14 +489,9 @@ namespace AssetUsageDetectorNamespace
|
||||
searchInAllScenes = WordWrappingToggleLeft( "All scenes in the project", searchInAllScenes );
|
||||
}
|
||||
|
||||
GUILayout.BeginHorizontal();
|
||||
GUILayout.Space( 35f );
|
||||
GUILayout.BeginVertical();
|
||||
|
||||
BeginIndentedGUI();
|
||||
excludedScenesDrawer.Draw( excludedScenes );
|
||||
|
||||
GUILayout.EndVertical();
|
||||
GUILayout.EndHorizontal();
|
||||
EndIndentedGUI();
|
||||
|
||||
EditorGUI.BeginDisabledGroup( !searchInOpenScenes && !searchInScenesInBuild && !searchInAllScenes );
|
||||
searchInSceneLightingSettings = WordWrappingToggleLeft( "Scene Lighting Settings (WARNING: This may change the active scene during search)", searchInSceneLightingSettings );
|
||||
@@ -573,9 +503,7 @@ namespace AssetUsageDetectorNamespace
|
||||
|
||||
GUILayout.Space( 10f );
|
||||
|
||||
GUI.backgroundColor = AssetUsageDetectorSettings.SettingsHeaderColor;
|
||||
GUILayout.Box( "<b>SETTINGS</b>", Utilities.BoxGUIStyle, Utilities.GL_EXPAND_WIDTH );
|
||||
GUI.backgroundColor = c;
|
||||
Utilities.DrawHeader( "<b>SETTINGS</b>" );
|
||||
|
||||
#if ASSET_USAGE_ADDRESSABLES
|
||||
EditorGUI.BeginDisabledGroup( addressablesSupport );
|
||||
@@ -587,10 +515,8 @@ namespace AssetUsageDetectorNamespace
|
||||
#endif
|
||||
calculateUnusedObjects = WordWrappingToggleLeft( "Calculate unused objects", calculateUnusedObjects );
|
||||
hideDuplicateRows = WordWrappingToggleLeft( "Hide duplicate rows in search results", hideDuplicateRows );
|
||||
#if UNITY_2018_3_OR_NEWER
|
||||
hideNonOverriddenPrefabVariablesInAssets = WordWrappingToggleLeft( "Hide non-overridden prefab variables in assets (references found in non-overridden variables of prefab variants/nested prefabs will be hidden)", hideNonOverriddenPrefabVariablesInAssets );
|
||||
hideNonOverriddenPrefabVariablesInScenes = WordWrappingToggleLeft( "Hide non-overridden prefab variables in scenes (references found in non-overridden variables of prefab instances will be hidden)", hideNonOverriddenPrefabVariablesInScenes );
|
||||
#endif
|
||||
hideRedundantPrefabReferencesInAssets = WordWrappingToggleLeft( hideRedundantPrefabReferencesInAssetsLabel, hideRedundantPrefabReferencesInAssets );
|
||||
hideRedundantPrefabReferencesInScenes = WordWrappingToggleLeft( hideRedundantPrefabReferencesInScenesLabel, hideRedundantPrefabReferencesInScenes );
|
||||
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 );
|
||||
|
||||
@@ -664,10 +590,7 @@ namespace AssetUsageDetectorNamespace
|
||||
|
||||
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;
|
||||
Utilities.DrawHeader( "<b>SEARCHED OBJECTS</b>" );
|
||||
|
||||
Rect searchedObjectsHeaderRect = GUILayoutUtility.GetLastRect();
|
||||
searchedObjectsHeaderRect.x += 5f;
|
||||
@@ -680,7 +603,31 @@ namespace AssetUsageDetectorNamespace
|
||||
objectsToSearchDrawer.Draw( objectsToSearch );
|
||||
}
|
||||
|
||||
private void BeginIndentedGUI( bool isVertical = true )
|
||||
{
|
||||
GUILayout.BeginHorizontal();
|
||||
GUILayout.Space( 35f );
|
||||
|
||||
if( isVertical )
|
||||
GUILayout.BeginVertical();
|
||||
}
|
||||
|
||||
private void EndIndentedGUI( bool isVertical = true )
|
||||
{
|
||||
if( isVertical )
|
||||
GUILayout.EndVertical();
|
||||
|
||||
GUILayout.EndHorizontal();
|
||||
}
|
||||
|
||||
public static bool WordWrappingToggleLeft( string label, bool value )
|
||||
{
|
||||
sharedGUIContent.text = label;
|
||||
sharedGUIContent.tooltip = null;
|
||||
return WordWrappingToggleLeft( sharedGUIContent, value );
|
||||
}
|
||||
|
||||
public static bool WordWrappingToggleLeft( GUIContent label, bool value )
|
||||
{
|
||||
GUILayout.BeginHorizontal();
|
||||
bool result = EditorGUILayout.ToggleLeft( GUIContent.none, value, GL_WIDTH_12 );
|
||||
@@ -699,10 +646,7 @@ namespace AssetUsageDetectorNamespace
|
||||
currentPhase = Phase.Processing;
|
||||
|
||||
SavePrefs();
|
||||
|
||||
#if UNITY_2018_3_OR_NEWER
|
||||
ReplacePrefabStageObjectsWithAssets( PrefabStageUtility.GetCurrentPrefabStage() );
|
||||
#endif
|
||||
|
||||
// Start searching
|
||||
searchResult = core.Run( new AssetUsageDetector.Parameters()
|
||||
@@ -716,10 +660,6 @@ namespace AssetUsageDetectorNamespace
|
||||
dontSearchInSourceAssets = dontSearchInSourceAssets,
|
||||
excludedScenesFromSearch = !excludedScenes.IsEmpty() ? excludedScenes.ToArray() : null,
|
||||
searchInProjectSettings = searchInProjectSettings,
|
||||
//fieldModifiers = fieldModifiers,
|
||||
//propertyModifiers = propertyModifiers,
|
||||
//searchDepthLimit = searchDepthLimit,
|
||||
//searchNonSerializableVariables = searchNonSerializableVariables,
|
||||
searchUnusedMaterialProperties = searchUnusedMaterialProperties,
|
||||
searchRefactoring = searchRefactoring,
|
||||
#if ASSET_USAGE_ADDRESSABLES
|
||||
@@ -730,8 +670,8 @@ namespace AssetUsageDetectorNamespace
|
||||
#endif
|
||||
calculateUnusedObjects = calculateUnusedObjects,
|
||||
hideDuplicateRows = hideDuplicateRows,
|
||||
hideNonOverriddenPrefabVariablesInAssets = hideNonOverriddenPrefabVariablesInAssets,
|
||||
hideNonOverriddenPrefabVariablesInScenes = hideNonOverriddenPrefabVariablesInScenes,
|
||||
hideRedundantPrefabReferencesInAssets = hideRedundantPrefabReferencesInAssets,
|
||||
hideRedundantPrefabReferencesInScenes = hideRedundantPrefabReferencesInScenes && searchInAssetsFolder,
|
||||
noAssetDatabaseChanges = noAssetDatabaseChanges,
|
||||
showDetailedProgressBar = showDetailedProgressBar
|
||||
} );
|
||||
@@ -745,18 +685,13 @@ namespace AssetUsageDetectorNamespace
|
||||
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( 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 );
|
||||
#endif
|
||||
if( prefabAsset == null || prefabAsset.Equals( null ) )
|
||||
return;
|
||||
|
||||
@@ -783,7 +718,6 @@ namespace AssetUsageDetectorNamespace
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
private bool ReturnToSetupPhase()
|
||||
{
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
using System.Collections.Generic;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using UnityEngine.U2D;
|
||||
using Object = UnityEngine.Object;
|
||||
|
||||
namespace AssetUsageDetectorNamespace
|
||||
@@ -95,6 +96,20 @@ namespace AssetUsageDetectorNamespace
|
||||
}
|
||||
}
|
||||
|
||||
// Add Sprites of SpriteAtlases to the sub-assets list
|
||||
if( target is SpriteAtlas spriteAtlas )
|
||||
{
|
||||
Sprite[] packedSprites = AssetUsageDetector.spriteAtlasPackedSpritesGetter( spriteAtlas );
|
||||
if( packedSprites != null )
|
||||
{
|
||||
for( int i = 0; i < packedSprites.Length; i++ )
|
||||
{
|
||||
if( packedSprites[i] != null && currentSubAssets.Add( packedSprites[i] ) )
|
||||
subAssets.Add( new SubAsset( packedSprites[i], shouldSearchChildren ?? true ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Find sub-asset(s) of the asset (if any)
|
||||
Object[] assets = AssetDatabase.LoadAllAssetsAtPath( AssetDatabase.GetAssetPath( target ) );
|
||||
for( int i = 0; i < assets.Length; i++ )
|
||||
@@ -103,13 +118,11 @@ namespace AssetUsageDetectorNamespace
|
||||
if( asset == null || asset.Equals( null ) || asset is Component || asset == target )
|
||||
continue;
|
||||
|
||||
#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( currentSubAssets.Add( asset ) )
|
||||
subAssets.Add( new SubAsset( asset, shouldSearchChildren ?? true ) );
|
||||
@@ -117,4 +130,4 @@ namespace AssetUsageDetectorNamespace
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ using System.Reflection;
|
||||
using UnityEditor;
|
||||
using UnityEditor.SceneManagement;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Rendering;
|
||||
using Object = UnityEngine.Object;
|
||||
|
||||
namespace AssetUsageDetectorNamespace
|
||||
@@ -152,9 +153,7 @@ namespace AssetUsageDetectorNamespace
|
||||
}
|
||||
|
||||
break;
|
||||
#if UNITY_2019_3_OR_NEWER
|
||||
case SerializedPropertyType.ManagedReference: SerializedProperty.managedReferenceValue = newValue; break;
|
||||
#endif
|
||||
}
|
||||
|
||||
SerializedProperty.serializedObject.ApplyModifiedPropertiesWithoutUndo();
|
||||
@@ -267,7 +266,7 @@ namespace AssetUsageDetectorNamespace
|
||||
|
||||
for( int i = 0; i < MonoScriptAllVariables.Length; i++ )
|
||||
{
|
||||
if( MonoScriptAllVariables[i].isSerializable && !MonoScriptAllVariables[i].IsProperty )
|
||||
if (!MonoScriptAllVariables[i].IsProperty)
|
||||
{
|
||||
Object variableDefaultValue = monoImporter.GetDefaultReference( MonoScriptAllVariables[i].Name );
|
||||
if( variableDefaultValue == Value && MonoScriptAllVariables[i].Name == Variable )
|
||||
@@ -288,20 +287,17 @@ namespace AssetUsageDetectorNamespace
|
||||
|
||||
List<string> textureNames = new List<string>( 16 );
|
||||
List<Texture> textureValues = new List<Texture>( 16 );
|
||||
#if UNITY_2018_1_OR_NEWER
|
||||
List<string> nonModifiableTextureNames = new List<string>( 16 );
|
||||
List<Texture> nonModifiableTextureValues = new List<Texture>( 16 );
|
||||
#endif
|
||||
|
||||
int shaderPropertyCount = ShaderUtil.GetPropertyCount( shader );
|
||||
int shaderPropertyCount = shader.GetPropertyCount();
|
||||
for( int i = 0; i < shaderPropertyCount; i++ )
|
||||
{
|
||||
if( ShaderUtil.GetPropertyType( shader, i ) != ShaderUtil.ShaderPropertyType.TexEnv )
|
||||
continue;
|
||||
if (shader.GetPropertyType(i) != ShaderPropertyType.Texture)
|
||||
continue;
|
||||
|
||||
string propertyName = ShaderUtil.GetPropertyName( shader, i );
|
||||
#if UNITY_2018_1_OR_NEWER
|
||||
if( ShaderUtil.IsShaderPropertyNonModifiableTexureProperty( shader, i ) )
|
||||
string propertyName = shader.GetPropertyName(i);
|
||||
if ((shader.GetPropertyFlags(i) & ShaderPropertyFlags.NonModifiableTextureData) != 0)
|
||||
{
|
||||
Texture propertyDefaultValue = shaderImporter.GetNonModifiableTexture( propertyName );
|
||||
if( propertyDefaultValue == Value && propertyName == Variable )
|
||||
@@ -311,7 +307,6 @@ namespace AssetUsageDetectorNamespace
|
||||
nonModifiableTextureValues.Add( propertyDefaultValue );
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
Texture propertyDefaultValue = shaderImporter.GetDefaultTexture( propertyName );
|
||||
if( propertyDefaultValue == Value && propertyName == Variable )
|
||||
@@ -323,9 +318,7 @@ namespace AssetUsageDetectorNamespace
|
||||
}
|
||||
|
||||
shaderImporter.SetDefaultTextures( textureNames.ToArray(), textureValues.ToArray() );
|
||||
#if UNITY_2018_1_OR_NEWER
|
||||
shaderImporter.SetNonModifiableTextures( nonModifiableTextureNames.ToArray(), nonModifiableTextureValues.ToArray() );
|
||||
#endif
|
||||
AssetDatabase.ImportAsset( shaderImporter.assetPath );
|
||||
}
|
||||
else
|
||||
|
||||
@@ -9,6 +9,14 @@ using UnityEditor.SceneManagement;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
using Object = UnityEngine.Object;
|
||||
#if UNITY_6000_3_OR_NEWER
|
||||
using EntityId = UnityEngine.EntityId;
|
||||
#else
|
||||
using EntityId = System.Int32;
|
||||
#endif
|
||||
#if UNITY_6000_2_OR_NEWER
|
||||
using TreeViewItem = UnityEditor.IMGUI.Controls.TreeViewItem<int>;
|
||||
#endif
|
||||
|
||||
namespace AssetUsageDetectorNamespace
|
||||
{
|
||||
@@ -23,6 +31,7 @@ namespace AssetUsageDetectorNamespace
|
||||
public SearchResultGroup.GroupType type;
|
||||
public bool isExpanded;
|
||||
public bool pendingSearch;
|
||||
public int redundantReferences;
|
||||
public SearchResultTreeViewState treeViewState;
|
||||
|
||||
public List<int> initialSerializedNodes;
|
||||
@@ -38,7 +47,7 @@ namespace AssetUsageDetectorNamespace
|
||||
}
|
||||
|
||||
public string label;
|
||||
public int instanceId;
|
||||
public EntityId instanceId;
|
||||
public bool isUnityObject, isMainReference;
|
||||
public ReferenceNode.UsedState usedState;
|
||||
|
||||
@@ -576,6 +585,9 @@ namespace AssetUsageDetectorNamespace
|
||||
public int NumberOfReferences { get { return references.Count; } }
|
||||
public ReferenceNode this[int index] { get { return references[index]; } }
|
||||
|
||||
public int NumberOfRedundantReferences { get; internal set; }
|
||||
public bool AnyReferencesFound { get { return NumberOfReferences > 0 || NumberOfRedundantReferences > 0; } }
|
||||
|
||||
public SearchResultGroup( string title, GroupType type, bool isExpanded = true, bool pendingSearch = false )
|
||||
{
|
||||
Title = title.StartsWith( "<b>" ) ? title : string.Concat( "<b>", title, "</b>" );
|
||||
@@ -816,6 +828,7 @@ namespace AssetUsageDetectorNamespace
|
||||
removedRows.Add( treeViewRows[i].id );
|
||||
}
|
||||
|
||||
treeView.ClearSearch();
|
||||
treeView.HideItems( removedRows );
|
||||
} );
|
||||
}
|
||||
@@ -868,6 +881,9 @@ namespace AssetUsageDetectorNamespace
|
||||
|
||||
if( IsExpanded )
|
||||
{
|
||||
if( NumberOfRedundantReferences > 0 )
|
||||
EditorGUILayout.HelpBox( string.Concat( NumberOfRedundantReferences.ToString(), " redundant prefab reference(s) were skipped. Disable \"Hide redundant prefab references in ", ( Type == GroupType.Scene || Type == GroupType.DontDestroyOnLoad ) ? "Scenes" : "Assets", "\" to see them." ), MessageType.Info );
|
||||
|
||||
if( PendingSearch )
|
||||
GUILayout.Box( "Lazy Search: this scene potentially has some references, hit Refresh to find them", Utilities.BoxGUIStyle );
|
||||
else if( references.Count == 0 )
|
||||
@@ -972,19 +988,8 @@ namespace AssetUsageDetectorNamespace
|
||||
|
||||
Rect treeViewRect = EditorGUILayout.GetControlRect( false, treeView.totalHeight );
|
||||
if( ev.type == EventType.Repaint )
|
||||
{
|
||||
lastTreeViewRect = treeViewRect;
|
||||
|
||||
#if !UNITY_2018_2_OR_NEWER
|
||||
// TreeView calls RowGUI for all rows instead of only the visible rows on early Unity versions which leads to performance issues. Do manual row culling on those versions
|
||||
// Credit: https://github.com/Unity-Technologies/UnityCsReference/blob/a048de916b23331bf6dfe92c4a6c205989b83b4f/Editor/Mono/GUI/TreeView/TreeViewGUI.cs#L273-L276
|
||||
float topPixel = scrollPosition - treeViewRect.y;
|
||||
float heightInPixels = window.position.height;
|
||||
treeView.visibleRowTop = (int) Mathf.Floor( topPixel / treeView.rowHeight );
|
||||
treeView.visibleRowBottom = treeView.visibleRowTop + (int) Mathf.Ceil( heightInPixels / treeView.rowHeight );
|
||||
#endif
|
||||
}
|
||||
|
||||
treeView.OnGUI( treeViewRect );
|
||||
|
||||
if( treeViewKeyboardNavigation && treeView.HasFocus() && treeView.HasSelection() )
|
||||
@@ -1064,6 +1069,7 @@ namespace AssetUsageDetectorNamespace
|
||||
type = Type,
|
||||
isExpanded = IsExpanded,
|
||||
pendingSearch = PendingSearch,
|
||||
redundantReferences = NumberOfRedundantReferences,
|
||||
treeViewState = treeViewState
|
||||
};
|
||||
|
||||
@@ -1081,6 +1087,7 @@ namespace AssetUsageDetectorNamespace
|
||||
// Deserialize this result group from the serialized data
|
||||
internal void Deserialize( SearchResult.SerializableResultGroup serializedResultGroup, List<ReferenceNode> allNodes )
|
||||
{
|
||||
NumberOfRedundantReferences = serializedResultGroup.redundantReferences;
|
||||
treeViewState = serializedResultGroup.treeViewState;
|
||||
|
||||
if( serializedResultGroup.initialSerializedNodes != null )
|
||||
@@ -1128,8 +1135,8 @@ namespace AssetUsageDetectorNamespace
|
||||
public bool IsMainReference { get; private set; } // True: if belongs to a scene search result group, then it's an object in that scene. If belongs to the assets search result group, then it's an asset
|
||||
|
||||
internal object nodeObject;
|
||||
private int? instanceId; // instanceId of the nodeObject if it is a Unity object, null otherwise
|
||||
public Object UnityObject { get { return instanceId.HasValue ? EditorUtility.InstanceIDToObject( instanceId.Value ) : null; } }
|
||||
private EntityId? instanceId; // instanceId of the nodeObject if it is a Unity object, null otherwise
|
||||
public Object UnityObject => instanceId.HasValue ? Utilities.EntityIdToObject(instanceId.Value) : null;
|
||||
|
||||
private readonly List<Link> links = new List<Link>( 2 );
|
||||
public int NumberOfOutgoingLinks { get { return links.Count; } }
|
||||
@@ -1223,7 +1230,7 @@ namespace AssetUsageDetectorNamespace
|
||||
Object unityObject = nodeObject as Object;
|
||||
if( unityObject != null )
|
||||
{
|
||||
instanceId = unityObject.GetInstanceID();
|
||||
instanceId = unityObject.GetEntityId();
|
||||
Label = unityObject.name + " (" + unityObject.GetType().Name + ")";
|
||||
|
||||
if( AssetUsageDetectorSettings.ShowRootAssetName && unityObject.IsAsset() && !AssetDatabase.IsMainAsset( unityObject ) )
|
||||
|
||||
@@ -26,11 +26,20 @@ namespace AssetUsageDetectorNamespace
|
||||
|
||||
public static void Show( Rect sourcePosition, string tooltip )
|
||||
{
|
||||
// Don't lose focus to the previous window
|
||||
EditorWindow prevFocusedWindow = focusedWindow;
|
||||
|
||||
if (!mainWindow)
|
||||
{
|
||||
mainWindow = CreateInstance<SearchResultTooltip>();
|
||||
mainWindow.ShowPopup();
|
||||
}
|
||||
|
||||
Vector2 preferredSize = Style.CalcSize( new GUIContent( tooltip ) ) + Style.contentOffset + new Vector2( Style.padding.horizontal + Style.margin.horizontal, Style.padding.vertical + Style.margin.vertical );
|
||||
Rect preferredPosition;
|
||||
|
||||
Rect positionLeft = new Rect( sourcePosition.position - new Vector2( preferredSize.x, 0f ), preferredSize );
|
||||
Rect screenFittedPositionLeft = Utilities.GetScreenFittedRect( positionLeft );
|
||||
Rect screenFittedPositionLeft = Utilities.GetScreenFittedRect(positionLeft, mainWindow);
|
||||
|
||||
Vector2 positionOffset = positionLeft.position - screenFittedPositionLeft.position;
|
||||
Vector2 sizeOffset = positionLeft.size - screenFittedPositionLeft.size;
|
||||
@@ -39,7 +48,7 @@ namespace AssetUsageDetectorNamespace
|
||||
else
|
||||
{
|
||||
Rect positionRight = new Rect( sourcePosition.position + new Vector2( sourcePosition.width, 0f ), preferredSize );
|
||||
Rect screenFittedPositionRight = Utilities.GetScreenFittedRect( positionRight );
|
||||
Rect screenFittedPositionRight = Utilities.GetScreenFittedRect(positionRight, mainWindow);
|
||||
|
||||
Vector2 positionOffset2 = positionRight.position - screenFittedPositionRight.position;
|
||||
Vector2 sizeOffset2 = positionRight.size - screenFittedPositionRight.size;
|
||||
@@ -49,15 +58,6 @@ namespace AssetUsageDetectorNamespace
|
||||
preferredPosition = screenFittedPositionLeft;
|
||||
}
|
||||
|
||||
// Don't lose focus to the previous window
|
||||
EditorWindow prevFocusedWindow = focusedWindow;
|
||||
|
||||
if( !mainWindow )
|
||||
{
|
||||
mainWindow = CreateInstance<SearchResultTooltip>();
|
||||
mainWindow.ShowPopup();
|
||||
}
|
||||
|
||||
SearchResultTooltip.tooltip = tooltip;
|
||||
mainWindow.minSize = preferredPosition.size;
|
||||
mainWindow.position = preferredPosition;
|
||||
|
||||
@@ -4,13 +4,12 @@ using System.Reflection;
|
||||
using System.Text;
|
||||
using UnityEditor;
|
||||
using UnityEditor.IMGUI.Controls;
|
||||
using UnityEditor.SceneManagement;
|
||||
using UnityEngine;
|
||||
#if UNITY_2021_2_OR_NEWER
|
||||
using PrefabStage = UnityEditor.SceneManagement.PrefabStage;
|
||||
using PrefabStageUtility = UnityEditor.SceneManagement.PrefabStageUtility;
|
||||
#elif UNITY_2018_3_OR_NEWER
|
||||
using PrefabStage = UnityEditor.Experimental.SceneManagement.PrefabStage;
|
||||
using PrefabStageUtility = UnityEditor.Experimental.SceneManagement.PrefabStageUtility;
|
||||
#if UNITY_6000_2_OR_NEWER
|
||||
using TreeView = UnityEditor.IMGUI.Controls.TreeView<int>;
|
||||
using TreeViewItem = UnityEditor.IMGUI.Controls.TreeViewItem<int>;
|
||||
using TreeViewState = UnityEditor.IMGUI.Controls.TreeViewState<int>;
|
||||
#endif
|
||||
|
||||
namespace AssetUsageDetectorNamespace
|
||||
@@ -104,11 +103,7 @@ namespace AssetUsageDetectorNamespace
|
||||
}
|
||||
|
||||
private const float SEARCHED_OBJECTS_BORDER_THICKNESS = 1f;
|
||||
#if UNITY_2019_3_OR_NEWER
|
||||
private const float TREE_VIEW_LINES_THICKNESS = 1.5f; // There are inexplicable spaces between the vertical and horizontal lines if we don't change thickness by 0.5f on 2019.3+
|
||||
#else
|
||||
private const float TREE_VIEW_LINES_THICKNESS = 2f;
|
||||
#endif
|
||||
private const float TREE_VIEW_LINES_THICKNESS = 1.5f; // There are inexplicable spaces between the vertical and horizontal lines if we set this to 2.0f on 2019.3+
|
||||
private const float HIGHLIGHTED_TREE_VIEW_LINES_THICKNESS = TREE_VIEW_LINES_THICKNESS * 2f;
|
||||
|
||||
private readonly new SearchResultTreeViewState state;
|
||||
@@ -127,10 +122,6 @@ namespace AssetUsageDetectorNamespace
|
||||
|
||||
private bool isSearching;
|
||||
|
||||
#if !UNITY_2018_2_OR_NEWER
|
||||
public int visibleRowTop = 0, visibleRowBottom = int.MaxValue;
|
||||
#endif
|
||||
|
||||
private readonly CompareInfo textComparer = new CultureInfo( "en-US" ).CompareInfo;
|
||||
private readonly CompareOptions textCompareOptions = CompareOptions.IgnoreCase | CompareOptions.IgnoreNonSpace;
|
||||
|
||||
@@ -150,13 +141,7 @@ namespace AssetUsageDetectorNamespace
|
||||
public new float rowHeight
|
||||
{
|
||||
get { return base.rowHeight; }
|
||||
set
|
||||
{
|
||||
base.rowHeight = value;
|
||||
#if !UNITY_2019_3_OR_NEWER
|
||||
customFoldoutYOffset = ( value - EditorGUIUtility.singleLineHeight ) * 0.5f;
|
||||
#endif
|
||||
}
|
||||
set { base.rowHeight = value; }
|
||||
}
|
||||
|
||||
// Avoid using these properties of TreeView by mistake
|
||||
@@ -183,13 +168,7 @@ namespace AssetUsageDetectorNamespace
|
||||
if( treeType != TreeType.IsolatedView )
|
||||
{
|
||||
// Draw only the visible rows. This requires setting useScrollView to false because we are using an external scroll view: https://docs.unity3d.com/ScriptReference/IMGUI.Controls.TreeView-useScrollView.html
|
||||
#if UNITY_2018_2_OR_NEWER
|
||||
useScrollView = false;
|
||||
#else
|
||||
// In my tests, SetUseScrollView seems to have no effect unfortunately but let's keep this line in case it fixes some other issues with the external scroll view
|
||||
object treeViewController = typeof( TreeView ).GetField( "m_TreeView", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance ).GetValue( this );
|
||||
treeViewController.GetType().GetMethod( "SetUseScrollView", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance ).Invoke( treeViewController, new object[1] { false } );
|
||||
#endif
|
||||
}
|
||||
|
||||
isSearching = !string.IsNullOrEmpty( state.searchTerm );
|
||||
@@ -200,6 +179,13 @@ namespace AssetUsageDetectorNamespace
|
||||
RefreshSelectedNodes( GetSelection() );
|
||||
}
|
||||
|
||||
public void ClearSearch()
|
||||
{
|
||||
string prevSearchTerm = state.searchTerm;
|
||||
state.searchTerm = "";
|
||||
RefreshSearch( prevSearchTerm );
|
||||
}
|
||||
|
||||
public void RefreshSearch( string prevSearchTerm )
|
||||
{
|
||||
bool wasSearchTermEmpty = string.IsNullOrEmpty( prevSearchTerm );
|
||||
@@ -416,12 +402,6 @@ namespace AssetUsageDetectorNamespace
|
||||
|
||||
protected override void RowGUI( RowGUIArgs args )
|
||||
{
|
||||
#if !UNITY_2018_2_OR_NEWER
|
||||
// Do manual row culling on early Unity versions
|
||||
if( args.row < visibleRowTop || args.row > visibleRowBottom )
|
||||
return;
|
||||
#endif
|
||||
|
||||
if( isTreeViewEmpty )
|
||||
{
|
||||
EditorGUI.LabelField( args.rowRect, "No matching results..." );
|
||||
@@ -659,9 +639,6 @@ namespace AssetUsageDetectorNamespace
|
||||
|
||||
rect.xMin += GetContentIndent( args.item );
|
||||
rect.y += AssetUsageDetectorSettings.ExtraRowHeight * 0.5f;
|
||||
#if !UNITY_2019_3_OR_NEWER
|
||||
rect.y -= 2f;
|
||||
#endif
|
||||
rect.height += 4f; // Incrementing height fixes cropped icon issue on Unity 2019.2 or earlier
|
||||
|
||||
if( foldoutLabelStyle == null )
|
||||
@@ -738,7 +715,6 @@ namespace AssetUsageDetectorNamespace
|
||||
isLMBDown = false;
|
||||
|
||||
Object clickedObject = GetDataFromId( id ).node.UnityObject;
|
||||
#if UNITY_2018_3_OR_NEWER
|
||||
if( clickedObject && clickedObject.IsAsset() )
|
||||
{
|
||||
GameObject clickedPrefabRoot = null;
|
||||
@@ -755,16 +731,11 @@ namespace AssetUsageDetectorNamespace
|
||||
// Try to open the prefab stage of this prefab
|
||||
string assetPath = AssetDatabase.GetAssetPath( clickedPrefabRoot );
|
||||
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
|
||||
AssetDatabase.OpenAsset( clickedPrefabRoot );
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
// Ping the clicked GameObject in the open prefab stage
|
||||
Object selection, pingTarget;
|
||||
@@ -1339,7 +1310,7 @@ namespace AssetUsageDetectorNamespace
|
||||
if( preferredHeight > 10f )
|
||||
{
|
||||
Vector2 size = position.size;
|
||||
position = Utilities.GetScreenFittedRect( new Rect( GUIUtility.GUIToScreenPoint( Event.current.mousePosition ) + new Vector2( size.x * -0.5f, 10f ), size ) );
|
||||
position = Utilities.GetScreenFittedRect(new Rect(GUIUtility.GUIToScreenPoint(Event.current.mousePosition) + new Vector2(size.x * -0.5f, 10f), size), this);
|
||||
|
||||
shouldRepositionSelf = false;
|
||||
GUIUtility.ExitGUI();
|
||||
|
||||
@@ -2,18 +2,12 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
#if UNITY_2018_1_OR_NEWER
|
||||
using Unity.Collections;
|
||||
#endif
|
||||
using UnityEditor;
|
||||
using UnityEditor.SceneManagement;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
using Object = UnityEngine.Object;
|
||||
#if UNITY_2018_3_OR_NEWER && !UNITY_2021_2_OR_NEWER
|
||||
using PrefabStage = UnityEditor.Experimental.SceneManagement.PrefabStage;
|
||||
using PrefabStageUtility = UnityEditor.Experimental.SceneManagement.PrefabStageUtility;
|
||||
#endif
|
||||
|
||||
namespace AssetUsageDetectorNamespace
|
||||
{
|
||||
@@ -37,19 +31,19 @@ namespace AssetUsageDetectorNamespace
|
||||
typeof( List<Vector4> ), typeof( List<Vector3> ), typeof( List<Vector2> ), typeof( List<Rect> ),
|
||||
typeof( List<Quaternion> ), typeof( List<Color> ), typeof( List<Color32> ), typeof( List<LayerMask> ), typeof( List<Bounds> ),
|
||||
typeof( List<Matrix4x4> ), typeof( List<AnimationCurve> ), typeof( List<Gradient> ), typeof( List<RectOffset> ),
|
||||
#if UNITY_2017_2_OR_NEWER
|
||||
typeof( Vector3Int ), typeof( Vector2Int ), typeof( RectInt ), typeof( BoundsInt ),
|
||||
typeof( Vector3Int[] ), typeof( Vector2Int[] ), typeof( RectInt[] ), typeof( BoundsInt[] ),
|
||||
typeof( List<Vector3Int> ), typeof( List<Vector2Int> ), typeof( List<RectInt> ), typeof( List<BoundsInt> )
|
||||
#endif
|
||||
};
|
||||
|
||||
private static readonly string reflectionNamespace = typeof( Assembly ).Namespace;
|
||||
#if UNITY_2018_1_OR_NEWER
|
||||
private static readonly string nativeCollectionsNamespace = typeof( NativeArray<int> ).Namespace;
|
||||
#endif
|
||||
|
||||
private static MethodInfo screenFittedRectGetter;
|
||||
private static MethodInfo screenFittedRectGetter;
|
||||
private static FieldInfo editorWindowHostViewGetter;
|
||||
private static PropertyInfo hostViewContainerWindowGetter;
|
||||
|
||||
private static readonly Func<Object, bool, bool> prefabHasAnyOverridesGetter = (Func<Object, bool, bool>) Delegate.CreateDelegate( typeof( Func<Object, bool, bool> ), typeof( PrefabUtility ).GetMethod( "HasObjectOverride", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static ) );
|
||||
|
||||
private static readonly HashSet<string> folderContentsSet = new HashSet<string>();
|
||||
|
||||
@@ -85,12 +79,7 @@ namespace AssetUsageDetectorNamespace
|
||||
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;
|
||||
@@ -114,6 +103,99 @@ namespace AssetUsageDetectorNamespace
|
||||
return obj is DefaultAsset && AssetDatabase.IsValidFolder( AssetDatabase.GetAssetPath( obj ) );
|
||||
}
|
||||
|
||||
public static T GetPrefabParent<T>( this T obj ) where T : Object
|
||||
{
|
||||
return PrefabUtility.GetCorrespondingObjectFromSource( obj );
|
||||
}
|
||||
|
||||
public static bool HasAnyPrefabOverrides( this Object obj )
|
||||
{
|
||||
if( obj.GetPrefabParent() == null )
|
||||
return false;
|
||||
|
||||
return prefabHasAnyOverridesGetter( obj, false );
|
||||
}
|
||||
|
||||
public static bool HasAnyPrefabOverrides( this GameObject gameObject )
|
||||
{
|
||||
if( gameObject.GetPrefabParent() == null )
|
||||
return false;
|
||||
|
||||
if( !PrefabUtility.HasPrefabInstanceAnyOverrides( gameObject, false ) )
|
||||
return false;
|
||||
|
||||
Transform rootTransform = gameObject.transform;
|
||||
List<Component> components = new List<Component>( 8 );
|
||||
Stack<Transform> stack = new Stack<Transform>( 8 );
|
||||
stack.Push( rootTransform );
|
||||
|
||||
while( stack.Count > 0 )
|
||||
{
|
||||
Transform transform = stack.Pop();
|
||||
Transform prefab = transform.GetPrefabParent();
|
||||
if( prefab == null ) // GameObject is added as override
|
||||
return true;
|
||||
|
||||
if( transform.childCount != prefab.childCount ) // Has some added/destroyed children as override
|
||||
return true;
|
||||
|
||||
bool isRootTransform = ReferenceEquals( transform, rootTransform );
|
||||
if( !isRootTransform && ( transform.gameObject as Object ).HasAnyPrefabOverrides() ) // GameObject's properties are modified (e.g. name or tag) (excluding root GameObject)
|
||||
return true;
|
||||
|
||||
components.Clear();
|
||||
transform.GetComponents( components );
|
||||
foreach( Component component in components )
|
||||
{
|
||||
if( component == null )
|
||||
continue;
|
||||
|
||||
if( component.GetPrefabParent() == null ) // Component is added as override
|
||||
return true;
|
||||
|
||||
if( ( !isRootTransform || !( component is Transform ) ) && component.HasAnyPrefabOverrides() ) // Component is modified (excluding root Transform)
|
||||
return true;
|
||||
}
|
||||
|
||||
int componentCount = components.Count;
|
||||
components.Clear();
|
||||
prefab.GetComponents( components );
|
||||
if( components.Count != componentCount ) // Has some destroyed components as override
|
||||
return true;
|
||||
|
||||
for( int i = 0, childCount = transform.childCount; i < childCount; i++ )
|
||||
{
|
||||
Transform child = transform.GetChild( i );
|
||||
if( child != null )
|
||||
stack.Push( child );
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
#if UNITY_6000_3_OR_NEWER
|
||||
public static EntityId GetEntityId(this Object obj)
|
||||
{
|
||||
return obj.GetEntityId();
|
||||
}
|
||||
|
||||
public static Object EntityIdToObject(EntityId entityId)
|
||||
{
|
||||
return EditorUtility.EntityIdToObject(entityId);
|
||||
}
|
||||
#else
|
||||
public static int GetEntityId(this Object obj)
|
||||
{
|
||||
return obj.GetInstanceID();
|
||||
}
|
||||
|
||||
public static Object EntityIdToObject(int instanceID)
|
||||
{
|
||||
return EditorUtility.InstanceIDToObject(instanceID);
|
||||
}
|
||||
#endif
|
||||
|
||||
// Returns an enumerator to iterate through all asset paths in the folder
|
||||
public static IEnumerable<string> EnumerateFolderContents( Object folderAsset )
|
||||
{
|
||||
@@ -151,7 +233,6 @@ namespace AssetUsageDetectorNamespace
|
||||
{
|
||||
// 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;
|
||||
|
||||
PrefabAssetType prefabAssetType = PrefabUtility.GetPrefabAssetType( objTR.gameObject );
|
||||
@@ -159,11 +240,7 @@ namespace AssetUsageDetectorNamespace
|
||||
{
|
||||
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
|
||||
{
|
||||
GameObject prefabStageGO = FollowSymmetricHierarchy( (GameObject) obj, ( (GameObject) obj ).transform.root.gameObject, openPrefabStage.prefabContentsRoot );
|
||||
if( prefabStageGO != null )
|
||||
@@ -172,10 +249,8 @@ namespace AssetUsageDetectorNamespace
|
||||
selection = objTR.gameObject;
|
||||
}
|
||||
}
|
||||
#if UNITY_2019_1_OR_NEWER
|
||||
else if( obj != objTR.gameObject )
|
||||
selection = objTR.gameObject;
|
||||
#endif
|
||||
}
|
||||
else if( prefabAssetType == PrefabAssetType.Model )
|
||||
{
|
||||
@@ -183,11 +258,6 @@ namespace AssetUsageDetectorNamespace
|
||||
while( objTR.parent != null && objTR.parent.parent != null )
|
||||
objTR = objTR.parent;
|
||||
}
|
||||
#else
|
||||
Transform objTR = ( (GameObject) obj ).transform;
|
||||
while( objTR.parent != null && objTR.parent.parent != null )
|
||||
objTR = objTR.parent;
|
||||
#endif
|
||||
|
||||
pingTarget = objTR.gameObject;
|
||||
}
|
||||
@@ -275,89 +345,15 @@ namespace AssetUsageDetectorNamespace
|
||||
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 )
|
||||
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 );
|
||||
}
|
||||
|
||||
// Check if the property is serializable
|
||||
public static bool IsSerializable( this PropertyInfo propertyInfo )
|
||||
{
|
||||
return IsTypeSerializable( propertyInfo.PropertyType );
|
||||
}
|
||||
|
||||
// Check if type is serializable
|
||||
private static bool IsTypeSerializable( Type type )
|
||||
{
|
||||
// see Serialization Rules: https://docs.unity3d.com/Manual/script-Serialization.html
|
||||
if( typeof( Object ).IsAssignableFrom( type ) )
|
||||
return true;
|
||||
|
||||
if( type.IsArray )
|
||||
{
|
||||
if( type.GetArrayRank() != 1 )
|
||||
return false;
|
||||
|
||||
type = type.GetElementType();
|
||||
|
||||
if( typeof( Object ).IsAssignableFrom( type ) )
|
||||
return true;
|
||||
}
|
||||
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;
|
||||
|
||||
type = type.GetGenericArguments()[0];
|
||||
|
||||
if( typeof( Object ).IsAssignableFrom( type ) )
|
||||
return true;
|
||||
#endif
|
||||
}
|
||||
|
||||
#if !UNITY_2020_1_OR_NEWER
|
||||
if( type.IsGenericType )
|
||||
return false;
|
||||
#endif
|
||||
|
||||
return Attribute.IsDefined( type, typeof( SerializableAttribute ), false );
|
||||
}
|
||||
|
||||
// Check if instances of this type should be searched for references
|
||||
public static bool IsIgnoredUnityType( this Type type )
|
||||
{
|
||||
if( type.IsPrimitive || primitiveUnityTypes.Contains( type ) || type.IsEnum )
|
||||
return true;
|
||||
|
||||
#if UNITY_2018_1_OR_NEWER
|
||||
// Searching NativeArrays for reference can throw InvalidOperationException if the collection is disposed
|
||||
if( type.Namespace == nativeCollectionsNamespace )
|
||||
return true;
|
||||
#endif
|
||||
|
||||
// Searching assembly variables for reference throws InvalidCastException on .NET 4.0 runtime
|
||||
if( typeof( Type ).IsAssignableFrom( type ) || type.Namespace == reflectionNamespace )
|
||||
@@ -446,6 +442,15 @@ namespace AssetUsageDetectorNamespace
|
||||
return stringBuilder.ToString();
|
||||
}
|
||||
|
||||
// Draw header inside OnGUI
|
||||
public static void DrawHeader( string label )
|
||||
{
|
||||
Color c = GUI.backgroundColor;
|
||||
GUI.backgroundColor = AssetUsageDetectorSettings.SettingsHeaderColor;
|
||||
GUILayout.Box( label, BoxGUIStyle, GL_EXPAND_WIDTH );
|
||||
GUI.backgroundColor = c;
|
||||
}
|
||||
|
||||
// Draw horizontal line inside OnGUI
|
||||
public static void DrawSeparatorLine()
|
||||
{
|
||||
@@ -454,14 +459,25 @@ namespace AssetUsageDetectorNamespace
|
||||
GUILayout.Space( 4f );
|
||||
}
|
||||
|
||||
// Restricts the given Rect within the screen's bounds
|
||||
public static Rect GetScreenFittedRect( Rect originalRect )
|
||||
{
|
||||
if( screenFittedRectGetter == null )
|
||||
screenFittedRectGetter = typeof( EditorWindow ).Assembly.GetType( "UnityEditor.ContainerWindow" ).GetMethod( "FitRectToScreen", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static );
|
||||
/// <summary>
|
||||
/// Restricts the given Rect within the screen's bounds.
|
||||
/// </summary>
|
||||
public static Rect GetScreenFittedRect(Rect originalRect, EditorWindow editorWindow)
|
||||
{
|
||||
screenFittedRectGetter ??= typeof(EditorWindow).Assembly.GetType("UnityEditor.ContainerWindow").GetMethod("FitRectToScreen", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
|
||||
|
||||
return (Rect) screenFittedRectGetter.Invoke( null, new object[3] { originalRect, true, true } );
|
||||
}
|
||||
if (screenFittedRectGetter.GetParameters().Length == 3)
|
||||
return (Rect)screenFittedRectGetter.Invoke(null, new object[] { originalRect, true, true });
|
||||
else
|
||||
{
|
||||
// New version introduced in Unity 2022.3.62f1, Unity 6.0.49f1 and Unity 6.1.0f1.
|
||||
// Usage example: https://github.com/Unity-Technologies/UnityCsReference/blob/10f8718268a7e34844ba7d59792117c28d75a99b/Editor/Mono/EditorWindow.cs#L1264
|
||||
editorWindowHostViewGetter ??= typeof(EditorWindow).GetField("m_Parent", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);
|
||||
hostViewContainerWindowGetter ??= typeof(EditorWindow).Assembly.GetType("UnityEditor.HostView").GetProperty("window", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);
|
||||
|
||||
return (Rect)screenFittedRectGetter.Invoke(null, new object[] { originalRect, originalRect.center, true, hostViewContainerWindowGetter.GetValue(editorWindowHostViewGetter.GetValue(editorWindow), null) });
|
||||
}
|
||||
}
|
||||
|
||||
// Check if all the objects inside the list are null
|
||||
public static bool IsEmpty( this List<ObjectToSearch> objectsToSearch )
|
||||
@@ -471,7 +487,7 @@ namespace AssetUsageDetectorNamespace
|
||||
|
||||
for( int i = 0; i < objectsToSearch.Count; i++ )
|
||||
{
|
||||
if( objectsToSearch[i].obj != null && !objectsToSearch[i].obj.Equals( null ) )
|
||||
if( objectsToSearch[i].obj != null )
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -479,38 +495,20 @@ namespace AssetUsageDetectorNamespace
|
||||
}
|
||||
|
||||
// Check if all the objects inside the list are null
|
||||
public static bool IsEmpty( this List<Object> objects )
|
||||
public static bool IsEmpty<T>( this List<T> objects ) where T : Object
|
||||
{
|
||||
if( objects == null )
|
||||
return true;
|
||||
|
||||
for( int i = 0; i < objects.Count; i++ )
|
||||
{
|
||||
if( objects[i] != null && !objects[i].Equals( null ) )
|
||||
if( objects[i] != null )
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// Check if all the objects that are enumerated are null
|
||||
public static bool IsEmpty( this IEnumerable<Object> objects )
|
||||
{
|
||||
if( objects == null )
|
||||
return true;
|
||||
|
||||
using( IEnumerator<Object> enumerator = objects.GetEnumerator() )
|
||||
{
|
||||
while( enumerator.MoveNext() )
|
||||
{
|
||||
if( enumerator.Current != null && !enumerator.Current.Equals( null ) )
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// Returns true is str starts with prefix
|
||||
public static bool StartsWithFast( this string str, string prefix )
|
||||
{
|
||||
|
||||
@@ -9,30 +9,27 @@ namespace AssetUsageDetectorNamespace
|
||||
public delegate object VariableGetVal( object obj );
|
||||
|
||||
// Custom struct to hold a variable, its important properties and its getter function
|
||||
public struct VariableGetterHolder
|
||||
public readonly struct VariableGetterHolder
|
||||
{
|
||||
public readonly MemberInfo variable;
|
||||
public readonly bool isSerializable;
|
||||
private readonly VariableGetVal getter;
|
||||
|
||||
public string Name { get { return variable.Name; } }
|
||||
public bool IsProperty { get { return variable is PropertyInfo; } }
|
||||
public readonly string Name { get { return variable.Name; } }
|
||||
public readonly bool IsProperty { get { return variable is PropertyInfo; } }
|
||||
|
||||
public VariableGetterHolder( FieldInfo fieldInfo, VariableGetVal getter, bool isSerializable )
|
||||
{
|
||||
this.variable = fieldInfo;
|
||||
this.isSerializable = isSerializable;
|
||||
this.getter = getter;
|
||||
}
|
||||
public VariableGetterHolder(FieldInfo fieldInfo, VariableGetVal getter)
|
||||
{
|
||||
this.variable = fieldInfo;
|
||||
this.getter = getter;
|
||||
}
|
||||
|
||||
public VariableGetterHolder( PropertyInfo propertyInfo, VariableGetVal getter, bool isSerializable )
|
||||
{
|
||||
this.variable = propertyInfo;
|
||||
this.isSerializable = isSerializable;
|
||||
this.getter = getter;
|
||||
}
|
||||
public VariableGetterHolder(PropertyInfo propertyInfo, VariableGetVal getter)
|
||||
{
|
||||
this.variable = propertyInfo;
|
||||
this.getter = getter;
|
||||
}
|
||||
|
||||
public object Get( object obj )
|
||||
public readonly object Get( object obj )
|
||||
{
|
||||
try
|
||||
{
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
= Asset Usage Detector (v2.5.4) =
|
||||
= Asset Usage Detector (v2.6.0) =
|
||||
|
||||
Documentation: https://github.com/yasirkula/UnityAssetUsageDetector
|
||||
E-mail: yasirkula@gmail.com
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "com.yasirkula.assetusagedetector",
|
||||
"displayName": "Asset Usage Detector",
|
||||
"version": "2.5.4",
|
||||
"version": "2.6.0",
|
||||
"documentationUrl": "https://github.com/yasirkula/UnityAssetUsageDetector",
|
||||
"changelogUrl": "https://github.com/yasirkula/UnityAssetUsageDetector/releases",
|
||||
"licensesUrl": "https://github.com/yasirkula/UnityAssetUsageDetector/blob/master/LICENSE.txt",
|
||||
|
||||
Reference in New Issue
Block a user