/// <summary> /// 修复路径发生错误的数据, 名字改了, 父节点改了的情况 /// </summary> public void RepairPathErrorUIElementData() { List <string> tOldNameList = new List <string>(); List <UIElementData> tNewNameUIElementDataList = new List <UIElementData>(); //更新数据 foreach (var tKv in mUIElementDic) { UIElementData tUiElementData = tKv.Value; if (tUiElementData.mState != UIElementData.eState.Go_Type_PathError) { continue; } string tOldName = tUiElementData.mVarName; tUiElementData.UpdateDataByGo(); if (tOldName == tUiElementData.mVarName) { continue; } tOldNameList.Add(tOldName); tNewNameUIElementDataList.Add(tUiElementData); } //处理用户 修改了prefab 节点名字的情况 for (int i = 0; i < tNewNameUIElementDataList.Count; ++i) { string tOldName = tOldNameList[i]; UIElementData tNewNameUIElementData = tNewNameUIElementDataList[i]; mUIElementDic.Remove(tOldName); UIElementData tSameNameUIElement = null; if (mUIElementDic.TryGetValue(tNewNameUIElementData.mVarName, out tSameNameUIElement) == false) { //没有同名的情况 mUIElementDic.Add(tNewNameUIElementData.mVarName, tNewNameUIElementData); } else { if (tSameNameUIElement.mGo == tNewNameUIElementData.mGo) { //同名且是同一个Go, 直接替换原有的 mUIElementDic.Remove(tNewNameUIElementData.mVarName); mUIElementDic.Add(tNewNameUIElementData.mVarName, tNewNameUIElementData); } else { //同名但不同Go, 出错了 Debug.LogError("冲突了:相同变量名, 但 GameObject 不是同一个, " + "\nGameObject 路径分别为:" + "\n" + tSameNameUIElement.mPath + "\n" + tNewNameUIElementData.mPath + "\n已删除 " + tNewNameUIElementData.mPath + " 上的冲突,如需要这个对象, 请处理名字冲突后, 重新绑定"); } } } }