void OnGUI() { InitGUI(); EditorGUILayout.BeginHorizontal(GUILayout.Width(960f), min_height); GUILayout.Label("Filter : ", EditorStyles.miniLabel, width_filter); string search = GUILayout.TextField(mSearch.FilterString, style_toolbar_search_text); if (GUILayout.Button("", style_toolbar_search_cancel)) { search = ""; } if (search != mSearch.FilterString) { mSearch.FilterString = search; FilterObjects(); } EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); GUILayout.Label("Asset", style_toolbar_button, width_asset); GUILayout.Label("User", style_toolbar_button, width_user); GUILayout.Label("Node", style_toolbar_button, width_node); GUILayout.Label("Component", style_toolbar_button, width_component); GUILayout.Label("Property", style_toolbar_button, width_property); GUILayout.Label("Denpendency", style_toolbar_button, width_dependency); EditorGUILayout.EndHorizontal(); mScroll = EditorGUILayout.BeginScrollView(mScroll, false, false); const float item_height = 20f; int from = Mathf.FloorToInt(mScroll.y / item_height); int end = Mathf.CeilToInt(position.height / item_height) + from; int len = mFilteredObjects == null ? 0 : mFilteredObjects.Length; for (int i = 0; i < len; i++) { AssetReferencedData ard = mFilteredObjects[i]; int ls = 0; foreach (ReferencedData rdd in ard.referenced) { foreach (ReferenceData rd in rdd.references) { foreach (ReferenceComponent rc in rd.components) { ls += rc.properties.Count; } } } if (ls <= 0) { ls = 1; } if (ard.from + ls < from || ard.from > end) { GUILayout.Space(ls * item_height); continue; } GUILayout.BeginHorizontal(min_height); // asset GUILayout.BeginVertical(style_cn_box, width_asset); float spacels = item_height * (ls - 1) * 0.5f; GUILayout.Space(spacels + 2f); EditorGUILayout.ObjectField(ard.asset, typeof(Object), false); GUILayout.Space(spacels); GUILayout.EndVertical(); if (ard.referenced.Count > 0) { int np = 0; // user np = 0; GUILayout.BeginVertical(width_user); foreach (ReferencedData rdd in ard.referenced) { int ps = 0; foreach (ReferenceData rd in rdd.references) { foreach (ReferenceComponent rc in rd.components) { ps += rc.properties.Count; } } if (ard.from + np >= from && ard.from + np + ps <= end) { GUILayout.BeginVertical(style_cn_box); float space = item_height * (ps - 1) * 0.5f; GUILayout.Space(space + 2f); EditorGUILayout.ObjectField(rdd.mainObject, typeof(Object), false); GUILayout.Space(space); GUILayout.EndVertical(); } else { GUILayout.Space(item_height * ps); } np += ps; } GUILayout.EndVertical(); // node np = 0; GUILayout.BeginVertical(width_node); foreach (ReferencedData rdd in ard.referenced) { foreach (ReferenceData rd in rdd.references) { int ps = 0; foreach (ReferenceComponent rc in rd.components) { ps += rc.properties.Count; } if (ard.from + np >= from && ard.from + np + ps <= end) { GUILayout.BeginVertical(style_cn_box); float space = item_height * (ps - 1) * 0.5f; GUILayout.Space(space + 2f); EditorGUILayout.ObjectField(rd.node, typeof(Object), false); GUILayout.Space(space); GUILayout.EndVertical(); } else { GUILayout.Space(item_height * ps); } np += ps; } } GUILayout.EndVertical(); // component np = 0; GUILayout.BeginVertical(width_component); foreach (ReferencedData rdd in ard.referenced) { foreach (ReferenceData rd in rdd.references) { foreach (ReferenceComponent rc in rd.components) { int ps = rc.properties.Count; if (ard.from + np >= from && ard.from + np + ps <= end) { GUILayout.BeginVertical(style_cn_box); float space = item_height * (ps - 1) * 0.5f; GUILayout.Space(space + 2f); EditorGUILayout.ObjectField(rc.component, typeof(Component), false); GUILayout.Space(space); GUILayout.EndVertical(); } else { GUILayout.Space(item_height * ps); } np += ps; } } } GUILayout.EndVertical(); // property np = 0; GUILayout.BeginVertical(width_property); foreach (ReferencedData rdd in ard.referenced) { foreach (ReferenceData rd in rdd.references) { foreach (ReferenceComponent rc in rd.components) { if (ard.from + np < from || ard.from + np + rc.properties.Count > end) { np += rc.properties.Count; GUILayout.Space(item_height * rc.properties.Count); continue; } foreach (ReferenceProperty rp in rc.properties) { if (ard.from + np >= from && ard.from + np <= end) { EditorGUILayout.BeginHorizontal(style_cn_box); EditorGUILayout.LabelField(rp.propertyPath, min_width); EditorGUILayout.EndHorizontal(); } else { GUILayout.Space(item_height); } np++; } } } } GUILayout.EndVertical(); // dependency np = 0; GUILayout.BeginVertical(width_dependency); foreach (ReferencedData rdd in ard.referenced) { foreach (ReferenceData rd in rdd.references) { foreach (ReferenceComponent rc in rd.components) { if (ard.from + np < from || ard.from + np + rc.properties.Count > end) { np += rc.properties.Count; GUILayout.Space(item_height * rc.properties.Count); continue; } foreach (ReferenceProperty rp in rc.properties) { if (ard.from + np >= from && ard.from + np <= end) { EditorGUILayout.BeginHorizontal(style_cn_box); EditorGUILayout.ObjectField(rp.asset, typeof(Object), false); EditorGUILayout.EndHorizontal(); } else { GUILayout.Space(item_height); } np++; } } } } GUILayout.EndVertical(); } else { GUILayout.BeginVertical(style_cn_box, width_user); EditorGUILayout.LabelField(" ", min_width); GUILayout.EndVertical(); GUILayout.BeginVertical(style_cn_box, width_node); EditorGUILayout.LabelField(" ", min_width); GUILayout.EndVertical(); GUILayout.BeginVertical(style_cn_box, width_component); EditorGUILayout.LabelField(" ", min_width); GUILayout.EndVertical(); GUILayout.BeginVertical(style_cn_box, width_property); EditorGUILayout.LabelField(" ", min_width); GUILayout.EndVertical(); GUILayout.BeginVertical(style_cn_box, width_dependency); EditorGUILayout.LabelField(" ", min_width); GUILayout.EndVertical(); } GUILayout.EndHorizontal(); } EditorGUILayout.EndScrollView(); }
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()); }
void OnGUI() { InitGUI(); EditorGUILayout.BeginHorizontal(GUILayout.Width(1040f), min_height); GUILayout.Label("Filter : ", EditorStyles.miniLabel, width_filter); string search = GUILayout.TextField(mSearch.FilterString, style_toolbar_search_text); if (GUILayout.Button("", style_toolbar_search_cancel)) { search = ""; } if (search != mSearch.FilterString) { mSearch.FilterString = search; FilterObjects(); } EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); GUILayout.Label("Asset", style_toolbar_button, width_asset); GUILayout.Label("Included", style_toolbar_button, width_included); GUILayout.Label("Sub Assets", style_toolbar_button, width_sub_assets); GUILayout.Label("Component", style_toolbar_button, width_comment); GUILayout.Label("User", style_toolbar_button, width_user); EditorGUILayout.EndHorizontal(); mScroll = EditorGUILayout.BeginScrollView(mScroll, false, false); const float item_height = 20f; int from = Mathf.FloorToInt(mScroll.y / item_height); int end = Mathf.CeilToInt(position.height / item_height) + from; int len = mFilteredObjects == null ? 0 : mFilteredObjects.Length; for (int i = 0; i < len; i++) { AssetReferencedData ard = mFilteredObjects[i]; int ls = Mathf.Max(ard.usages.Count, ard.subAssets.Count); if (ard.from + ls < from || ard.from > end) { GUILayout.Space(ls * item_height); continue; } GUILayout.BeginHorizontal(min_height); // asset GUILayout.BeginVertical(style_cn_box, width_asset); float spacels = item_height * (ls - 1) * 0.5f; GUILayout.Space(spacels + 2f); EditorGUILayout.ObjectField(ard.asset, typeof(Object), false); GUILayout.Space(spacels); GUILayout.EndVertical(); // included GUILayout.BeginVertical(style_cn_box, width_included); GUILayout.Space(spacels + 2f); bool included = ard.IsIncluded(); Color cachedColor = GUI.color; if (!included) { GUI.color = Color.red; } EditorGUILayout.LabelField(included ? "YES" : "NO", min_width); GUI.color = cachedColor; GUILayout.Space(spacels); GUILayout.EndVertical(); // sub assets float spacesa = item_height * (ls - ard.subAssets.Count) * 0.5f / ard.subAssets.Count; GUILayout.BeginVertical(min_height, width_sub_assets); foreach (SubAssetData sa in ard.subAssets) { GUILayout.BeginVertical(style_cn_box); GUILayout.Space(spacesa + 2f); EditorGUILayout.ObjectField(sa.asset, typeof(Object), false); GUILayout.Space(spacesa); GUILayout.EndVertical(); } GUILayout.EndVertical(); // commonet GUILayout.BeginVertical(min_height, width_comment); foreach (SubAssetData sa in ard.subAssets) { GUILayout.BeginVertical(style_cn_box); GUILayout.Space(spacesa + 2f); cachedColor = GUI.color; if (sa.commentWarning) { GUI.color = new Color(1f, 0.5f, 0f, 1f); } EditorGUILayout.LabelField(sa.comment, sa.commentBold ? EditorStyles.miniBoldLabel : EditorStyles.miniLabel, min_width); GUI.color = cachedColor; GUILayout.Space(spacesa); GUILayout.EndVertical(); } GUILayout.EndVertical(); // user float spaceur = item_height * (ls - ard.usages.Count); if (ard.usages.Count > 0) { spaceur = spaceur * 0.5f / ard.usages.Count; GUILayout.BeginVertical(width_user); foreach (AssetReferencedData user in ard.usages) { GUILayout.BeginVertical(style_cn_box); GUILayout.Space(spaceur + 2f); GUILayout.BeginHorizontal(); EditorGUILayout.ObjectField(user.asset, typeof(Object), false, width_user_object); if (GUILayout.Button(user.path, EditorStyles.label, min_width)) { EditorGUIUtility.PingObject(AssetDatabase.LoadMainAssetAtPath(user.path)); } GUILayout.EndHorizontal(); GUILayout.Space(spaceur); GUILayout.EndVertical(); } GUILayout.EndVertical(); } else { GUILayout.BeginVertical(style_cn_box, width_user); GUILayout.Space(spaceur); GUILayout.EndVertical(); } GUILayout.EndHorizontal(); } EditorGUILayout.EndScrollView(); }
protected static void CollectDependenciesInPrefab(out PrefabReferenceData[] prds, out AssetReferencedData[] ards) { string[] all = AssetDatabase.GetAllAssetPaths(); float step1 = 0.3f; int len = all.Length; List <AssetReferencedData> ars = new List <AssetReferencedData>(2048); Dictionary <int, AssetReferencedData> instanceId2Asset = new Dictionary <int, AssetReferencedData>(1024); 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; } if (path.LastIndexOf(".unity", System.StringComparison.OrdinalIgnoreCase) == path.Length - 6) { continue; } AssetReferencedData ard = new AssetReferencedData(); ard.path = path; ard.asset = AssetDatabase.LoadMainAssetAtPath(path); ard.assets = AssetDatabase.LoadAllAssetsAtPath(path); ars.Add(ard); foreach (Object obj in ard.assets) { if (obj == null) { continue; } instanceId2Asset.Add(obj.GetInstanceID(), ard); } } string[] prefabs = AssetDatabase.FindAssets("t:prefab"); len = prefabs.Length; List <PrefabReferenceData> prs = new List <PrefabReferenceData>(2048); Stack <Transform> trans = new Stack <Transform>(); List <Component> components = new List <Component>(); for (int i = 0; i < len; i++) { PrefabReferenceData prd = new PrefabReferenceData(); prd.path = AssetDatabase.GUIDToAssetPath(prefabs[i]); prs.Add(prd); float t = Mathf.Lerp(step1, 1f, (i + 0.5f) / len); EditorUtility.DisplayProgressBar("Collecting Dependencies", string.Format("Step 2 ({0} / {1}) {2}", i + 1, len, prd.path), t); prd.asset = AssetDatabase.LoadMainAssetAtPath(prd.path); GameObject go = prd.asset as GameObject; if (go == null) { continue; } trans.Push(go.transform); while (trans.Count > 0) { Transform tt = trans.Pop(); tt.GetComponents <Component>(components); foreach (Component component in components) { if (component == null || component is Transform) { continue; } SerializedObject so = new SerializedObject(component); SerializedProperty p = so.GetIterator(); while (p.NextVisible(true)) { if (p.propertyType != SerializedPropertyType.ObjectReference) { continue; } AssetReferencedData ard; if (!instanceId2Asset.TryGetValue(p.objectReferenceInstanceIDValue, out ard)) { continue; } if (ard == null || ard.path == prd.path) { continue; } AddReferenceData(prd.path, prd.references, component, p, ard.path); ReferencedData rd = null; foreach (ReferencedData trd in ard.referenced) { if (trd.mainObject == prd.asset) { rd = trd; break; } } if (rd == null) { rd = new ReferencedData(); rd.mainObject = prd.asset; ard.referenced.Add(rd); } AddReferenceData(prd.path, rd.references, component, p, ard.path); } } components.Clear(); for (int j = tt.childCount - 1; j >= 0; j--) { trans.Push(tt.GetChild(j)); } } } EditorUtility.ClearProgressBar(); prds = prs.ToArray(); ards = ars.ToArray(); }