/// <summary> /// 构建层级面板数据 /// </summary> /// <param name="gameObj"> 创建对象,包含子物体 </param> public void CreatTree(GameObject gameObj) { m_CurrentGenerateDatas.Clear(); HierarchyData data = new HierarchyData(); string id = GameTools.Instance.GenerateMD5(gameObj.name); data.CurID = id; data.ParentID = m_InitHierarchy.ToString(); data.CurName = gameObj.name; m_CurrentGenerateDatas.Add(data); AllGameObjectDic.Add(id, gameObj); ChildTree(gameObj, m_InitHierarchy + 1); }
/// <summary> /// 添加子物体 /// </summary> private void ChildTree(GameObject gameObj, int count) { int index = gameObj.transform.childCount; if (index > 0) { for (int i = 0; i < index; i++) { HierarchyData data = new HierarchyData(); GameObject obj = gameObj.transform.GetChild(i).gameObject; if (obj.activeInHierarchy == true) { SumCount++; obj.name = obj.name + "_" + SumCount.ToString(); string id = GameTools.Instance.GenerateMD5(obj.name); data.CurID = id; data.CurName = obj.name; data.ParentID = GameTools.Instance.GenerateMD5(gameObj.name); m_CurrentGenerateDatas.Add(data); if (!AllGameObjectDic.ContainsKey(id)) { AllGameObjectDic.Add(id, obj); } else { Debug.LogError("出现相同的Key值!字典错误!"); } if (obj.transform.childCount > 0) { ChildTree(obj, count + 1); } } } } }