using System.Collections; using System.Collections.Generic; using System.Xml; using UnityEngine; using UnityEngine.UI; public class UpdateMaps : MonoBehaviour { private Dictionary maps = new Dictionary(); private MapType mapType = new MapType(); private Transform mapsContent; public GameObject mapItem; // Use this for initialization private void Awake() { /* *TODO:请求服务器,下载服务器地图清单文件并于本地对比,更新本地地图清单文件 * 更新完后,在服务器返回更新完成命令里调用GetMaps()和RefreshMaps() **/ } void Start () { mapsContent = transform.Find("Body/Viewport/Content"); GetMaps(); RefreshMaps(); } private void GetMaps() { var doc = new XmlDocument(); doc.Load(Application.dataPath + @"\StreamingAssets\MainMapXml.xml"); var children = doc.SelectSingleNode("Maps").ChildNodes; foreach (XmlElement node in children) { var sceneType = node.GetAttribute("MapType"); var sceneTp = SceneType.None; if (sceneType == SceneType.化工建筑.ToString()) { sceneTp = SceneType.化工建筑; } else if (sceneType == SceneType.高层建筑.ToString()) { sceneTp = SceneType.高层建筑; } else if (sceneType == SceneType.地下建筑.ToString()) { sceneTp = SceneType.地下建筑; } else if (sceneType == SceneType.综合体建筑.ToString()) { sceneTp = SceneType.综合体建筑; } else if (sceneType == SceneType.大跨度建筑.ToString()) { sceneTp = SceneType.大跨度建筑; } var path = node.GetAttribute("Path"); var unit = Unit.None; if (path == Unit.DongYouLiQing.ToString()) { unit = Unit.DongYouLiQing; } var mapName = node.GetAttribute("MapName"); var intro = node.GetAttribute("Intro"); var areaSquadron = node.GetAttribute("XiaQZD"); mapType.sceneType = sceneTp; mapType.unit = unit; mapType.name = mapName; mapType.introduction = intro; mapType.areaSquadron = areaSquadron; maps.Add(mapType.unit.ToString(),mapType); } } private void RefreshMaps() { foreach (var item in maps) { GameObject obj = Instantiate(mapItem,mapsContent) as GameObject; obj.transform.Find("Dept").GetComponent().group = mapsContent.GetComponent(); obj.transform.Find("Dept/Label").GetComponent().text = item.Value.name; obj.GetComponent().mapType = mapType; } } // Update is called once per frame void Update () { } }