1- // Asset Usage Detector - by Suleyman Yasir KULA (yasirkula@gmail.com)
2-
31using UnityEngine ;
42using UnityEditor ;
53using UnityEngine . SceneManagement ;
@@ -93,13 +91,9 @@ public class Parameters
9391 private bool searchingSourceAssets ;
9492 private bool isInPlayMode ;
9593
96- #if UNITY_2018_3_OR_NEWER
9794 private PrefabStage openPrefabStage ;
9895 private GameObject openPrefabStagePrefabAsset ;
99- #if UNITY_2020_1_OR_NEWER
10096 private GameObject openPrefabStageContextObject ;
101- #endif
102- #endif
10397
10498 private int searchedObjectsCount ; // Number of searched objects
10599 private double searchStartTime ;
@@ -121,7 +115,6 @@ public SearchResult Run( Parameters searchParameters )
121115 return new SearchResult ( false , null , null , null , this , searchParameters ) ;
122116 }
123117
124- #if UNITY_2018_3_OR_NEWER
125118 openPrefabStagePrefabAsset = null ;
126119 string openPrefabStageAssetPath = null ;
127120 openPrefabStage = PrefabStageUtility . GetCurrentPrefabStage ( ) ;
@@ -138,20 +131,12 @@ public SearchResult Run( Parameters searchParameters )
138131 return new SearchResult ( false , null , null , null , this , searchParameters ) ;
139132 }
140133
141- #if UNITY_2020_1_OR_NEWER
142134 string prefabAssetPath = openPrefabStage . assetPath ;
143- #else
144- string prefabAssetPath = openPrefabStage . prefabAssetPath ;
145- #endif
146135 openPrefabStagePrefabAsset = AssetDatabase . LoadAssetAtPath < GameObject > ( prefabAssetPath ) ;
147136 openPrefabStageAssetPath = prefabAssetPath ;
148-
149- #if UNITY_2020_1_OR_NEWER
150137 openPrefabStageContextObject = openPrefabStage . openedFromInstanceRoot ;
151- #endif
152138 }
153139 }
154- #endif
155140
156141 List < SearchResultGroup > searchResult = null ;
157142 isInPlayMode = EditorApplication . isPlaying ;
@@ -193,9 +178,7 @@ public SearchResult Run( Parameters searchParameters )
193178 excludedAssetsPathsSet . Clear ( ) ;
194179 alwaysSearchedExtensionsSet . Clear ( ) ;
195180 shaderIncludesToSearchSet . Clear ( ) ;
196- #if UNITY_2017_3_OR_NEWER
197181 assemblyDefinitionFilesToSearch . Clear ( ) ;
198- #endif
199182
200183 if ( assetDependencyCache == null )
201184 {
@@ -527,7 +510,6 @@ public SearchResult Run( Parameters searchParameters )
527510 if ( excludedScenesPathsSet . Contains ( scenePath ) )
528511 continue ;
529512
530- #if UNITY_2019_2_OR_NEWER
531513 // Skip scenes in read-only packages (Issue #36)
532514 // Credit: https://forum.unity.com/threads/check-if-asset-inside-package-is-readonly.900902/#post-5990822
533515 if ( ! scenePath . StartsWithFast ( "Assets/" ) )
@@ -536,7 +518,6 @@ public SearchResult Run( Parameters searchParameters )
536518 if ( packageInfo != null && packageInfo . source != UnityEditor . PackageManager . PackageSource . Embedded && packageInfo . source != UnityEditor . PackageManager . PackageSource . Local )
537519 continue ;
538520 }
539- #endif
540521
541522 SearchScene ( scenePath , searchResult , searchParameters , initialSceneSetup ) ;
542523 }
@@ -625,11 +606,9 @@ public SearchResult Run( Parameters searchParameters )
625606 if ( EditorSceneManager . GetActiveScene ( ) != activeScene )
626607 EditorSceneManager . SetActiveScene ( activeScene ) ;
627608
628- #if UNITY_2018_3_OR_NEWER
629609 // If a prefab stage was open when the search was triggered, try reopening the prefab stage after the search is completed
630610 if ( ! string . IsNullOrEmpty ( openPrefabStageAssetPath ) )
631611 {
632- #if UNITY_2020_1_OR_NEWER
633612 bool shouldOpenPrefabStageWithoutContext = true ;
634613 if ( openPrefabStageContextObject != null && ! openPrefabStageContextObject . Equals ( null ) )
635614 {
@@ -647,12 +626,8 @@ public SearchResult Run( Parameters searchParameters )
647626 }
648627
649628 if ( shouldOpenPrefabStageWithoutContext )
650- #endif
651- {
652629 AssetDatabase . OpenAsset ( AssetDatabase . LoadAssetAtPath < GameObject > ( openPrefabStageAssetPath ) ) ;
653- }
654630 }
655- #endif
656631 }
657632 }
658633
@@ -837,15 +812,13 @@ private void AddSearchedObjectToFilteredSets( Object obj, bool expandGameObjects
837812
838813 objectsToSearchSet . Add ( obj ) ;
839814
840- #if UNITY_2018_3_OR_NEWER
841815 // When searching for references of a prefab stage object, try adding its corresponding prefab asset to the searched assets, as well
842816 if ( openPrefabStage != null && openPrefabStagePrefabAsset != null && obj is GameObject && openPrefabStage . IsPartOfPrefabContents ( ( GameObject ) obj ) )
843817 {
844818 GameObject prefabStageObjectSource = ( ( GameObject ) obj ) . FollowSymmetricHierarchy ( openPrefabStage . prefabContentsRoot , openPrefabStagePrefabAsset ) ;
845819 if ( prefabStageObjectSource != null )
846820 AddSearchedObjectToFilteredSets ( prefabStageObjectSource , expandGameObjects ) ;
847821 }
848- #endif
849822
850823 bool isAsset = obj . IsAsset ( ) ;
851824 if ( isAsset )
0 commit comments