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(); }
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("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); GUILayout.Label("Comment", style_toolbar_button, width_comment); 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++) { PrefabReferenceData prd = mFilteredObjects[i]; int ls = 0; foreach (ReferenceData rd in prd.references) { foreach (ReferenceComponent rc in rd.components) { ls += rc.properties.Count; } } if (ls <= 0) { ls = 1; } if (prd.from + ls < from || prd.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(prd.asset, typeof(Object), false); GUILayout.Space(spacels); GUILayout.EndVertical(); if (prd.references.Count > 0) { // node GUILayout.BeginVertical(width_node); foreach (ReferenceData rd in prd.references) { int ps = 0; foreach (ReferenceComponent rc in rd.components) { ps += rc.properties.Count; } 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(); } GUILayout.EndVertical(); // component GUILayout.BeginVertical(width_component); foreach (ReferenceData rd in prd.references) { foreach (ReferenceComponent rc in rd.components) { int ps = rc.properties.Count; 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(); } } GUILayout.EndVertical(); // property GUILayout.BeginVertical(width_property); foreach (ReferenceData rd in prd.references) { foreach (ReferenceComponent rc in rd.components) { foreach (ReferenceProperty rp in rc.properties) { EditorGUILayout.BeginHorizontal(style_cn_box); EditorGUILayout.LabelField(rp.propertyPath, min_width); EditorGUILayout.EndHorizontal(); } } } GUILayout.EndVertical(); // dependency GUILayout.BeginVertical(width_dependency); foreach (ReferenceData rd in prd.references) { foreach (ReferenceComponent rc in rd.components) { foreach (ReferenceProperty rp in rc.properties) { EditorGUILayout.BeginHorizontal(style_cn_box); EditorGUILayout.ObjectField(rp.asset, typeof(Object), false); EditorGUILayout.EndHorizontal(); } } } GUILayout.EndVertical(); // comment GUILayout.BeginVertical(width_comment); foreach (ReferenceData rd in prd.references) { foreach (ReferenceComponent rc in rd.components) { foreach (ReferenceProperty rp in rc.properties) { EditorGUILayout.BeginHorizontal(style_cn_box); Color cachedColor = GUI.color; if (rp.commentWarning) { GUI.color = new Color(1f, 0.5f, 0f, 1f); } EditorGUILayout.LabelField(rp.comment, rp.commentBold ? EditorStyles.miniBoldLabel : EditorStyles.miniLabel, min_width); GUI.color = cachedColor; EditorGUILayout.EndHorizontal(); } } } GUILayout.EndVertical(); } else { 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.BeginVertical(style_cn_box, width_comment); EditorGUILayout.LabelField(" ", min_width); GUILayout.EndVertical(); } GUILayout.EndHorizontal(); } EditorGUILayout.EndScrollView(); }