@@ -161,9 +161,9 @@ private static string ExtractGUIDFromString( string str )
161161 #endregion
162162
163163 // Dictionary to quickly find the function to search a specific type with
164- private Dictionary < Type , Func < Object , ReferenceNode > > typeToSearchFunction ;
164+ private Dictionary < Type , Func < object , ReferenceNode > > typeToSearchFunction ;
165165 // Dictionary to associate special file extensions with their search functions
166- private Dictionary < string , Func < Object , ReferenceNode > > extensionToSearchFunction ;
166+ private Dictionary < string , Func < object , ReferenceNode > > extensionToSearchFunction ;
167167
168168 // An optimization to fetch & filter fields and properties of a class only once
169169 private readonly Dictionary < Type , VariableGetterHolder [ ] > typeToVariables = new Dictionary < Type , VariableGetterHolder [ ] > ( 4096 ) ;
@@ -199,19 +199,28 @@ private static string ExtractGUIDFromString( string str )
199199
200200 // Unity's internal function that returns a SerializedProperty's corresponding FieldInfo
201201 private delegate FieldInfo FieldInfoGetter ( SerializedProperty p , out Type t ) ;
202- private FieldInfoGetter fieldInfoGetter ;
202+ #if UNITY_2019_3_OR_NEWER
203+ private readonly FieldInfoGetter fieldInfoGetter = ( FieldInfoGetter ) Delegate . CreateDelegate ( typeof ( FieldInfoGetter ) , typeof ( Editor ) . Assembly . GetType ( "UnityEditor.ScriptAttributeUtility" ) . GetMethod ( "GetFieldInfoAndStaticTypeFromProperty" , BindingFlags . Public | BindingFlags . NonPublic | BindingFlags . Static ) ) ;
204+ #else
205+ private readonly FieldInfoGetter fieldInfoGetter = ( FieldInfoGetter ) Delegate . CreateDelegate ( typeof ( FieldInfoGetter ) , typeof ( Editor ) . Assembly . GetType ( "UnityEditor.ScriptAttributeUtility" ) . GetMethod ( "GetFieldInfoFromProperty" , BindingFlags . Public | BindingFlags . NonPublic | BindingFlags . Static ) ) ;
206+ #endif
203207
204208#if ASSET_USAGE_ADDRESSABLES
205- private delegate Sprite [ ] SpriteAtlasPackedSpritesGetter ( SpriteAtlas atlas ) ;
206- private SpriteAtlasPackedSpritesGetter spriteAtlasPackedSpritesGetter ;
207- private PropertyInfo assetReferenceSubObjectTypeGetter ;
209+ 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 ) ) ;
210+ private readonly PropertyInfo assetReferenceSubObjectTypeGetter = typeof ( AssetReference ) . GetProperty ( "SubOjbectType" , BindingFlags . Public | BindingFlags . NonPublic | BindingFlags . Instance ) ;
211+ #endif
212+
213+ #if ASSET_USAGE_VFX_GRAPH
214+ private readonly Func < string , object > vfxResourceGetter = ( Func < string , object > ) Delegate . CreateDelegate ( typeof ( Func < string , object > ) , typeof ( Editor ) . Assembly . GetType ( "UnityEditor.VFX.VisualEffectResource" ) . GetMethod ( "GetResourceAtPath" , BindingFlags . Public | BindingFlags . NonPublic | BindingFlags . Static ) ) ;
215+ private readonly MethodInfo vfxResourceContentsGetter = typeof ( Editor ) . Assembly . GetType ( "UnityEditor.VFX.VisualEffectResource" ) . GetMethod ( "GetContents" , BindingFlags . Public | BindingFlags . NonPublic | BindingFlags . Instance ) ;
216+ private readonly MethodInfo vfxSerializableObjectValueGetter = Array . Find ( Array . Find ( AppDomain . CurrentDomain . GetAssemblies ( ) , ( assembly ) => assembly . GetName ( ) . Name == "Unity.VisualEffectGraph.Editor" ) . GetType ( "UnityEditor.VFX.VFXSerializableObject" ) . GetMethods ( BindingFlags . Public | BindingFlags . NonPublic | BindingFlags . Instance ) , ( methodInfo ) => methodInfo . Name == "Get" && ! methodInfo . IsGenericMethod ) ;
208217#endif
209218
210219 private void InitializeSearchFunctionsData ( Parameters searchParameters )
211220 {
212221 if ( typeToSearchFunction == null )
213222 {
214- typeToSearchFunction = new Dictionary < Type , Func < Object , ReferenceNode > > ( )
223+ typeToSearchFunction = new Dictionary < Type , Func < object , ReferenceNode > > ( )
215224 {
216225 { typeof ( GameObject ) , SearchGameObject } ,
217226 { typeof ( Material ) , SearchMaterial } ,
@@ -234,7 +243,7 @@ private void InitializeSearchFunctionsData( Parameters searchParameters )
234243
235244 if ( extensionToSearchFunction == null )
236245 {
237- extensionToSearchFunction = new Dictionary < string , Func < Object , ReferenceNode > > ( )
246+ extensionToSearchFunction = new Dictionary < string , Func < object , ReferenceNode > > ( )
238247 {
239248 { "compute" , SearchShaderSecondaryAsset } ,
240249 { "cginc" , SearchShaderSecondaryAsset } ,
@@ -250,6 +259,11 @@ private void InitializeSearchFunctionsData( Parameters searchParameters )
250259#if UNITY_2018_1_OR_NEWER
251260 { "shadergraph" , SearchShaderGraph } ,
252261 { "shadersubgraph" , SearchShaderGraph } ,
262+ #endif
263+ #if ASSET_USAGE_VFX_GRAPH
264+ { "vfx" , SearchVFXGraphAsset } ,
265+ { "vfxoperator" , SearchVFXGraphAsset } ,
266+ { "vfxblock" , SearchVFXGraphAsset } ,
253267#endif
254268 } ;
255269 }
@@ -271,6 +285,9 @@ private void InitializeSearchFunctionsData( Parameters searchParameters )
271285#if UNITY_2018_1_OR_NEWER
272286 searchShaderGraphsForSubGraphs = false ;
273287#endif
288+ #if ASSET_USAGE_VFX_GRAPH
289+ bool searchVFXGraphs = false ;
290+ #endif
274291
275292 foreach ( Object obj in objectsToSearchSet )
276293 {
@@ -292,6 +309,10 @@ private void InitializeSearchFunctionsData( Parameters searchParameters )
292309#if UNITY_2017_3_OR_NEWER
293310 else if ( obj is UnityEditorInternal. AssemblyDefinitionAsset )
294311 assemblyDefinitionFilesToSearch [ AssetDatabase . GetAssetPath ( obj ) ] = obj ;
312+ #endif
313+ #if ASSET_USAGE_VFX_GRAPH
314+ else if ( ! searchVFXGraphs && ( obj is Shader || obj is Mesh || obj . GetType ( ) . Name . StartsWithFast ( "PointCache" ) || obj . GetType ( ) . Name == "ShaderGraphVfxAsset" ) )
315+ searchVFXGraphs = true ;
295316#endif
296317 }
297318
@@ -349,23 +370,19 @@ private void InitializeSearchFunctionsData( Parameters searchParameters )
349370 }
350371#endif
351372
352- #if UNITY_2019_3_OR_NEWER
353- MethodInfo fieldInfoGetterMethod = typeof ( Editor ) . Assembly . GetType ( "UnityEditor.ScriptAttributeUtility" ) . GetMethod ( "GetFieldInfoAndStaticTypeFromProperty" , BindingFlags . Public | BindingFlags . NonPublic | BindingFlags . Static ) ;
354- #else
355- MethodInfo fieldInfoGetterMethod = typeof ( Editor ) . Assembly . GetType ( "UnityEditor.ScriptAttributeUtility" ) . GetMethod ( "GetFieldInfoFromProperty" , BindingFlags . Public | BindingFlags . NonPublic | BindingFlags . Static ) ;
356- #endif
357- fieldInfoGetter = ( FieldInfoGetter ) Delegate . CreateDelegate ( typeof ( FieldInfoGetter ) , fieldInfoGetterMethod ) ;
358-
359- #if ASSET_USAGE_ADDRESSABLES
360- MethodInfo spriteAtlasPackedSpritesGetterMethod = typeof ( SpriteAtlasExtensions ) . GetMethod ( "GetPackedSprites" , BindingFlags . Public | BindingFlags . NonPublic | BindingFlags . Static ) ;
361- spriteAtlasPackedSpritesGetter = ( SpriteAtlasPackedSpritesGetter ) Delegate . CreateDelegate ( typeof ( SpriteAtlasPackedSpritesGetter ) , spriteAtlasPackedSpritesGetterMethod ) ;
362- assetReferenceSubObjectTypeGetter = typeof ( AssetReference ) . GetProperty ( "SubOjbectType" , BindingFlags . Public | BindingFlags . NonPublic | BindingFlags . Instance ) ;
373+ #if ASSET_USAGE_VFX_GRAPH
374+ if ( searchTextureReferences || searchVFXGraphs )
375+ {
376+ alwaysSearchedExtensionsSet . Add ( "vfx" ) ;
377+ alwaysSearchedExtensionsSet . Add ( "vfxoperator" ) ;
378+ alwaysSearchedExtensionsSet . Add ( "vfxblock" ) ;
379+ }
363380#endif
364381 }
365382
366- private ReferenceNode SearchGameObject ( Object unityObject )
383+ private ReferenceNode SearchGameObject ( object obj )
367384 {
368- GameObject go = ( GameObject ) unityObject ;
385+ GameObject go = ( GameObject ) obj ;
369386 ReferenceNode referenceNode = PopReferenceNode ( go ) ;
370387
371388 // Check if this GameObject's prefab is one of the selected assets
@@ -397,9 +414,9 @@ private ReferenceNode SearchGameObject( Object unityObject )
397414 return referenceNode ;
398415 }
399416
400- private ReferenceNode SearchComponent ( Object unityObject )
417+ private ReferenceNode SearchComponent ( object obj )
401418 {
402- Component component = ( Component ) unityObject ;
419+ Component component = ( Component ) obj ;
403420
404421 // Ignore Transform component (no object field to search for)
405422 if ( component is Transform )
@@ -610,11 +627,11 @@ private ReferenceNode SearchComponent( Object unityObject )
610627 return referenceNode ;
611628 }
612629
613- private ReferenceNode SearchMaterial ( Object unityObject )
630+ private ReferenceNode SearchMaterial ( object obj )
614631 {
615632 const string TEXTURE_PROPERTY_PREFIX = "m_SavedProperties.m_TexEnvs[" ;
616633
617- Material material = ( Material ) unityObject ;
634+ Material material = ( Material ) obj ;
618635 ReferenceNode referenceNode = PopReferenceNode ( material ) ;
619636
620637 // We used to search only the shader and the Texture properties in this function but it has changed for 2 major reasons:
@@ -689,14 +706,14 @@ private ReferenceNode SearchMaterial( Object unityObject )
689706 }
690707
691708 // Searches default Texture values assigned to shader properties, as well as #include references in shader source code
692- private ReferenceNode SearchShader ( Object unityObject )
709+ private ReferenceNode SearchShader ( object obj )
693710 {
694- Shader shader = ( Shader ) unityObject ;
711+ Shader shader = ( Shader ) obj ;
695712 ReferenceNode referenceNode = PopReferenceNode ( shader ) ;
696713
697714 if ( searchTextureReferences )
698715 {
699- ShaderImporter shaderImporter = AssetImporter . GetAtPath ( AssetDatabase . GetAssetPath ( unityObject ) ) as ShaderImporter ;
716+ ShaderImporter shaderImporter = AssetImporter . GetAtPath ( AssetDatabase . GetAssetPath ( shader ) ) as ShaderImporter ;
700717 if ( shaderImporter != null )
701718 {
702719 int shaderPropertyCount = ShaderUtil . GetPropertyCount ( shader ) ;
@@ -731,20 +748,20 @@ private ReferenceNode SearchShader( Object unityObject )
731748 }
732749
733750 // Searches .compute, .cginc, .cg, .hlsl and .glslinc assets for #include references
734- private ReferenceNode SearchShaderSecondaryAsset ( Object unityObject )
751+ private ReferenceNode SearchShaderSecondaryAsset ( object obj )
735752 {
736753 if ( shaderIncludesToSearchSet . Count == 0 )
737754 return null ;
738755
739- ReferenceNode referenceNode = PopReferenceNode ( unityObject ) ;
756+ ReferenceNode referenceNode = PopReferenceNode ( obj ) ;
740757 SearchShaderSourceCodeForCGIncludes ( referenceNode ) ;
741758 return referenceNode ;
742759 }
743760
744761 // Searches class/interface inheritances and default UnityEngine.Object values assigned to script variables
745- private ReferenceNode SearchMonoScript ( Object unityObject )
762+ private ReferenceNode SearchMonoScript ( object obj )
746763 {
747- MonoScript script = ( MonoScript ) unityObject ;
764+ MonoScript script = ( MonoScript ) obj ;
748765 Type scriptType = script . GetClass ( ) ;
749766 if ( scriptType == null || ( ! scriptType . IsSubclassOf ( typeof ( MonoBehaviour ) ) && ! scriptType . IsSubclassOf ( typeof ( ScriptableObject ) ) ) )
750767 return null ;
@@ -758,7 +775,7 @@ private ReferenceNode SearchMonoScript( Object unityObject )
758775 referenceNode . AddLinkTo ( GetReferenceNode ( monoScriptsToSearch [ i ] ) , monoScriptsToSearchTypes [ i ] . IsInterface ? "Implements interface" : "Extends class" ) ;
759776 }
760777
761- MonoImporter scriptImporter = AssetImporter . GetAtPath ( AssetDatabase . GetAssetPath ( unityObject ) ) as MonoImporter ;
778+ MonoImporter scriptImporter = AssetImporter . GetAtPath ( AssetDatabase . GetAssetPath ( script ) ) as MonoImporter ;
762779 if ( scriptImporter != null )
763780 {
764781 VariableGetterHolder [ ] variables = GetFilteredVariablesForType ( scriptType ) ;
@@ -781,9 +798,9 @@ private ReferenceNode SearchMonoScript( Object unityObject )
781798 return referenceNode ;
782799 }
783800
784- private ReferenceNode SearchAnimatorController ( Object unityObject )
801+ private ReferenceNode SearchAnimatorController ( object obj )
785802 {
786- RuntimeAnimatorController controller = ( RuntimeAnimatorController ) unityObject ;
803+ RuntimeAnimatorController controller = ( RuntimeAnimatorController ) obj ;
787804 ReferenceNode referenceNode = PopReferenceNode ( controller ) ;
788805
789806 if ( controller is AnimatorController )
@@ -845,9 +862,9 @@ private ReferenceNode SearchAnimatorController( Object unityObject )
845862 return referenceNode ;
846863 }
847864
848- private ReferenceNode SearchAnimatorStateMachine ( Object unityObject )
865+ private ReferenceNode SearchAnimatorStateMachine ( object obj )
849866 {
850- AnimatorStateMachine animatorStateMachine = ( AnimatorStateMachine ) unityObject ;
867+ AnimatorStateMachine animatorStateMachine = ( AnimatorStateMachine ) obj ;
851868 ReferenceNode referenceNode = PopReferenceNode ( animatorStateMachine ) ;
852869
853870 ChildAnimatorStateMachine [ ] stateMachines = animatorStateMachine . stateMachines ;
@@ -877,9 +894,9 @@ private ReferenceNode SearchAnimatorStateMachine( Object unityObject )
877894 return referenceNode ;
878895 }
879896
880- private ReferenceNode SearchAnimatorState ( Object unityObject )
897+ private ReferenceNode SearchAnimatorState ( object obj )
881898 {
882- AnimatorState animatorState = ( AnimatorState ) unityObject ;
899+ AnimatorState animatorState = ( AnimatorState ) obj ;
883900 ReferenceNode referenceNode = PopReferenceNode ( animatorState ) ;
884901
885902 referenceNode . AddLinkTo ( SearchObject ( animatorState . motion ) , "Motion" ) ;
@@ -906,15 +923,15 @@ private ReferenceNode SearchAnimatorState( Object unityObject )
906923 return referenceNode ;
907924 }
908925
909- private ReferenceNode SearchAnimatorStateTransition ( Object unityObject )
926+ private ReferenceNode SearchAnimatorStateTransition ( object obj )
910927 {
911928 // Don't search AnimatorStateTransition objects, it will just return duplicate results of SearchAnimatorStateMachine
912- return PopReferenceNode ( unityObject ) ;
929+ return PopReferenceNode ( obj ) ;
913930 }
914931
915- private ReferenceNode SearchBlendTree ( Object unityObject )
932+ private ReferenceNode SearchBlendTree ( object obj )
916933 {
917- BlendTree blendTree = ( BlendTree ) unityObject ;
934+ BlendTree blendTree = ( BlendTree ) obj ;
918935 ReferenceNode referenceNode = PopReferenceNode ( blendTree ) ;
919936
920937 ChildMotion [ ] children = blendTree . children ;
@@ -929,9 +946,9 @@ private ReferenceNode SearchBlendTree( Object unityObject )
929946 return referenceNode ;
930947 }
931948
932- private ReferenceNode SearchAnimationClip ( Object unityObject )
949+ private ReferenceNode SearchAnimationClip ( object obj )
933950 {
934- AnimationClip clip = ( AnimationClip ) unityObject ;
951+ AnimationClip clip = ( AnimationClip ) obj ;
935952 ReferenceNode referenceNode = PopReferenceNode ( clip ) ;
936953
937954 // Get all curves from animation clip
@@ -983,17 +1000,17 @@ private ReferenceNode SearchAnimationClip( Object unityObject )
9831000 }
9841001
9851002 // TerrainData's properties like tree/detail/layer definitions aren't exposed to SerializedObject so use reflection instead
986- private ReferenceNode SearchTerrainData ( Object unityObject )
1003+ private ReferenceNode SearchTerrainData ( object obj )
9871004 {
988- ReferenceNode referenceNode = PopReferenceNode ( unityObject ) ;
1005+ ReferenceNode referenceNode = PopReferenceNode ( obj ) ;
9891006 SearchVariablesWithReflection ( referenceNode ) ;
9901007 return referenceNode ;
9911008 }
9921009
9931010#if UNITY_2017_1_OR_NEWER
994- private ReferenceNode SearchSpriteAtlas ( Object unityObject )
1011+ private ReferenceNode SearchSpriteAtlas ( object obj )
9951012 {
996- SpriteAtlas spriteAtlas = ( SpriteAtlas ) unityObject ;
1013+ SpriteAtlas spriteAtlas = ( SpriteAtlas ) obj ;
9971014 ReferenceNode referenceNode = PopReferenceNode ( spriteAtlas ) ;
9981015
9991016 SerializedObject spriteAtlasSO = new SerializedObject ( spriteAtlas ) ;
@@ -1083,13 +1100,13 @@ private void SearchSpriteAtlas( ReferenceNode referenceNode, Object packedAsset
10831100
10841101#if UNITY_2017_3_OR_NEWER
10851102 // Find references from an Assembly Definition File to its Assembly Definition References
1086- private ReferenceNode SearchAssemblyDefinitionFile ( Object unityObject )
1103+ private ReferenceNode SearchAssemblyDefinitionFile ( object obj )
10871104 {
10881105 if ( assemblyDefinitionFilesToSearch . Count == 0 )
10891106 return null ;
10901107
1091- AssemblyDefinitionReferences assemblyDefinitionFile = JsonUtility . FromJson < AssemblyDefinitionReferences > ( ( ( TextAsset ) unityObject ) . text ) ;
1092- ReferenceNode referenceNode = PopReferenceNode ( unityObject ) ;
1108+ AssemblyDefinitionReferences assemblyDefinitionFile = JsonUtility . FromJson < AssemblyDefinitionReferences > ( ( ( TextAsset ) obj ) . text ) ;
1109+ ReferenceNode referenceNode = PopReferenceNode ( obj ) ;
10931110
10941111 if ( ! string . IsNullOrEmpty ( assemblyDefinitionFile . reference ) )
10951112 {
@@ -1123,15 +1140,15 @@ private ReferenceNode SearchAssemblyDefinitionFile( Object unityObject )
11231140
11241141#if UNITY_2018_1_OR_NEWER
11251142 // Searches Shader Graph assets for references
1126- private ReferenceNode SearchShaderGraph ( Object unityObject )
1143+ private ReferenceNode SearchShaderGraph ( object obj )
11271144 {
11281145 if ( ! searchTextureReferences && ! searchShaderGraphsForSubGraphs && shaderIncludesToSearchSet . Count == 0 )
11291146 return null ;
11301147
1131- ReferenceNode referenceNode = PopReferenceNode ( unityObject ) ;
1148+ ReferenceNode referenceNode = PopReferenceNode ( obj ) ;
11321149
11331150 // Shader Graph assets are JSON files, they must be crawled manually to find references
1134- string graphJson = File . ReadAllText ( AssetDatabase . GetAssetPath ( unityObject ) ) ;
1151+ string graphJson = File . ReadAllText ( AssetDatabase . GetAssetPath ( ( Object ) obj ) ) ;
11351152 if ( graphJson . IndexOf ( "\" m_ObjectId\" " , 0 , Mathf . Min ( 200 , graphJson . Length ) ) >= 0 )
11361153 {
11371154 // New Shader Graph serialization format is used: https://github.com/Unity-Technologies/Graphics/pull/222
@@ -1252,6 +1269,19 @@ private ReferenceNode SearchShaderGraph( Object unityObject )
12521269 }
12531270#endif
12541271
1272+ #if ASSET_USAGE_VFX_GRAPH
1273+ private ReferenceNode SearchVFXGraphAsset ( object obj )
1274+ {
1275+ ReferenceNode referenceNode = PopReferenceNode ( obj ) ;
1276+
1277+ object vfxResource = vfxResourceGetter ( AssetDatabase . GetAssetPath ( ( Object ) obj ) ) ;
1278+ foreach ( Object vfxResourceContent in ( Object [ ] ) vfxResourceContentsGetter . Invoke ( vfxResource , null ) )
1279+ referenceNode . AddLinkTo ( SearchObject ( vfxResourceContent ) ) ;
1280+
1281+ return referenceNode ;
1282+ }
1283+ #endif
1284+
12551285 // Find references from an Animation/Animator component to the objects that it animates
12561286 private void SearchAnimatedObjects ( ReferenceNode referenceNode )
12571287 {
@@ -1427,14 +1457,23 @@ private void SearchVariablesWithSerializedObject( ReferenceNode referenceNode )
14271457#endif
14281458 case SerializedPropertyType . Generic :
14291459#if ASSET_USAGE_ADDRESSABLES
1430- AssetReference assetReference ;
1431- if ( searchParameters . addressablesSupport && iterator . type . StartsWithFast ( "AssetReference" ) && ( assetReference = GetRawSerializedPropertyValue ( iterator ) as AssetReference ) != null )
1460+ if ( searchParameters . addressablesSupport && iterator . type . StartsWithFast ( "AssetReference" ) && GetRawSerializedPropertyValue ( iterator ) is AssetReference assetReference )
14321461 {
14331462 propertyValue = GetAddressablesAssetReferenceValue ( assetReference ) ;
14341463 searchResult = SearchObject ( PreferablyGameObject ( propertyValue ) ) ;
14351464 enterChildren = false ;
14361465 }
14371466 else
1467+ #endif
1468+ #if ASSET_USAGE_VFX_GRAPH
1469+ if ( vfxSerializableObjectValueGetter != null && iterator . type == "VFXSerializableObject" && GetRawSerializedPropertyValue ( iterator ) is object vfxSerializableObject )
1470+ {
1471+ object vfxSerializableObjectValue = vfxSerializableObjectValueGetter . Invoke ( vfxSerializableObject , null ) ;
1472+ propertyValue = vfxSerializableObjectValue as Object ;
1473+ searchResult = SearchObject ( PreferablyGameObject ( vfxSerializableObjectValue ) ) ;
1474+ enterChildren = false ;
1475+ }
1476+ else
14381477#endif
14391478 {
14401479 propertyValue = null ;
0 commit comments