Added support to scan prefabs
This commit is contained in:
parent
269789b36f
commit
591693da1d
11 changed files with 159 additions and 62 deletions
|
|
@ -31,20 +31,21 @@ namespace Module.ProjectValidator.Editor
|
|||
|
||||
internal static GUID GetAssetGuid(Object obj)
|
||||
{
|
||||
var assetGuid = new GUID();
|
||||
|
||||
var assetPath = string.Empty;
|
||||
|
||||
if (obj is GameObject gameObject)
|
||||
{
|
||||
if (gameObject.scene.isLoaded)
|
||||
GUID.TryParse(AssetDatabase.AssetPathToGUID(gameObject.scene.path), out assetGuid);
|
||||
assetPath = gameObject.scene.path;
|
||||
else if (PrefabUtility.IsPartOfPrefabAsset(gameObject))
|
||||
GUID.TryParse(AssetDatabase.AssetPathToGUID(gameObject.scene.path), out assetGuid);
|
||||
assetPath = AssetDatabase.GetAssetPath(gameObject);
|
||||
}
|
||||
else
|
||||
{
|
||||
GUID.TryParse(AssetDatabase.GetAssetPath(obj), out assetGuid);
|
||||
assetPath = AssetDatabase.GetAssetPath(obj);
|
||||
}
|
||||
|
||||
GUID.TryParse(AssetDatabase.AssetPathToGUID(assetPath), out var assetGuid);
|
||||
return assetGuid;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -62,14 +62,17 @@ namespace Module.ProjectValidator.Editor
|
|||
return str;
|
||||
}
|
||||
|
||||
internal static void AppendToScenePath(GameObject gameObject, ref string scenePath)
|
||||
internal static void AppendToRelativePath(GameObject gameObject, ref string relativePath, bool initial)
|
||||
{
|
||||
scenePath = string.IsNullOrEmpty(scenePath) ? gameObject.name : $"{scenePath}/{gameObject.name}";
|
||||
if (string.IsNullOrEmpty(relativePath))
|
||||
relativePath = gameObject.name;
|
||||
else
|
||||
relativePath = initial ? $"{relativePath}{gameObject.name}" : $"{relativePath}/{gameObject.name}";
|
||||
}
|
||||
|
||||
internal static string ApplyRichTextToScenePath(string scenePath)
|
||||
internal static string ApplyRichTextToRelativePath(string relativePath)
|
||||
{
|
||||
return scenePath.Replace("/", "<color=#00ff00><b>/</b></color>");
|
||||
return relativePath.Replace("/", "<color=#00ff00><b>/</b></color>");
|
||||
}
|
||||
|
||||
public static void AppendToFieldPath(FieldInfo fieldInfo, ref string fieldPath)
|
||||
|
|
@ -105,7 +108,7 @@ namespace Module.ProjectValidator.Editor
|
|||
{
|
||||
var scene = SceneManager.GetSceneByPath(assetPath);
|
||||
|
||||
if (scene.isLoaded && TryFindSceneObjectByPath(scene, entry.ScenePath, out var gameObject))
|
||||
if (scene.isLoaded && TryFindSceneObjectByPath(scene, entry.RelativePath, out var gameObject))
|
||||
EditorGUIUtility.PingObject(gameObject);
|
||||
else
|
||||
EditorGUIUtility.PingObject(asset);
|
||||
|
|
@ -116,14 +119,14 @@ namespace Module.ProjectValidator.Editor
|
|||
}
|
||||
}
|
||||
|
||||
private static bool TryFindSceneObjectByPath(Scene scene, string scenePath, out GameObject gameObject)
|
||||
private static bool TryFindSceneObjectByPath(Scene scene, string relativePath, out GameObject gameObject)
|
||||
{
|
||||
using var _ = ListPool<GameObject>.Get(out var rootObjects);
|
||||
scene.GetRootGameObjects(rootObjects);
|
||||
|
||||
var index = scenePath.IndexOf('/');
|
||||
var rootName = index != -1 ? scenePath[..index] : scenePath;
|
||||
var childPath = index != -1 ? scenePath[(index + 1)..] : string.Empty;
|
||||
var index = relativePath.IndexOf('/');
|
||||
var rootName = index != -1 ? relativePath[..index] : relativePath;
|
||||
var childPath = index != -1 ? relativePath[(index + 1)..] : string.Empty;
|
||||
|
||||
for (var i = 0; i < rootObjects.Count; i++)
|
||||
{
|
||||
|
|
@ -212,25 +215,25 @@ namespace Module.ProjectValidator.Editor
|
|||
for (var j = 0; j < rootObjects.Count; j++)
|
||||
{
|
||||
var rootObject = rootObjects[j];
|
||||
var scenePath = string.Empty;
|
||||
RebuildSceneInstanceMapping(report, dictMapping, rootObject, assetGuid, scenePath);
|
||||
var relativePath = string.Empty;
|
||||
RebuildSceneInstanceMapping(report, dictMapping, rootObject, assetGuid, relativePath, true);
|
||||
}
|
||||
}
|
||||
|
||||
RebuildForAllParents(dictMapping);
|
||||
}
|
||||
|
||||
private static void RebuildSceneInstanceMapping(Report report, Dictionary<int, Report.MappingEntry> dictMapping, GameObject gameObject, GUID assetGuid, string scenePath)
|
||||
private static void RebuildSceneInstanceMapping(Report report, Dictionary<int, Report.MappingEntry> dictMapping, GameObject gameObject, GUID assetGuid, string relativePath, bool initial)
|
||||
{
|
||||
var transform = gameObject.transform;
|
||||
AppendToScenePath(gameObject, ref scenePath);
|
||||
AppendToRelativePath(gameObject, ref relativePath, initial);
|
||||
|
||||
if (report.TryGetSeverityFor(assetGuid, scenePath, out var mapping))
|
||||
if (report.TryGetSeverityFor(assetGuid, relativePath, out var mapping))
|
||||
dictMapping.Add(gameObject.GetInstanceID(), new Report.MappingEntry(mapping.Severity, false));
|
||||
|
||||
for (var i = 0; i < transform.childCount; i++)
|
||||
{
|
||||
RebuildSceneInstanceMapping(report, dictMapping, transform.GetChild(i).gameObject, assetGuid, scenePath);
|
||||
RebuildSceneInstanceMapping(report, dictMapping, transform.GetChild(i).gameObject, assetGuid, relativePath, false);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue