added unity files
This commit is contained in:
parent
9042333f51
commit
28c15035a4
62 changed files with 3873 additions and 270 deletions
|
|
@ -0,0 +1,98 @@
|
|||
using System.Collections.Generic;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace RunlevelSystems.DevPlus1.EditorTools
|
||||
{
|
||||
public static class RLPrefabAnalyzer
|
||||
{
|
||||
public static List<RLPrefabInfo> AnalyzePrefabs()
|
||||
{
|
||||
List<RLPrefabInfo> results = new List<RLPrefabInfo>();
|
||||
string[] guids = AssetDatabase.FindAssets("t:Prefab");
|
||||
|
||||
foreach (string guid in guids)
|
||||
{
|
||||
string path = AssetDatabase.GUIDToAssetPath(guid);
|
||||
GameObject prefab = AssetDatabase.LoadAssetAtPath<GameObject>(path);
|
||||
if (prefab == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
RLPrefabInfo info = new RLPrefabInfo();
|
||||
info.prefabPath = path;
|
||||
TraversePrefab(prefab, info);
|
||||
results.Add(info);
|
||||
}
|
||||
|
||||
return results;
|
||||
}
|
||||
|
||||
private static void TraversePrefab(GameObject gameObject, RLPrefabInfo info)
|
||||
{
|
||||
info.missingScriptCount += GameObjectUtility.GetMonoBehavioursWithMissingScriptCount(gameObject);
|
||||
|
||||
Component[] components = gameObject.GetComponents<Component>();
|
||||
foreach (Component component in components)
|
||||
{
|
||||
if (component == null)
|
||||
{
|
||||
AddUnique(info.components, "Missing Script");
|
||||
continue;
|
||||
}
|
||||
|
||||
AddUnique(info.components, component.GetType().Name);
|
||||
if (component is MonoBehaviour)
|
||||
{
|
||||
AddUnique(info.attachedScripts, component.GetType().Name);
|
||||
}
|
||||
|
||||
CollectReferences(component, info);
|
||||
}
|
||||
|
||||
string prefabSource = PrefabUtility.GetPrefabAssetPathOfNearestInstanceRoot(gameObject);
|
||||
if (!string.IsNullOrEmpty(prefabSource) && prefabSource != info.prefabPath)
|
||||
{
|
||||
AddUnique(info.nestedPrefabs, prefabSource);
|
||||
}
|
||||
|
||||
foreach (Transform child in gameObject.transform)
|
||||
{
|
||||
TraversePrefab(child.gameObject, info);
|
||||
}
|
||||
}
|
||||
|
||||
private static void CollectReferences(Component component, RLPrefabInfo info)
|
||||
{
|
||||
SerializedObject serializedObject = new SerializedObject(component);
|
||||
SerializedProperty property = serializedObject.GetIterator();
|
||||
bool enterChildren = true;
|
||||
while (property.NextVisible(enterChildren))
|
||||
{
|
||||
enterChildren = false;
|
||||
if (property.propertyType != SerializedPropertyType.ObjectReference)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (property.objectReferenceValue != null)
|
||||
{
|
||||
AddUnique(info.importantReferences, component.GetType().Name + "." + property.displayName + " -> " + property.objectReferenceValue.name);
|
||||
}
|
||||
else if (property.objectReferenceInstanceIDValue != 0)
|
||||
{
|
||||
info.missingReferenceCount++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void AddUnique(List<string> values, string value)
|
||||
{
|
||||
if (!values.Contains(value))
|
||||
{
|
||||
values.Add(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue