From d57a707678b9deaeb1cf12f4cb66178554a35fa2 Mon Sep 17 00:00:00 2001 From: yasirkula Date: Sat, 18 Mar 2023 15:12:13 +0300 Subject: [PATCH] Fixed exceptions while searching for some URP assets' references due to their overriden GetHashCode functions --- .../Editor/AssetUsageDetector.cs | 20 +++++++++---------- .../Editor/SearchResultTreeView.cs | 2 +- Plugins/AssetUsageDetector/README.txt | 2 +- package.json | 2 +- 4 files changed, 13 insertions(+), 13 deletions(-) diff --git a/Plugins/AssetUsageDetector/Editor/AssetUsageDetector.cs b/Plugins/AssetUsageDetector/Editor/AssetUsageDetector.cs index 5b2dab8..cbe2b4d 100644 --- a/Plugins/AssetUsageDetector/Editor/AssetUsageDetector.cs +++ b/Plugins/AssetUsageDetector/Editor/AssetUsageDetector.cs @@ -350,7 +350,7 @@ public SearchResult Run( Parameters searchParameters ) // Initialize the nodes of searched asset(s) foreach( Object obj in objectsToSearchSet ) - searchedUnityObjects.Add( obj.GetHashCode(), PopReferenceNode( obj ) ); + searchedUnityObjects.Add( obj.GetInstanceID(), PopReferenceNode( obj ) ); // Progressbar values int searchProgress = 0; @@ -672,7 +672,7 @@ private void CalculateUnusedObjects( List searchResult, out H else { for( Transform parent = ( (GameObject) obj ).transform.parent; parent != null; parent = parent.parent ) - usedObjectPathsSet.Add( parent.gameObject.GetHashCode().ToString() ); + usedObjectPathsSet.Add( parent.gameObject.GetInstanceID().ToString() ); } } } @@ -739,13 +739,13 @@ private void CalculateUnusedObjects( List searchResult, out H if( !searchedTopmostGameObject ) { if( obj is GameObject ) - unusedMainObjectNodes[obj.GetHashCode().ToString()] = node; + unusedMainObjectNodes[obj.GetInstanceID().ToString()] = node; else currentSearchResultGroup.AddReference( node ); } else // List child GameObject scene objects under their parent GameObject { - string dictionaryKey = searchedTopmostGameObject.GetHashCode().ToString(); + string dictionaryKey = searchedTopmostGameObject.GetInstanceID().ToString(); List unusedSubObjectNodesAtPath; if( !unusedSubObjectNodes.TryGetValue( dictionaryKey, out unusedSubObjectNodesAtPath ) ) unusedSubObjectNodes[dictionaryKey] = unusedSubObjectNodesAtPath = new List( 2 ); @@ -1012,14 +1012,14 @@ private ReferenceNode SearchObject( object obj ) { if( assetsToSearchSet.Count == 0 ) { - searchedUnityObjects.Add( unityObject.GetHashCode(), null ); + searchedUnityObjects.Add( unityObject.GetInstanceID(), null ); return null; } assetPath = AssetDatabase.GetAssetPath( unityObject ); if( excludedAssetsPathsSet.Contains( assetPath ) || !AssetHasAnyReference( assetPath ) ) { - searchedUnityObjects.Add( unityObject.GetHashCode(), null ); + searchedUnityObjects.Add( unityObject.GetInstanceID(), null ); return null; } } @@ -1089,13 +1089,13 @@ private ReferenceNode SearchObject( object obj ) if( !searchingSourceAsset ) { if( obj is Object ) - searchedUnityObjects.Add( unityObject.GetHashCode(), result ); + searchedUnityObjects.Add( unityObject.GetInstanceID(), result ); else searchedObjects.Add( GetNodeObjectHash( obj ), result ); } else if( result != null ) { - result.CopyReferencesTo( searchedUnityObjects[unityObject.GetHashCode()] ); + result.CopyReferencesTo( searchedUnityObjects[unityObject.GetInstanceID()] ); PoolReferenceNode( result ); } } @@ -1229,7 +1229,7 @@ private bool TryGetReferenceNode( object nodeObject, out ReferenceNode reference { if( nodeObject is Object ) { - if( searchedUnityObjects.TryGetValue( nodeObject.GetHashCode(), out referenceNode ) ) + if( searchedUnityObjects.TryGetValue( ( (Object) nodeObject ).GetInstanceID(), out referenceNode ) ) return true; } else if( searchedObjects.TryGetValue( GetNodeObjectHash( nodeObject ), out referenceNode ) ) @@ -1245,7 +1245,7 @@ private ReferenceNode GetReferenceNode( object nodeObject ) ReferenceNode result; if( nodeObject is Object ) { - int hash = nodeObject.GetHashCode(); + int hash = ( (Object) nodeObject ).GetInstanceID(); if( !searchedUnityObjects.TryGetValue( hash, out result ) || result == null ) { result = PopReferenceNode( nodeObject ); diff --git a/Plugins/AssetUsageDetector/Editor/SearchResultTreeView.cs b/Plugins/AssetUsageDetector/Editor/SearchResultTreeView.cs index af48a89..833c28a 100644 --- a/Plugins/AssetUsageDetector/Editor/SearchResultTreeView.cs +++ b/Plugins/AssetUsageDetector/Editor/SearchResultTreeView.cs @@ -299,7 +299,7 @@ private bool GenerateRowsRecursive( TreeViewItem parent, ReferenceNode reference if( linkDescriptions.Count > 0 ) { Object prefabObject = PrefabUtility.GetCorrespondingObjectFromSource( unityObject ); - if( prefabObject && parentData.node.HasLinkToObjectWithDescriptions( prefabObject.GetHashCode(), linkDescriptions ) ) + if( prefabObject && parentData.node.HasLinkToObjectWithDescriptions( prefabObject.GetInstanceID(), linkDescriptions ) ) return false; } } diff --git a/Plugins/AssetUsageDetector/README.txt b/Plugins/AssetUsageDetector/README.txt index 55daf8b..55c4be1 100644 --- a/Plugins/AssetUsageDetector/README.txt +++ b/Plugins/AssetUsageDetector/README.txt @@ -1,4 +1,4 @@ -= Asset Usage Detector (v2.3.0) = += Asset Usage Detector (v2.3.1) = Online documentation available at: https://github.com/yasirkula/UnityAssetUsageDetector E-mail: yasirkula@gmail.com diff --git a/package.json b/package.json index 8e8cc39..35157e1 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "com.yasirkula.assetusagedetector", "displayName": "Asset Usage Detector", - "version": "2.3.0", + "version": "2.3.1", "documentationUrl": "https://github.com/yasirkula/UnityAssetUsageDetector", "changelogUrl": "https://github.com/yasirkula/UnityAssetUsageDetector/releases", "licensesUrl": "https://github.com/yasirkula/UnityAssetUsageDetector/blob/master/LICENSE.txt",