private static void AddReferenceData(string path, List <ReferenceData> references, Component component, SerializedProperty p, string dp) { ReferenceData rd = null; Transform node = component.transform; foreach (ReferenceData trd in references) { if (trd.node == node) { rd = trd; break; } } if (rd == null) { rd = new ReferenceData(); rd.node = node; node_path_gen.Clear(); Transform t = node; while (t != null) { node_path_gen.Add(t.name); t = t.parent; } node_path_gen.Reverse(); rd.nodePath = string.Join("/", node_path_gen.ToArray()); references.Add(rd); } ReferenceComponent rc = null; foreach (ReferenceComponent trc in rd.components) { if (trc.component == component) { rc = trc; break; } } if (rc == null) { rc = new ReferenceComponent(); rc.component = component; rc.componentName = component.GetType().FullName; rd.components.Add(rc); } ReferenceProperty rp = new ReferenceProperty(); rp.propertyPath = new GUIContent(p.propertyPath, string.Format("Asset Path :\n {0}\n\nNode Path :\n {1}\n\nComponent :\n {2}\n\nProperty Path :\n {3}\n\nDependency Asset :\n {4}", path, rd.nodePath, rc.componentName, p.propertyPath, dp)); rp.asset = p.objectReferenceValue; rp.comment = AssetComment.GetAssetComment(rp.asset, true, out rp.commentBold, out rp.commentWarning); rc.properties.Add(rp); }
private static AssetReferencedData[] CollectDependencies() { List <string> scenes = new List <string>(); foreach (EditorBuildSettingsScene scene in EditorBuildSettings.scenes) { if (scene.enabled) { scenes.Add(scene.path); } } string[] all = AssetDatabase.GetAllAssetPaths(); float step1 = 0.3f; float step2 = 0.85f; int len = all.Length; List <AssetReferencedData> ars = new List <AssetReferencedData>(2048); Dictionary <string, AssetReferencedData> instanceId2Asset = new Dictionary <string, AssetReferencedData>(2048); for (int i = 0; i < len; i++) { string path = all[i]; float t = Mathf.Lerp(0f, step1, (i + 0.5f) / len); EditorUtility.DisplayProgressBar("Collecting Dependencies", string.Format("Step 1 ({0} / {1}) {2}", i + 1, len, path), t); if (AssetDatabase.IsValidFolder(path)) { continue; } if (!path.StartsWith("Assets/")) { continue; } AssetReferencedData ard = new AssetReferencedData(); ard.path = path; ard.asset = AssetDatabase.LoadMainAssetAtPath(path); bool isScene = path.LastIndexOf(".unity", System.StringComparison.OrdinalIgnoreCase) == path.Length - 6; if (isScene) { ard.included = scenes.Contains(path); } else if (path.Contains("/Resources/") || path.Contains("/Plugins/")) { ard.included = true; } else if (path.LastIndexOf(".dll", System.StringComparison.OrdinalIgnoreCase) == path.Length - 4) { ard.included = true; } else if (ard.asset is MonoScript) { ard.included = true; } else { ard.included = false; } instanceId2Asset.Add(path, ard); ars.Add(ard); } len = ars.Count; for (int i = 0; i < len; i++) { AssetReferencedData user = ars[i]; float t = Mathf.Lerp(step1, step2, (i + 0.5f) / len); EditorUtility.DisplayProgressBar("Collecting Dependencies", string.Format("Step 2 ({0} / {1}) {2}", i + 1, len, user.path), t); string[] dependencies = AssetDatabase.GetDependencies(user.path, false); if (dependencies.Length <= 0) { continue; } foreach (string dependency in dependencies) { AssetReferencedData ard; if (!instanceId2Asset.TryGetValue(dependency, out ard)) { continue; } ard.usages.Add(user); } } for (int i = 0; i < len; i++) { AssetReferencedData ard = ars[i]; string path = ard.path; float t = Mathf.Lerp(step2, 1f, (i + 0.5f) / len); EditorUtility.DisplayProgressBar("Analysing Dependencies", string.Format("Step 3 ({0} / {1}) {2}", i + 1, len, path), t); bool ignoreSpriteNPOT = false; foreach (AssetReferencedData user in ard.usages) { if (user.asset is SpriteAtlas) { ignoreSpriteNPOT = true; break; } } SubAssetData sam = new SubAssetData(); sam.asset = ard.asset; sam.comment = AssetComment.GetAssetComment(sam.asset, ignoreSpriteNPOT, out sam.commentBold, out sam.commentWarning); ard.subAssets.Add(sam); bool isScene = path.LastIndexOf(".unity", System.StringComparison.OrdinalIgnoreCase) == path.Length - 6; bool isPrefab = path.LastIndexOf(".prefab", System.StringComparison.OrdinalIgnoreCase) == path.Length - 7; if (!isScene && !isPrefab) { foreach (Object asset in AssetDatabase.LoadAllAssetRepresentationsAtPath(path)) { if (asset == ard.asset) { continue; } SubAssetData sa = new SubAssetData(); sa.asset = asset; sa.comment = AssetComment.GetAssetComment(asset, ignoreSpriteNPOT, out sa.commentBold, out sa.commentWarning); ard.subAssets.Add(sa); } } } EditorUtility.ClearProgressBar(); return(ars.ToArray()); }