diff --git a/Plugins/AssetUsageDetector/Editor/AssetUsageDetector.cs b/Plugins/AssetUsageDetector/Editor/AssetUsageDetector.cs index fe7896d..11b7e67 100644 --- a/Plugins/AssetUsageDetector/Editor/AssetUsageDetector.cs +++ b/Plugins/AssetUsageDetector/Editor/AssetUsageDetector.cs @@ -1,6 +1,5 @@ // Asset Usage Detector - by Suleyman Yasir KULA (yasirkula@gmail.com) -using AssetUsageDetectorNamespace.Extras; using UnityEngine; using UnityEditor; using UnityEditor.Animations; diff --git a/Plugins/AssetUsageDetector/Editor/AssetUsageDetectorWindow.cs b/Plugins/AssetUsageDetector/Editor/AssetUsageDetectorWindow.cs index e0cfeb8..81886d8 100644 --- a/Plugins/AssetUsageDetector/Editor/AssetUsageDetectorWindow.cs +++ b/Plugins/AssetUsageDetector/Editor/AssetUsageDetectorWindow.cs @@ -6,7 +6,7 @@ using System.Collections.Generic; using System.Reflection; using Object = UnityEngine.Object; -namespace AssetUsageDetectorNamespace.Extras +namespace AssetUsageDetectorNamespace { public enum Phase { Setup, Processing, Complete }; @@ -26,6 +26,9 @@ namespace AssetUsageDetectorNamespace.Extras private const string PREFS_SHOW_PROGRESS = "AUD_Progress"; private const string PREFS_SHOW_TOOLTIPS = "AUD_Tooltips"; + private static readonly GUIContent windowTitle = new GUIContent( "Asset Usage Detector" ); + private static readonly Vector2 windowMinSize = new Vector2( 325f, 220f ); + private AssetUsageDetector core = new AssetUsageDetector(); private SearchResult searchResult; // Overall search results @@ -38,7 +41,7 @@ namespace AssetUsageDetectorNamespace.Extras private bool searchInScenesInBuildTickedOnly = true; // Scenes in build (ticked only or not) private bool searchInAllScenes = true; // All scenes (including scenes that are not in build) private bool searchInAssetsFolder = true; // Assets in Project window - private bool dontSearchInSourceAssets = false; // objectsToSearch won't be searched for internal references + private bool dontSearchInSourceAssets = true; // objectsToSearch won't be searched for internal references private List searchInAssetsSubset = new List() { null }; // If not empty, only these assets are searched for references private List excludedAssets = new List() { null }; // These assets won't be searched for references @@ -68,17 +71,47 @@ namespace AssetUsageDetectorNamespace.Extras private Vector2 scrollPosition = Vector2.zero; - private static AssetUsageDetectorWindow visibleWindow = null; + private bool shouldRepositionSelf; + private Rect windowTargetPosition; + + private static AssetUsageDetectorWindow mainWindow = null; // Add "Asset Usage Detector" menu item to the Window menu - [MenuItem( "Window/Asset Usage Detector" )] - private static void Init() + [MenuItem( "Window/Asset Usage Detector/Active Window" )] + private static void OpenActiveWindow() { - AssetUsageDetectorWindow window = GetWindow(); - window.titleContent = new GUIContent( "Asset Usage Detector" ); - window.minSize = new Vector2( 325f, 220f ); + if( !mainWindow ) + { + mainWindow = GetWindow(); + mainWindow.titleContent = windowTitle; + mainWindow.minSize = windowMinSize; + } - window.Show(); + mainWindow.Show(); + } + + [MenuItem( "Window/Asset Usage Detector/New Window" )] + private static void OpenNewWindow() + { + Rect? windowTargetPosition = null; + if( mainWindow ) + { + Rect position = mainWindow.position; + position.position += new Vector2( 50f, 50f ); + windowTargetPosition = position; + } + + mainWindow = CreateInstance(); + mainWindow.titleContent = windowTitle; + mainWindow.minSize = windowMinSize; + + if( windowTargetPosition.HasValue ) + { + mainWindow.shouldRepositionSelf = true; + mainWindow.windowTargetPosition = windowTargetPosition.Value; + } + + mainWindow.Show( true ); } // Quickly initiate search for the selected assets @@ -133,57 +166,58 @@ namespace AssetUsageDetectorNamespace.Extras private static void ShowAndSearchInternal( IEnumerable searchObjects, AssetUsageDetector.Parameters searchParameters ) { - if( visibleWindow != null && !visibleWindow.ReturnToSetupPhase( true ) ) + if( mainWindow != null && !mainWindow.ReturnToSetupPhase( true ) ) { Debug.LogError( "Need to reset the previous search first!" ); return; } - Init(); + OpenActiveWindow(); - visibleWindow.objectsToSearch.Clear(); + mainWindow.objectsToSearch.Clear(); if( searchObjects != null ) { foreach( Object obj in searchObjects ) - visibleWindow.objectsToSearch.Add( new ObjectToSearch( obj ) ); + mainWindow.objectsToSearch.Add( new ObjectToSearch( obj ) ); } if( searchParameters != null ) { - visibleWindow.ParseSceneSearchMode( searchParameters.searchInScenes ); - visibleWindow.searchInAssetsFolder = searchParameters.searchInAssetsFolder; - visibleWindow.dontSearchInSourceAssets = searchParameters.dontSearchInSourceAssets; - visibleWindow.searchDepthLimit = searchParameters.searchDepthLimit; - visibleWindow.fieldModifiers = searchParameters.fieldModifiers; - visibleWindow.propertyModifiers = searchParameters.propertyModifiers; - visibleWindow.searchNonSerializableVariables = searchParameters.searchNonSerializableVariables; - visibleWindow.lazySceneSearch = searchParameters.lazySceneSearch; - visibleWindow.noAssetDatabaseChanges = searchParameters.noAssetDatabaseChanges; - visibleWindow.showDetailedProgressBar = searchParameters.showDetailedProgressBar; + mainWindow.ParseSceneSearchMode( searchParameters.searchInScenes ); + mainWindow.searchInAssetsFolder = searchParameters.searchInAssetsFolder; + mainWindow.dontSearchInSourceAssets = searchParameters.dontSearchInSourceAssets; + mainWindow.searchDepthLimit = searchParameters.searchDepthLimit; + mainWindow.fieldModifiers = searchParameters.fieldModifiers; + mainWindow.propertyModifiers = searchParameters.propertyModifiers; + mainWindow.searchNonSerializableVariables = searchParameters.searchNonSerializableVariables; + mainWindow.lazySceneSearch = searchParameters.lazySceneSearch; + mainWindow.noAssetDatabaseChanges = searchParameters.noAssetDatabaseChanges; + mainWindow.showDetailedProgressBar = searchParameters.showDetailedProgressBar; - visibleWindow.searchInAssetsSubset.Clear(); + mainWindow.searchInAssetsSubset.Clear(); if( searchParameters.searchInAssetsSubset != null ) { foreach( Object obj in searchParameters.searchInAssetsSubset ) - visibleWindow.searchInAssetsSubset.Add( obj ); + mainWindow.searchInAssetsSubset.Add( obj ); } - visibleWindow.excludedAssets.Clear(); + mainWindow.excludedAssets.Clear(); if( searchParameters.excludedAssetsFromSearch != null ) { foreach( Object obj in searchParameters.excludedAssetsFromSearch ) - visibleWindow.excludedAssets.Add( obj ); + mainWindow.excludedAssets.Add( obj ); } - visibleWindow.excludedScenes.Clear(); + mainWindow.excludedScenes.Clear(); if( searchParameters.excludedScenesFromSearch != null ) { foreach( Object obj in searchParameters.excludedScenesFromSearch ) - visibleWindow.excludedScenes.Add( obj ); + mainWindow.excludedScenes.Add( obj ); } } - visibleWindow.InitiateSearch(); + mainWindow.InitiateSearch(); + mainWindow.Repaint(); } private void Awake() @@ -193,7 +227,7 @@ namespace AssetUsageDetectorNamespace.Extras private void OnEnable() { - visibleWindow = this; + mainWindow = this; #if UNITY_2018_3_OR_NEWER UnityEditor.Experimental.SceneManagement.PrefabStage.prefabStageClosing -= ReplacePrefabStageObjectsWithAssets; @@ -206,6 +240,9 @@ namespace AssetUsageDetectorNamespace.Extras #if UNITY_2018_3_OR_NEWER UnityEditor.Experimental.SceneManagement.PrefabStage.prefabStageClosing -= ReplacePrefabStageObjectsWithAssets; #endif + + if( mainWindow == this ) + mainWindow = null; } private void OnDestroy() @@ -220,8 +257,11 @@ namespace AssetUsageDetectorNamespace.Extras if( EditorUtility.DisplayDialog( "Scenes", "Restore initial scene setup?", "Yes", "Leave it as is" ) ) searchResult.RestoreInitialSceneSetup(); } + } - visibleWindow = null; + private void OnFocus() + { + mainWindow = this; } private void SavePrefs() @@ -298,6 +338,12 @@ namespace AssetUsageDetectorNamespace.Extras nextPlayModeRefreshTime = EditorApplication.timeSinceStartup + PLAY_MODE_REFRESH_INTERVAL; ; Repaint(); } + + if( shouldRepositionSelf ) + { + shouldRepositionSelf = false; + position = windowTargetPosition; + } } private void OnGUI() diff --git a/Plugins/AssetUsageDetector/Editor/Enumerators.cs b/Plugins/AssetUsageDetector/Editor/Enumerators.cs index f493424..2280128 100644 --- a/Plugins/AssetUsageDetector/Editor/Enumerators.cs +++ b/Plugins/AssetUsageDetector/Editor/Enumerators.cs @@ -2,7 +2,7 @@ using System.Collections.Generic; using UnityEngine; -namespace AssetUsageDetectorNamespace.Extras +namespace AssetUsageDetectorNamespace { public class EmptyEnumerator : IEnumerable, IEnumerator { diff --git a/Plugins/AssetUsageDetector/Editor/ListDrawer.cs b/Plugins/AssetUsageDetector/Editor/ListDrawer.cs index e120415..697706f 100644 --- a/Plugins/AssetUsageDetector/Editor/ListDrawer.cs +++ b/Plugins/AssetUsageDetector/Editor/ListDrawer.cs @@ -2,7 +2,7 @@ using UnityEditor; using UnityEngine; -namespace AssetUsageDetectorNamespace.Extras +namespace AssetUsageDetectorNamespace { public abstract class ListDrawer { diff --git a/Plugins/AssetUsageDetector/Editor/ObjectToSearch.cs b/Plugins/AssetUsageDetector/Editor/ObjectToSearch.cs index aa6e3e3..72803bf 100644 --- a/Plugins/AssetUsageDetector/Editor/ObjectToSearch.cs +++ b/Plugins/AssetUsageDetector/Editor/ObjectToSearch.cs @@ -4,7 +4,7 @@ using UnityEditor; using UnityEngine; using Object = UnityEngine.Object; -namespace AssetUsageDetectorNamespace.Extras +namespace AssetUsageDetectorNamespace { [Serializable] public class ObjectToSearch diff --git a/Plugins/AssetUsageDetector/Editor/SearchResult.cs b/Plugins/AssetUsageDetector/Editor/SearchResult.cs index 414dd52..ef52290 100644 --- a/Plugins/AssetUsageDetector/Editor/SearchResult.cs +++ b/Plugins/AssetUsageDetector/Editor/SearchResult.cs @@ -1,5 +1,4 @@ -using AssetUsageDetectorNamespace.Extras; -using System; +using System; using System.Collections.Generic; using UnityEditor; using UnityEditor.SceneManagement; @@ -629,7 +628,7 @@ namespace AssetUsageDetectorNamespace referencePathsShortUnique = new List( 32 ); for( int i = 0; i < references.Count; i++ ) - references[i].CalculateShortUniquePaths( referencePathsShortUnique ); + references[i].CalculateShortUniquePaths( referencePathsShortUnique, Type == GroupType.Scene || Type == GroupType.DontDestroyOnLoad ); referencePathsShortest = new List( referencePathsShortUnique.Count ); for( int i = 0; i < referencePathsShortUnique.Count; i++ ) @@ -1019,13 +1018,13 @@ namespace AssetUsageDetectorNamespace } // Calculate short unique paths that start with this node - public void CalculateShortUniquePaths( List currentPaths ) + public void CalculateShortUniquePaths( List currentPaths, bool startPathsWithSceneObjects ) { - CalculateShortUniquePaths( currentPaths, new List( 8 ), new List( 8 ) { -1 }, 0, new List( 8 ) ); + CalculateShortUniquePaths( currentPaths, startPathsWithSceneObjects, new List( 8 ), new List( 8 ) { -1 }, 0, new List( 8 ) ); } // Just some boring calculations to find the short unique paths recursively - private void CalculateShortUniquePaths( List shortestPaths, List currentPath, List currentPathIndices, int latestObjectIndexInPath, List stack ) + private void CalculateShortUniquePaths( List shortestPaths, bool startPathsWithSceneObjects, List currentPath, List currentPathIndices, int latestObjectIndexInPath, List stack ) { int currentIndex = currentPath.Count; currentPath.Add( this ); @@ -1066,14 +1065,17 @@ namespace AssetUsageDetectorNamespace else { if( instanceId.HasValue ) // nodeObject is Unity object - latestObjectIndexInPath = currentIndex; + { + if( !startPathsWithSceneObjects || !AssetDatabase.Contains( instanceId.Value ) ) + latestObjectIndexInPath = currentIndex; + } for( int i = 0; i < links.Count; i++ ) { currentPathIndices.Add( i ); stack.Add( this ); - links[i].targetNode.CalculateShortUniquePaths( shortestPaths, currentPath, currentPathIndices, latestObjectIndexInPath, stack ); + links[i].targetNode.CalculateShortUniquePaths( shortestPaths, startPathsWithSceneObjects, currentPath, currentPathIndices, latestObjectIndexInPath, stack ); stack.RemoveAt( stack.Count - 1 ); currentPathIndices.RemoveAt( currentIndex + 1 ); diff --git a/Plugins/AssetUsageDetector/Editor/Utilities.cs b/Plugins/AssetUsageDetector/Editor/Utilities.cs index c60740d..b499ed8 100644 --- a/Plugins/AssetUsageDetector/Editor/Utilities.cs +++ b/Plugins/AssetUsageDetector/Editor/Utilities.cs @@ -10,7 +10,7 @@ using UnityEngine; using UnityEngine.SceneManagement; using Object = UnityEngine.Object; -namespace AssetUsageDetectorNamespace.Extras +namespace AssetUsageDetectorNamespace { public static class Utilities { diff --git a/Plugins/AssetUsageDetector/Editor/VariableGetter.cs b/Plugins/AssetUsageDetector/Editor/VariableGetter.cs index d86da03..7048bea 100644 --- a/Plugins/AssetUsageDetector/Editor/VariableGetter.cs +++ b/Plugins/AssetUsageDetector/Editor/VariableGetter.cs @@ -2,7 +2,7 @@ using System.Reflection; using UnityEngine; -namespace AssetUsageDetectorNamespace.Extras +namespace AssetUsageDetectorNamespace { // Delegate to get the value of a variable (either field or property) public delegate object VariableGetVal( object obj );