static void SaveHierarchyResult(Object obj, HierarchyResult r) { if (m_HierarchyResults.ContainsKey(obj)) { m_HierarchyResults[obj].Add(r); } else { m_HierarchyResults.Add(obj, new List <HierarchyResult>() { r }); } }
static void CheckGameObject(GameObject go, bool inHierarchy, Object asset = null) { if (m_IsFindingAsset) { if (m_SelectedIsPrefab && PrefabUtility.GetPrefabParent(go) == m_SelectedObj) { if (inHierarchy) { HierarchyResult r = new HierarchyResult() { tip = "<prefab>" }; SaveHierarchyResult(go, r); } else { string childpath = go.name; Transform parent = go.transform.parent; while (parent != null) { childpath = parent.name + " \u27A4 " + childpath; parent = parent.parent; } ProjectResult r = new ProjectResult() { childPath = childpath }; SaveProjectResult(asset, r); } return; } } foreach (Component c in go.GetComponents <Component>()) { CheckReference(c, inHierarchy, asset); } foreach (Transform child in go.transform) { CheckGameObject(child.gameObject, inHierarchy, asset); } }
/// <summary> /// Get the Hierarchy Details /// </summary> /// <returns></returns> public JsonResult GetHierarchyDetails() { HierarchyResult result = oAdminManager.GetHierarchyDetails(CookieManager.GetCookie(CookieManager.CookieName).logindetail.EmpID); return(Json(new { result }, JsonRequestBehavior.AllowGet)); }
void OnResultsInHierarchyGUI() { if (m_HierarchyResults.Count == 0) { return; } EditorGUILayout.BeginVertical("RegionBg"); //header GUILayout.Space(-15); EditorGUILayout.LabelField(m_HierarchyLabelIcon, m_HeaderStyle, GUILayout.Width(200), GUILayout.Height(20)); //title Rect rect = EditorGUILayout.GetControlRect(); float controlWidth = rect.width; rect.width = 200; EditorGUI.LabelField(rect, "gameObject", m_TitleStyle); rect.x = rect.width + 20; float labelWidth = controlWidth - rect.x - 5; rect.width = labelWidth * 0.4f; EditorGUI.LabelField(rect, "component", m_TitleStyle); rect.x += rect.width; rect.width = labelWidth - rect.width; EditorGUI.LabelField(rect, "property", m_TitleStyle); GUILayout.Space(5); m_SceneLabelIcon.text = " " + EditorSceneManager.GetActiveScene().name; EditorGUILayout.LabelField(m_SceneLabelIcon, GUILayout.Height(18)); GUILayout.Space(5); foreach (var pair in m_HierarchyResults) { for (int i = 0; i < pair.Value.Count; i++) { HierarchyResult r = pair.Value[i]; rect = EditorGUILayout.GetControlRect(); //gameobject if (i == 0) { rect.width = 200; EditorGUI.ObjectField(rect, pair.Key, typeof(GameObject), true); } else { rect.x += 185; rect.width = 15; EditorGUI.LabelField(rect, "\u27A5"); } if (!string.IsNullOrEmpty(r.tip)) { rect.x += rect.width + 20; rect.width = labelWidth; EditorGUI.LabelField(rect, r.tip); GUILayout.Space(5); continue; } //component rect.x += rect.width + 20; float contentWidth = labelWidth * 0.4f; rect.width = contentWidth; if (r.script != null) { EditorGUI.LabelField(rect, "", m_LabelStyle); rect.x += labelTextOffset; rect.width -= labelTextOffset; rect.y += 1; EditorGUI.ObjectField(rect, r.script, r.script.GetType(), false); rect.x += contentWidth - labelTextOffset; rect.y -= 1; } else { EditorGUI.LabelField(rect, new GUIContent(AssetPreview.GetMiniThumbnail(r.component)), m_LabelStyle); rect.x += 25; rect.width -= 25; EditorGUI.SelectableLabel(rect, r.component.GetType().Name); rect.x += rect.width; } //property if (!(r.script != null && r.script == m_SelectedObj)) { contentWidth = labelWidth - contentWidth; rect.width = contentWidth; EditorGUI.LabelField(rect, "", m_LabelStyle); rect.x += labelTextOffset; rect.width = contentWidth * 0.5f; EditorGUI.SelectableLabel(rect, r.propertyName); rect.x += rect.width; rect.width = contentWidth - rect.width - labelTextOffset; rect.y += 1; EditorGUI.ObjectField(rect, r.property, r.property.GetType(), false); } GUILayout.Space(5); } } EditorGUILayout.EndVertical(); GUILayout.Space(15); }
static void CheckReference(Object obj, bool inHierarchy, Object asset = null) { if (obj == null || obj is Transform) { return; } SerializedObject so = new SerializedObject(obj); SerializedProperty p = so.GetIterator(); do { if (p.propertyType != SerializedPropertyType.ObjectReference || p.objectReferenceValue == null || (inHierarchy && p.propertyPath == "m_GameObject")) { continue; } bool isMatched = false; if (m_IsFindingGameObject) { if (m_SelectedObjects.Contains(p.objectReferenceValue)) { isMatched = true; } } else if (m_IsFindingAsset) { if (p.objectReferenceValue == m_SelectedObj || (m_SelectedIsMainAsset && AssetDatabase.GetAssetPath(p.objectReferenceValue) == m_SelectedObjPath)) { isMatched = true; } } if (isMatched) { if (inHierarchy) { Component c = obj as Component; HierarchyResult r = new HierarchyResult() { component = c, property = p.objectReferenceValue, propertyName = GetPropertyName(c, p) }; if (obj is MonoBehaviour) { MonoScript script = MonoScript.FromMonoBehaviour(obj as MonoBehaviour); string path = AssetDatabase.GetAssetPath(script.GetInstanceID()); if (path.StartsWith("Assets/")) { r.script = script; } } if (r.script == null && r.propertyName.StartsWith("m_")) { r.propertyName = r.propertyName.Substring(2); } SaveHierarchyResult(c.gameObject, r); } else if (asset is SceneAsset || asset is GameObject) { Component c = obj as Component; ProjectResult r = new ProjectResult() { childPath = GetPropertyPath(asset, c, p), propertyName = GetPropertyName(c, p), referenceObject = p.objectReferenceValue }; SaveProjectResult(asset, r); } else { ProjectResult r = new ProjectResult() { childPath = p.propertyPath, propertyName = p.displayName, referenceObject = p.objectReferenceValue }; SaveProjectResult(asset, r); } } }while (p.Next(true)); }