You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
97 lines
2.9 KiB
97 lines
2.9 KiB
4 years ago
|
using System.Collections;
|
||
|
using System.Collections.Generic;
|
||
|
using System.Xml;
|
||
|
using UnityEngine;
|
||
|
using UnityEngine.UI;
|
||
|
|
||
|
public class UpdateMaps : MonoBehaviour {
|
||
|
|
||
|
private Dictionary<string, MapType> maps = new Dictionary<string, MapType>();
|
||
|
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.综合体建筑;
|
||
|
}
|
||
|
|
||
|
|
||
|
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<Toggle>().group = mapsContent.GetComponent<ToggleGroup>();
|
||
|
obj.transform.Find("Dept/Label").GetComponent<Text>().text = item.Value.name;
|
||
|
obj.GetComponent<MapItem>().mapType = mapType;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// Update is called once per frame
|
||
|
void Update () {
|
||
|
|
||
|
}
|
||
|
}
|