private static void CityLoad(TiledMapInfo tiledmapinfo, lc_ObjGather objgather) { lc_ObjManager tmpmanager = new lc_ObjManager(objgather); for (int i = 0; i < tiledmapinfo.baselayertiled.Count; i++) { if (tiledmapinfo.baselayertiled[i].iscity == true) { lc_City city = objgather.AddObject <lc_City>(tiledmapinfo.baselayertiled[i].name); city.user_id = tiledmapinfo.baselayertiled[i].id; tiledmapinfo.baselayertiled[i].obj_id = city.obj_id; tmpmanager.SetCityRelNum(city.obj_id, tiledmapinfo.baselayertiled[i].citynum); lc_Country country = tmpmanager.GetObjectByUserId <lc_Country>(tiledmapinfo.baselayertiled[i].countryid); if (country != null) { //Debug.Log("set city[" + city.m_name + "] belong country[" + country_objid + "]"); tmpmanager.SetCityBel(city.obj_id, country.obj_id); } else { Debug.Log("map_id " + tiledmapinfo.baselayertiled[i].countryid + " not mapping city id=[" + city.user_id + "]"); } } } tmpmanager = null; }
public override void OnSceneLoaded() { Debug.Log("MainMapScene load activescene=[" + SceneManager.GetActiveScene().name + "]"); //创建场景消息管理中心 MapSceneMsgCenter = new NotifacitionCenter(); //创建UI管理器管理UI Singleton <UIManager> .Create(); Singleton <ContextManager> .Create(); //string mappath = Application.dataPath + "/StreamingAssets/AssetBundles/maptile"; //string mapuipath = Application.dataPath + "/StreamingAssets/AssetBundles/mapsceneui"; //string rolepath = Application.dataPath + "/StreamingAssets/AssetBundles/role"; ResourceManger.Instance.LoadRes(Application.streamingAssetsPath + @"/AssetBundles/AssetBundles"); ResourceManger.Instance.LoadRes(Application.streamingAssetsPath + @"/AssetBundles/maptile"); ResourceManger.Instance.LoadRes(Application.streamingAssetsPath + @"/AssetBundles/mapsceneui"); ResourceManger.Instance.LoadRes(Application.streamingAssetsPath + @"/AssetBundles/role"); //AssetBundle mapBundle = AssetBundle.LoadFromFile(Application.dataPath + "/StreamingAssets/AssetBundles/maptile"); //AssetBundle mapUiBundle= AssetBundle.LoadFromFile(Application.dataPath + "/StreamingAssets/AssetBundles/mapsceneui"); //AssetBundle roleBundle=AssetBundle.LoadFromFile(Application.dataPath + "/StreamingAssets/AssetBundles/role"); //创建地图实例 Singleton <TiledMapInfo> .Create(); objgather = Singleton <lc_ObjGather> .Instance; objmanager = new lc_ObjManager(objgather); objviewer = new lc_ObjViewer(objgather); //加载游戏地图及游戏脚本文件 string mapfilepath = Application.dataPath + @"/StreamingAssets/Map/MapInfo.tmx"; string gamefilepath = Application.dataPath + @"/StreamingAssets/Game/GameData.xml"; XmlLoad.MapTileXmlLoad(mapfilepath, Singleton <TiledMapInfo> .Instance); XmlLoad.GameXmlLoad(gamefilepath, objgather, Singleton <TiledMapInfo> .Instance); //UI初始化 Singleton <ContextManager> .Instance.Push(new ActiveMenuContext()); Singleton <ContextManager> .Instance.Push(new OptionPanelContext()); Singleton <ContextManager> .Instance.Push(new PopInterFacePanelContext()); Singleton <ContextManager> .Instance.NoStackPush(new CityInfoSignContext()); //创建地图生成器生成地图 GameObject go = new GameObject("MapMaker"); go.AddComponent <hexgrid>(); CreateGameTest(); }
} /*读取地图XML文件并放入地图结构体中*/ public static void GameXmlLoad(string filepath, lc_ObjGather objgather, TiledMapInfo tiledmapinfo) { if (File.Exists(filepath)) { XmlDocument xmlDoc = new XmlDocument(); xmlDoc.Load(filepath); CountryLoad(xmlDoc, objgather); CityLoad(tiledmapinfo, objgather); } } /*读取游戏XML*/
} /*读取游戏XML*/ private static void CountryLoad(XmlDocument doc, lc_ObjGather objgather) { XmlNodeList countrylist = doc.SelectNodes("listType/InitConf/CountryConf/Country"); foreach (XmlNode country in countrylist) { XmlElement tempelement = (XmlElement)country; string name = tempelement.GetAttribute("name"); int mapid = int.Parse(tempelement.GetAttribute("mapid")); int military = int.Parse(country.SelectSingleNode("military").InnerText); int crown = int.Parse(country.SelectSingleNode("crown").InnerText); lc_Country lccountry = objgather.AddObject <lc_Country>(name); lccountry.m_military = military; lccountry.m_crown = crown; lccountry.user_id = mapid; } }