mirror of
https://github.com/yasirkula/UnityAssetUsageDetector.git
synced 2026-11-19 22:42:37 +08:00
Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 6280305a63 | |||
| 5d04e70b7b | |||
| 541e33db89 | |||
| bc3a8069b4 | |||
| 98d1f43180 |
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,182 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using Object = UnityEngine.Object;
|
||||
|
||||
namespace AssetUsageDetectorNamespace
|
||||
{
|
||||
public partial class AssetUsageDetector
|
||||
{
|
||||
#region Helper Classes
|
||||
private class CacheEntry
|
||||
{
|
||||
public enum Result { Unknown = 0, No = 1, Yes = 2 };
|
||||
|
||||
public string hash;
|
||||
public string[] dependencies;
|
||||
public long[] fileSizes;
|
||||
|
||||
public bool verified;
|
||||
public Result searchResult;
|
||||
|
||||
public CacheEntry( string path )
|
||||
{
|
||||
Verify( path );
|
||||
}
|
||||
|
||||
public CacheEntry( string hash, string[] dependencies, long[] fileSizes )
|
||||
{
|
||||
this.hash = hash;
|
||||
this.dependencies = dependencies;
|
||||
this.fileSizes = fileSizes;
|
||||
}
|
||||
|
||||
public void Verify( string path )
|
||||
{
|
||||
string hash = AssetDatabase.GetAssetDependencyHash( path ).ToString();
|
||||
if( this.hash != hash )
|
||||
{
|
||||
this.hash = hash;
|
||||
Refresh( path );
|
||||
}
|
||||
|
||||
verified = true;
|
||||
}
|
||||
|
||||
public void Refresh( string path )
|
||||
{
|
||||
dependencies = AssetDatabase.GetDependencies( path, false );
|
||||
if( fileSizes == null || fileSizes.Length != dependencies.Length )
|
||||
fileSizes = new long[dependencies.Length];
|
||||
|
||||
for( int i = 0; i < dependencies.Length; i++ )
|
||||
{
|
||||
FileInfo assetFile = new FileInfo( dependencies[i] );
|
||||
fileSizes[i] = assetFile.Exists ? assetFile.Length : 0L;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
// An optimization to fetch the dependencies of an asset only once (key is the path of the asset)
|
||||
private Dictionary<string, CacheEntry> assetDependencyCache;
|
||||
private CacheEntry lastRefreshedCacheEntry;
|
||||
|
||||
private string CachePath { get { return Application.dataPath + "/../Library/AssetUsageDetector.cache"; } } // Path of the cache file
|
||||
|
||||
public void SaveCache()
|
||||
{
|
||||
if( assetDependencyCache == null )
|
||||
return;
|
||||
|
||||
try
|
||||
{
|
||||
using( FileStream stream = new FileStream( CachePath, FileMode.Create ) )
|
||||
using( BinaryWriter writer = new BinaryWriter( stream ) )
|
||||
{
|
||||
writer.Write( assetDependencyCache.Count );
|
||||
|
||||
foreach( var keyValuePair in assetDependencyCache )
|
||||
{
|
||||
CacheEntry cacheEntry = keyValuePair.Value;
|
||||
string[] dependencies = cacheEntry.dependencies;
|
||||
long[] fileSizes = cacheEntry.fileSizes;
|
||||
|
||||
writer.Write( keyValuePair.Key );
|
||||
writer.Write( cacheEntry.hash );
|
||||
writer.Write( dependencies.Length );
|
||||
|
||||
for( int i = 0; i < dependencies.Length; i++ )
|
||||
{
|
||||
writer.Write( dependencies[i] );
|
||||
writer.Write( fileSizes[i] );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch( Exception e )
|
||||
{
|
||||
Debug.LogException( e );
|
||||
}
|
||||
}
|
||||
|
||||
private void LoadCache()
|
||||
{
|
||||
if( File.Exists( CachePath ) )
|
||||
{
|
||||
using( FileStream stream = new FileStream( CachePath, FileMode.Open, FileAccess.Read ) )
|
||||
using( BinaryReader reader = new BinaryReader( stream ) )
|
||||
{
|
||||
try
|
||||
{
|
||||
int cacheSize = reader.ReadInt32();
|
||||
assetDependencyCache = new Dictionary<string, CacheEntry>( cacheSize );
|
||||
|
||||
for( int i = 0; i < cacheSize; i++ )
|
||||
{
|
||||
string assetPath = reader.ReadString();
|
||||
string hash = reader.ReadString();
|
||||
|
||||
int dependenciesLength = reader.ReadInt32();
|
||||
string[] dependencies = new string[dependenciesLength];
|
||||
long[] fileSizes = new long[dependenciesLength];
|
||||
for( int j = 0; j < dependenciesLength; j++ )
|
||||
{
|
||||
dependencies[j] = reader.ReadString();
|
||||
fileSizes[j] = reader.ReadInt64();
|
||||
}
|
||||
|
||||
assetDependencyCache[assetPath] = new CacheEntry( hash, dependencies, fileSizes );
|
||||
}
|
||||
}
|
||||
catch( Exception e )
|
||||
{
|
||||
assetDependencyCache = null;
|
||||
Debug.LogWarning( "Couldn't load cache (probably cache format has changed in an update), will regenerate cache.\n" + e.ToString() );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Generate cache for all assets for the first time
|
||||
if( assetDependencyCache == null )
|
||||
{
|
||||
assetDependencyCache = new Dictionary<string, CacheEntry>( 1024 * 8 );
|
||||
|
||||
string[] allAssets = AssetDatabase.GetAllAssetPaths();
|
||||
if( allAssets.Length > 0 )
|
||||
{
|
||||
double startTime = EditorApplication.timeSinceStartup;
|
||||
|
||||
try
|
||||
{
|
||||
for( int i = 0; i < allAssets.Length; i++ )
|
||||
{
|
||||
if( i % 30 == 0 && EditorUtility.DisplayCancelableProgressBar( "Please wait...", "Generating cache for the first time (optional)", (float) i / allAssets.Length ) )
|
||||
{
|
||||
EditorUtility.ClearProgressBar();
|
||||
Debug.LogWarning( "Initial cache generation cancelled, cache will be generated on the fly as more and more assets are searched." );
|
||||
break;
|
||||
}
|
||||
|
||||
assetDependencyCache[allAssets[i]] = new CacheEntry( allAssets[i] );
|
||||
}
|
||||
|
||||
EditorUtility.ClearProgressBar();
|
||||
|
||||
Debug.Log( "Cache generated in " + ( EditorApplication.timeSinceStartup - startTime ).ToString( "F2" ) + " seconds" );
|
||||
Debug.Log( "You can always reset the cache by deleting " + Path.GetFullPath( CachePath ) );
|
||||
|
||||
SaveCache();
|
||||
}
|
||||
catch( Exception e )
|
||||
{
|
||||
EditorUtility.ClearProgressBar();
|
||||
Debug.LogException( e );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 71ea9a3fd0b82594d8130d882dbfc844
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 93aaae685d4c3db44baeb91a0296855e
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -16,6 +16,7 @@ namespace AssetUsageDetectorNamespace
|
||||
|
||||
private const string PREFS_SEARCH_SCENES = "AUD_SceneSearch";
|
||||
private const string PREFS_SEARCH_ASSETS = "AUD_AssetsSearch";
|
||||
private const string PREFS_SEARCH_PROJECT_SETTINGS = "AUD_ProjectSettingsSearch";
|
||||
private const string PREFS_DONT_SEARCH_SOURCE_ASSETS = "AUD_AssetsExcludeSrc";
|
||||
private const string PREFS_SEARCH_DEPTH_LIMIT = "AUD_Depth";
|
||||
private const string PREFS_SEARCH_FIELDS = "AUD_Fields";
|
||||
@@ -42,6 +43,7 @@ namespace AssetUsageDetectorNamespace
|
||||
private bool searchInAllScenes = true; // All scenes (including scenes that are not in build)
|
||||
private bool searchInAssetsFolder = true; // Assets in Project window
|
||||
private bool dontSearchInSourceAssets = true; // objectsToSearch won't be searched for internal references
|
||||
private bool searchInProjectSettings = true; // Player Settings, Graphics Settings etc.
|
||||
|
||||
private List<Object> searchInAssetsSubset = new List<Object>() { null }; // If not empty, only these assets are searched for references
|
||||
private List<Object> excludedAssets = new List<Object>() { null }; // These assets won't be searched for references
|
||||
@@ -69,6 +71,9 @@ namespace AssetUsageDetectorNamespace
|
||||
private readonly ObjectListDrawer excludedAssetsDrawer = new ObjectListDrawer( "Don't search following asset(s):", false );
|
||||
private readonly ObjectListDrawer excludedScenesDrawer = new ObjectListDrawer( "Don't search in following scene(s):", false );
|
||||
|
||||
private readonly GUIContent restoreInitialSceneSetupLabel = new GUIContent( "Restore initial scene setup (Recommended)", "For example, if scene A was open when the search was started and scenes A and B are open after the search is completed, clicking the \"Reset Search\" button will automatically close scene B" );
|
||||
private readonly GUIContent showTooltipsLabel = new GUIContent( "Show tooltips", "Display nodes' contents in a tooltip when cursor hovers over them" );
|
||||
|
||||
private Vector2 scrollPosition = Vector2.zero;
|
||||
|
||||
private bool shouldRepositionSelf;
|
||||
@@ -186,6 +191,7 @@ namespace AssetUsageDetectorNamespace
|
||||
mainWindow.ParseSceneSearchMode( searchParameters.searchInScenes );
|
||||
mainWindow.searchInAssetsFolder = searchParameters.searchInAssetsFolder;
|
||||
mainWindow.dontSearchInSourceAssets = searchParameters.dontSearchInSourceAssets;
|
||||
mainWindow.searchInProjectSettings = searchParameters.searchInProjectSettings;
|
||||
mainWindow.searchDepthLimit = searchParameters.searchDepthLimit;
|
||||
mainWindow.fieldModifiers = searchParameters.fieldModifiers;
|
||||
mainWindow.propertyModifiers = searchParameters.propertyModifiers;
|
||||
@@ -269,6 +275,7 @@ namespace AssetUsageDetectorNamespace
|
||||
EditorPrefs.SetInt( PREFS_SEARCH_SCENES, (int) GetSceneSearchMode( false ) );
|
||||
EditorPrefs.SetBool( PREFS_SEARCH_ASSETS, searchInAssetsFolder );
|
||||
EditorPrefs.SetBool( PREFS_DONT_SEARCH_SOURCE_ASSETS, dontSearchInSourceAssets );
|
||||
EditorPrefs.SetBool( PREFS_SEARCH_PROJECT_SETTINGS, searchInProjectSettings );
|
||||
EditorPrefs.SetInt( PREFS_SEARCH_DEPTH_LIMIT, searchDepthLimit );
|
||||
EditorPrefs.SetInt( PREFS_SEARCH_FIELDS, (int) fieldModifiers );
|
||||
EditorPrefs.SetInt( PREFS_SEARCH_PROPERTIES, (int) propertyModifiers );
|
||||
@@ -285,6 +292,7 @@ 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 );
|
||||
|
||||
// Fetch public, protected and private non-static fields and properties from objects by default
|
||||
@@ -366,7 +374,7 @@ namespace AssetUsageDetectorNamespace
|
||||
// If we are stuck at this phase, then we have encountered an exception
|
||||
GUILayout.Label( ". . . Search in progress or something went wrong (check console) . . ." );
|
||||
|
||||
restoreInitialSceneSetup = EditorGUILayout.ToggleLeft( "Restore initial scene setup (Recommended)", restoreInitialSceneSetup );
|
||||
restoreInitialSceneSetup = EditorGUILayout.ToggleLeft( restoreInitialSceneSetupLabel, restoreInitialSceneSetup );
|
||||
|
||||
if( GUILayout.Button( "RETURN", Utilities.GL_HEIGHT_30 ) )
|
||||
ReturnToSetupPhase( restoreInitialSceneSetup );
|
||||
@@ -378,8 +386,13 @@ namespace AssetUsageDetectorNamespace
|
||||
|
||||
GUILayout.Space( 10 );
|
||||
|
||||
Color c = GUI.color;
|
||||
GUI.color = Color.cyan;
|
||||
|
||||
GUILayout.Box( "SEARCH IN", Utilities.BoxGUIStyle, Utilities.GL_EXPAND_WIDTH );
|
||||
|
||||
GUI.color = c;
|
||||
|
||||
searchInAssetsFolder = EditorGUILayout.ToggleLeft( "Project window (Assets folder)", searchInAssetsFolder );
|
||||
|
||||
if( searchInAssetsFolder )
|
||||
@@ -397,7 +410,7 @@ namespace AssetUsageDetectorNamespace
|
||||
GUILayout.EndHorizontal();
|
||||
}
|
||||
|
||||
GUILayout.Space( 10 );
|
||||
Utilities.DrawSeparatorLine();
|
||||
|
||||
if( searchInAllScenes && !EditorApplication.isPlaying )
|
||||
GUI.enabled = false;
|
||||
@@ -433,6 +446,10 @@ namespace AssetUsageDetectorNamespace
|
||||
GUILayout.EndVertical();
|
||||
GUILayout.EndHorizontal();
|
||||
|
||||
Utilities.DrawSeparatorLine();
|
||||
|
||||
searchInProjectSettings = EditorGUILayout.ToggleLeft( "Project Settings (Player Settings, Graphics Settings etc.)", searchInProjectSettings );
|
||||
|
||||
GUILayout.Space( 10 );
|
||||
|
||||
//GUILayout.Box( "SEARCH SETTINGS", Utilities.BoxGUIStyle, Utilities.GL_EXPAND_WIDTH );
|
||||
@@ -487,8 +504,12 @@ namespace AssetUsageDetectorNamespace
|
||||
|
||||
//GUILayout.Space( 10 );
|
||||
|
||||
GUI.color = Color.cyan;
|
||||
|
||||
GUILayout.Box( "SETTINGS", Utilities.BoxGUIStyle, Utilities.GL_EXPAND_WIDTH );
|
||||
|
||||
GUI.color = c;
|
||||
|
||||
lazySceneSearch = EditorGUILayout.ToggleLeft( "Lazy scene search: scenes are searched in detail only when they are manually refreshed (faster search)", lazySceneSearch );
|
||||
noAssetDatabaseChanges = EditorGUILayout.ToggleLeft( "I haven't modified any assets/scenes since the last search (faster search)", noAssetDatabaseChanges );
|
||||
showDetailedProgressBar = EditorGUILayout.ToggleLeft( "Show detailed progress bar (slower search)", showDetailedProgressBar );
|
||||
@@ -496,11 +517,14 @@ namespace AssetUsageDetectorNamespace
|
||||
GUILayout.Space( 10 );
|
||||
|
||||
// Don't let the user press the GO button without any valid search location
|
||||
if( !searchInAllScenes && !searchInOpenScenes && !searchInScenesInBuild && !searchInAssetsFolder )
|
||||
if( !searchInAllScenes && !searchInOpenScenes && !searchInScenesInBuild && !searchInAssetsFolder && !searchInProjectSettings )
|
||||
GUI.enabled = false;
|
||||
|
||||
if( GUILayout.Button( "GO!", Utilities.GL_HEIGHT_30 ) )
|
||||
{
|
||||
InitiateSearch();
|
||||
GUIUtility.ExitGUI();
|
||||
}
|
||||
}
|
||||
else if( currentPhase == Phase.Complete )
|
||||
{
|
||||
@@ -512,7 +536,7 @@ namespace AssetUsageDetectorNamespace
|
||||
GUILayout.Space( 10 );
|
||||
GUI.enabled = true;
|
||||
|
||||
restoreInitialSceneSetup = EditorGUILayout.ToggleLeft( "Restore initial scene setup after search is reset (Recommended)", restoreInitialSceneSetup );
|
||||
restoreInitialSceneSetup = EditorGUILayout.ToggleLeft( restoreInitialSceneSetupLabel, restoreInitialSceneSetup );
|
||||
|
||||
if( GUILayout.Button( "Reset Search", Utilities.GL_HEIGHT_30 ) )
|
||||
ReturnToSetupPhase( restoreInitialSceneSetup );
|
||||
@@ -560,11 +584,11 @@ namespace AssetUsageDetectorNamespace
|
||||
|
||||
//GUILayout.Space( 10 );
|
||||
|
||||
searchResultDrawParameters.showTooltips = EditorGUILayout.ToggleLeft( "Show tooltips", searchResultDrawParameters.showTooltips );
|
||||
searchResultDrawParameters.showTooltips = EditorGUILayout.ToggleLeft( showTooltipsLabel, searchResultDrawParameters.showTooltips );
|
||||
noAssetDatabaseChanges = EditorGUILayout.ToggleLeft( "I haven't modified any assets/scenes since the last search (faster Refresh)", noAssetDatabaseChanges );
|
||||
searchResultDrawParameters.noAssetDatabaseChanges = noAssetDatabaseChanges;
|
||||
|
||||
GUILayout.Space( 10 );
|
||||
Utilities.DrawSeparatorLine();
|
||||
|
||||
GUILayout.Label( "Path drawing mode:" );
|
||||
|
||||
@@ -590,7 +614,7 @@ namespace AssetUsageDetectorNamespace
|
||||
|
||||
GUILayout.Space( 35 );
|
||||
|
||||
if( EditorGUILayout.ToggleLeft( "Shortest: Draw only the last two nodes of complete paths", searchResultDrawParameters.pathDrawingMode == PathDrawingMode.Shortest ) )
|
||||
if( EditorGUILayout.ToggleLeft( "Shortest: Draw only the last two nodes of the complete paths", searchResultDrawParameters.pathDrawingMode == PathDrawingMode.Shortest ) )
|
||||
searchResultDrawParameters.pathDrawingMode = PathDrawingMode.Shortest;
|
||||
|
||||
GUILayout.EndHorizontal();
|
||||
@@ -636,6 +660,7 @@ namespace AssetUsageDetectorNamespace
|
||||
excludedAssetsFromSearch = !excludedAssets.IsEmpty() ? excludedAssets.ToArray() : null,
|
||||
dontSearchInSourceAssets = dontSearchInSourceAssets,
|
||||
excludedScenesFromSearch = !excludedScenes.IsEmpty() ? excludedScenes.ToArray() : null,
|
||||
searchInProjectSettings = searchInProjectSettings,
|
||||
//fieldModifiers = fieldModifiers,
|
||||
//propertyModifiers = propertyModifiers,
|
||||
//searchDepthLimit = searchDepthLimit,
|
||||
@@ -665,7 +690,7 @@ namespace AssetUsageDetectorNamespace
|
||||
Object obj = objectsToSearch[i].obj;
|
||||
if( obj != null && !obj.Equals( null ) && obj is GameObject && prefabStage.IsPartOfPrefabContents( (GameObject) obj ) )
|
||||
{
|
||||
GameObject prefabStageObjectSource = ( (GameObject) obj ).FollowSymmetricHierarchy( prefabAsset );
|
||||
GameObject prefabStageObjectSource = ( (GameObject) obj ).FollowSymmetricHierarchy( prefabStage.prefabContentsRoot, prefabAsset );
|
||||
if( prefabStageObjectSource != null )
|
||||
objectsToSearch[i].obj = prefabStageObjectSource;
|
||||
|
||||
@@ -675,7 +700,7 @@ namespace AssetUsageDetectorNamespace
|
||||
obj = subAssets[j].subAsset;
|
||||
if( obj != null && !obj.Equals( null ) && obj is GameObject && prefabStage.IsPartOfPrefabContents( (GameObject) obj ) )
|
||||
{
|
||||
prefabStageObjectSource = ( (GameObject) obj ).FollowSymmetricHierarchy( prefabAsset );
|
||||
prefabStageObjectSource = ( (GameObject) obj ).FollowSymmetricHierarchy( prefabStage.prefabContentsRoot, prefabAsset );
|
||||
if( prefabStageObjectSource != null )
|
||||
subAssets[j].subAsset = prefabStageObjectSource;
|
||||
}
|
||||
|
||||
@@ -127,6 +127,7 @@ namespace AssetUsageDetectorNamespace
|
||||
Object[] searchInScenesSubset = m_searchParameters.searchInScenesSubset;
|
||||
bool searchInAssetsFolder = m_searchParameters.searchInAssetsFolder;
|
||||
Object[] searchInAssetsSubset = m_searchParameters.searchInAssetsSubset;
|
||||
bool searchInProjectSettings = m_searchParameters.searchInProjectSettings;
|
||||
|
||||
try
|
||||
{
|
||||
@@ -134,6 +135,15 @@ namespace AssetUsageDetectorNamespace
|
||||
{
|
||||
m_searchParameters.searchInScenes = SceneSearchMode.None;
|
||||
m_searchParameters.searchInScenesSubset = null;
|
||||
m_searchParameters.searchInProjectSettings = false;
|
||||
}
|
||||
else if( searchResultGroup.Type == SearchResultGroup.GroupType.ProjectSettings )
|
||||
{
|
||||
m_searchParameters.searchInScenes = SceneSearchMode.None;
|
||||
m_searchParameters.searchInScenesSubset = null;
|
||||
m_searchParameters.searchInAssetsFolder = false;
|
||||
m_searchParameters.searchInAssetsSubset = null;
|
||||
m_searchParameters.searchInProjectSettings = true;
|
||||
}
|
||||
else if( searchResultGroup.Type == SearchResultGroup.GroupType.Scene )
|
||||
{
|
||||
@@ -141,6 +151,7 @@ namespace AssetUsageDetectorNamespace
|
||||
m_searchParameters.searchInScenesSubset = new Object[1] { AssetDatabase.LoadAssetAtPath<SceneAsset>( searchResultGroup.Title ) };
|
||||
m_searchParameters.searchInAssetsFolder = false;
|
||||
m_searchParameters.searchInAssetsSubset = null;
|
||||
m_searchParameters.searchInProjectSettings = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -148,6 +159,7 @@ namespace AssetUsageDetectorNamespace
|
||||
m_searchParameters.searchInScenesSubset = null;
|
||||
m_searchParameters.searchInAssetsFolder = false;
|
||||
m_searchParameters.searchInAssetsSubset = null;
|
||||
m_searchParameters.searchInProjectSettings = false;
|
||||
}
|
||||
|
||||
m_searchParameters.lazySceneSearch = false;
|
||||
@@ -188,6 +200,7 @@ namespace AssetUsageDetectorNamespace
|
||||
m_searchParameters.searchInScenesSubset = searchInScenesSubset;
|
||||
m_searchParameters.searchInAssetsFolder = searchInAssetsFolder;
|
||||
m_searchParameters.searchInAssetsSubset = searchInAssetsSubset;
|
||||
m_searchParameters.searchInProjectSettings = searchInProjectSettings;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -413,7 +426,7 @@ namespace AssetUsageDetectorNamespace
|
||||
// Custom class to hold the results for a single scene or Assets folder
|
||||
public class SearchResultGroup
|
||||
{
|
||||
public enum GroupType { Assets = 0, Scene = 1, DontDestroyOnLoad = 2 };
|
||||
public enum GroupType { Assets = 0, Scene = 1, DontDestroyOnLoad = 2, ProjectSettings = 3 };
|
||||
|
||||
// Custom struct to hold a single path to a reference
|
||||
public struct ReferencePath
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
#if UNITY_2018_1_OR_NEWER
|
||||
using Unity.Collections;
|
||||
#endif
|
||||
@@ -46,6 +47,8 @@ namespace AssetUsageDetectorNamespace
|
||||
|
||||
private static readonly HashSet<string> folderContentsSet = new HashSet<string>();
|
||||
|
||||
private static readonly StringBuilder stringBuilder = new StringBuilder( 10 );
|
||||
|
||||
#if UNITY_2018_3_OR_NEWER
|
||||
private static int previousPingedPrefabInstanceId;
|
||||
private static double previousPingedPrefabPingTime;
|
||||
@@ -57,6 +60,7 @@ namespace AssetUsageDetectorNamespace
|
||||
public static readonly GUILayoutOption GL_WIDTH_100 = GUILayout.Width( 100 );
|
||||
public static readonly GUILayoutOption GL_WIDTH_250 = GUILayout.Width( 250 );
|
||||
public static readonly GUILayoutOption GL_HEIGHT_0 = GUILayout.Height( 0 );
|
||||
public static readonly GUILayoutOption GL_HEIGHT_2 = GUILayout.Height( 2 );
|
||||
public static readonly GUILayoutOption GL_HEIGHT_30 = GUILayout.Height( 30 );
|
||||
public static readonly GUILayoutOption GL_HEIGHT_35 = GUILayout.Height( 35 );
|
||||
public static readonly GUILayoutOption GL_HEIGHT_40 = GUILayout.Height( 40 );
|
||||
@@ -105,7 +109,7 @@ namespace AssetUsageDetectorNamespace
|
||||
|
||||
if( normalState.background == null || normalState.background.Equals( null ) )
|
||||
{
|
||||
Texture2D backgroundTexture = new Texture2D( 1, 1 );
|
||||
Texture2D backgroundTexture = new Texture2D( 1, 1 ) { hideFlags = HideFlags.HideAndDontSave };
|
||||
backgroundTexture.SetPixel( 0, 0, new Color( 0.88f, 0.88f, 0.88f, 0.85f ) );
|
||||
backgroundTexture.Apply();
|
||||
|
||||
@@ -246,7 +250,7 @@ namespace AssetUsageDetectorNamespace
|
||||
|
||||
if( openPrefabStage != null && openPrefabStage.stageHandle.IsValid() && assetPath == openPrefabStage.prefabAssetPath )
|
||||
{
|
||||
GameObject prefabStageGO = FollowSymmetricHierarchy( (GameObject) obj, openPrefabStage.prefabContentsRoot );
|
||||
GameObject prefabStageGO = FollowSymmetricHierarchy( (GameObject) obj, ( (GameObject) obj ).transform.root.gameObject, openPrefabStage.prefabContentsRoot );
|
||||
if( prefabStageGO != null )
|
||||
{
|
||||
objTR = prefabStageGO.transform;
|
||||
@@ -277,10 +281,12 @@ namespace AssetUsageDetectorNamespace
|
||||
return selection;
|
||||
}
|
||||
|
||||
public static GameObject FollowSymmetricHierarchy( this GameObject go, GameObject symmetricRoot )
|
||||
// We are passing "go"s root Transform to thisRoot parameter. If we use go.transform.root instead, when we are in prefab mode on
|
||||
// newer Unity versions, it points to the preview scene at the root of the prefab stage instead of pointing to the actual root of "go"
|
||||
public static GameObject FollowSymmetricHierarchy( this GameObject go, GameObject thisRoot, GameObject symmetricRoot )
|
||||
{
|
||||
Transform target = go.transform;
|
||||
Transform root1 = target.root;
|
||||
Transform root1 = thisRoot.transform;
|
||||
Transform root2 = symmetricRoot.transform;
|
||||
while( root1 != target )
|
||||
{
|
||||
@@ -426,6 +432,34 @@ namespace AssetUsageDetectorNamespace
|
||||
return true;
|
||||
}
|
||||
|
||||
// Returns file extension in lowercase (period not included)
|
||||
public static string GetFileExtension( string path )
|
||||
{
|
||||
int extensionIndex = path.LastIndexOf( '.' );
|
||||
if( extensionIndex < 0 || extensionIndex >= path.Length - 1 )
|
||||
return "";
|
||||
|
||||
stringBuilder.Length = 0;
|
||||
for( extensionIndex++; extensionIndex < path.Length; extensionIndex++ )
|
||||
{
|
||||
char ch = path[extensionIndex];
|
||||
if( ch >= 65 && ch <= 90 ) // A-Z
|
||||
ch += (char) 32; // Converted to a-z
|
||||
|
||||
stringBuilder.Append( ch );
|
||||
}
|
||||
|
||||
return stringBuilder.ToString();
|
||||
}
|
||||
|
||||
// Draw horizontal line inside OnGUI
|
||||
public static void DrawSeparatorLine()
|
||||
{
|
||||
GUILayout.Space( 4 );
|
||||
GUILayout.Box( "", GL_HEIGHT_2, GL_EXPAND_WIDTH );
|
||||
GUILayout.Space( 4 );
|
||||
}
|
||||
|
||||
// Check if all the objects inside the list are null
|
||||
public static bool IsEmpty( this List<ObjectToSearch> objectsToSearch )
|
||||
{
|
||||
@@ -474,6 +508,35 @@ namespace AssetUsageDetectorNamespace
|
||||
return true;
|
||||
}
|
||||
|
||||
// Returns true is str starts with prefix
|
||||
public static bool StartsWithFast( this string str, string prefix )
|
||||
{
|
||||
int aLen = str.Length;
|
||||
int bLen = prefix.Length;
|
||||
int ap = 0; int bp = 0;
|
||||
while( ap < aLen && bp < bLen && str[ap] == prefix[bp] )
|
||||
{
|
||||
ap++;
|
||||
bp++;
|
||||
}
|
||||
|
||||
return bp == bLen;
|
||||
}
|
||||
|
||||
// Returns true is str ends with postfix
|
||||
public static bool EndsWithFast( this string str, string postfix )
|
||||
{
|
||||
int ap = str.Length - 1;
|
||||
int bp = postfix.Length - 1;
|
||||
while( ap >= 0 && bp >= 0 && str[ap] == postfix[bp] )
|
||||
{
|
||||
ap--;
|
||||
bp--;
|
||||
}
|
||||
|
||||
return bp < 0;
|
||||
}
|
||||
|
||||
public static bool ContainsFast<T>( this List<T> list, T element )
|
||||
{
|
||||
if( !( element is ValueType ) )
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "com.yasirkula.assetusagedetector",
|
||||
"displayName": "Asset Usage Detector",
|
||||
"version": "1.7.8",
|
||||
"version": "1.8.2",
|
||||
"description": "This editor extension helps you figure out at which places an asset or GameObject is used, i.e. lists the objects that refer to the asset. It is possible to search for references in the Assets folder (Project view) and/or in the scene(s) of your project. You can also search for references while in Play mode!"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user