11namespace TypeReferences
22{
33 using System ;
4+ using System . Collections . Generic ;
5+ using System . Diagnostics ;
46 using System . Linq ;
57 using Debug = UnityEngine . Debug ;
68
79#if UNITY_EDITOR
810 using SolidUtilities . Editor ;
911 using UnityEditor ;
12+ using UnityEditor . SceneManagement ;
13+ using UnityEngine ;
14+ using UnityEngine . SceneManagement ;
1015#endif
1116
1217 // This part of the class contains only the methods that are meant to be executed in Editor and not in builds.
@@ -31,7 +36,7 @@ private void UnsubscribeFromDelayCall()
3136 private static string GetGUIDFromType ( Type type )
3237 {
3338#if UNITY_EDITOR
34- return AssetSearcher . GetClassGUID ( type ) ;
39+ return AssetHelper . GetClassGUID ( type ) ;
3540#else
3641 return string . Empty ;
3742#endif
@@ -71,18 +76,30 @@ private void TryUpdatingTypeUsingGUID()
7176#endif
7277 }
7378
74- private void ReportObjectsWithMissingValue ( )
79+ [ Conditional ( "UNITY_EDITOR" ) ]
80+ private static void ReportObjectsWithMissingValue ( string typeName )
7581 {
7682#if UNITY_EDITOR
77- var foundObjects = AssetSearcher . FindObjectsWithValue ( nameof ( _typeNameAndAssembly ) , _typeNameAndAssembly ) ;
78- Debug . Log ( "The value is set in the following objects:" ) ;
83+ bool firstLineLogged = false ;
7984
80- foreach ( FoundObject foundObject in foundObjects )
85+ var serializedObjects = ProjectDependencySearcher . GetSerializedObjectsFromOpenScenes ( new ProjectDependencySearcher . FoundObjects ( ) ) ;
86+ var typeReferenceProperties = SerializedPropertyHelper . FindPropertiesOfType ( serializedObjects , "TypeReference" ) ;
87+
88+ foreach ( var typeReferenceProperty in typeReferenceProperties )
8189 {
82- var details = foundObject
83- . Select ( detail => $ "{ detail . Key } : { detail . Value } ") ;
90+ if ( typeReferenceProperty . FindPropertyRelative ( nameof ( _typeNameAndAssembly ) ) . stringValue != typeName )
91+ continue ;
92+
93+ var targetObject = typeReferenceProperty . serializedObject . targetObject ;
8494
85- Debug . Log ( $ "[{ foundObject . Type } ] { string . Join ( ", " , details ) } ") ;
95+ // Log the first message only if any objects with missing value were found.
96+ if ( ! firstLineLogged )
97+ {
98+ Debug . LogWarning ( $ "'{ typeName } ' was referenced but such type was not found. The value was set in the following objects:") ;
99+ firstLineLogged = true ;
100+ }
101+
102+ Debug . Log ( $ "<a>{ targetObject . name } { ( targetObject is MonoBehaviour ? $ ".{ targetObject . GetType ( ) . Name } " : string . Empty ) } </a>") ;
86103 }
87104#endif
88105 }
0 commit comments