Skip to content

Commit 92e8d7e

Browse files
committed
feat: Implemented new algorithm to find the objects with the missing type
1 parent e6f7a38 commit 92e8d7e

File tree

2 files changed

+26
-10
lines changed

2 files changed

+26
-10
lines changed

Runtime/TypeReference.Editor.cs

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
11
namespace 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
}

Runtime/TypeReference.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,8 +182,7 @@ private void LogTypeNotFound()
182182
if (_reportedMissingValues.Contains(_typeNameAndAssembly))
183183
return;
184184

185-
Debug.LogWarning($"'{_typeNameAndAssembly}' was referenced but such type was not found.");
186-
ReportObjectsWithMissingValue();
185+
ReportObjectsWithMissingValue(_typeNameAndAssembly);
187186
_reportedMissingValues.Add(_typeNameAndAssembly);
188187
}
189188

0 commit comments

Comments
 (0)