public void Save() { var edges = GetGameObjects("Edge", collisionRoot); var circles = GetGameObjects("Circle", collisionRoot); var rects = GetGameObjects("Rect", collisionRoot); var polies = GetGameObjects("Poly", collisionRoot); List <PolyJson> polyJsons = new List <PolyJson>(); polyJsons.AddRange(rects.Select(x => x.GetComponent <RectBuilder>().GetJson())); polyJsons.AddRange(polies.Select(x => x.GetComponent <PolyBuilder>().GetJson())); var map = new MapJson() { width = width, height = height, edges = edges.Select(x => x.GetComponent <EdgeBuilder>().GetJson()).ToArray(), circles = circles.Select(x => x.GetComponent <CircleBuilder>().GetJson()).ToArray(), polies = polyJsons.ToArray() }; string json = JsonConvert.SerializeObject(map); StreamWriter sw = new StreamWriter(saveFileName + ".json", false); sw.WriteLine(json); sw.Flush(); ExportObj(loadFileName); GenerateNavMesh(loadFileName); }
/// <summary> /// 坐标互转 /// </summary> /// <param name="lng">经度</param> /// <param name="lat">纬度</param> /// <param name="from">待转换的坐标类型</param> /// <param name="to">最终转换成的坐标类型</param> /// <returns></returns> public static Map ConvertAll(double lng, double lat, MapEnum from, MapEnum to) { //google 坐标转百度链接 //http://api.map.baidu.com/ag/coord/convert?from=2&to=4&x=&y= //gps坐标的type=0 //google坐标的type=2 //baidu坐标的type=4 string path = "http://api.map.baidu.com/ag/coord/convert?from=" + from.GetHashCode() + "&to=" + to.GetHashCode() + "&x=" + lng + "+&y=" + lat; //使用http请求获取转换结果、得到返回的结果 string res = HttpHelper.GET(path).ToString(); //处理结果 MapJson json = JsonHelper.JsonDeserialize <MapJson>(res); Map map = new Map(); if (json.X != null) { byte[] outputb = Convert.FromBase64String(json.X); map.X = Convert.ToDouble(Encoding.Default.GetString(outputb)); } if (json.Y != null) { byte[] outputb = Convert.FromBase64String(json.Y); map.Y = Convert.ToDouble(Encoding.Default.GetString(outputb)); } return(map); }
// 解析josn public static MapJson Parse(LitJson.JsonData data) { MapJson json = new MapJson(); try { json.dropicon = (string)data["dropicon"]; json.yid = (int)data["yid"]; json.coin = (int)data["coin"]; json.name = (string)data["name"]; json.levelrequired = (int)data["levelrequired"]; json.resourceid = (int)data["resourceid"]; json.scene = (int)data["scene"]; json.dropid = (int)data["dropid"]; json.priority = (int)data["priority"]; json.exp = (int)data["exp"]; json.icon = (int)data["icon"]; json.quality = (int)data["quality"]; json.id = (int)data["id"]; json.desc = (string)data["desc"]; json.mconfig = new List <int>(); LitJson.JsonData arr = data["mconfig"]; int iarrCount = arr.Count; LitJson.JsonData arrItem; for (int i = 0; i < iarrCount; i++) // 将 mconfig 放到 List { arrItem = arr[i]; json.mconfig.Add((int)arrItem); } /* * mapJson.dropicon = (string)data["dropicon"]; * mapJson.yid = (int)data["yid"]; * mapJson.coin = (int)data["coin"]; * mapJson.mconfig = new List<int>(); * LitJson.JsonData arr = data["mconfig"]; * int iarrCount = arr.Count; * for(int i = 0; i < iarrCount; i++) { * mapJson.mconfig.Add((int)arr[i]); * } * //mapJson.mconfig = (List<int>)data["mconfig"]; * mapJson.name = (string)data["name"]; * mapJson.levelrequired = (int)data["levelrequired"]; * mapJson.resourceid = (int)data["resourceid"]; * mapJson.scene = (int)data["scene"]; * mapJson.dropid = (int)data["dropid"]; * mapJson.priority = (int)data["priority"]; * mapJson.exp = (int)data["exp"]; * mapJson.icon = (int)data["icon"]; * mapJson.quality = (int)data["quality"]; * mapJson.id = (int)data["id"]; * mapJson.desc = (string)data["desc"]; */ } catch (System.Exception ex) { Debug.Log("Parse MapJson Error :" + ex.Message); } return(json); }
public static WriteFileJson FromMap(InputActionMap map) { return(new WriteFileJson { maps = new[] { MapJson.FromMap(map) } }); }
void CreateStaticBodies(MapJson map) { CollisionEntity collision = GetChild <CollisionEntity>(); Vector2 p0 = Vector2.Zero; Vector2 p1 = new Vector2(0, map.height); Vector2 p2 = new Vector2(map.width, map.height); Vector2 p3 = new Vector2(map.width, 0); collision.GenerateStaticBody(p0, p1); collision.GenerateStaticBody(p1, p2); collision.GenerateStaticBody(p2, p3); collision.GenerateStaticBody(p3, p0); foreach (EdgeJson edge in map.edges) { collision.GenerateStaticBody(edge.point0, edge.point1); } foreach (CircleJson circle in map.circles) { collision.GenerateStaticBody(circle.center, circle.radius); } foreach (PolyJson poly in map.polies) { collision.GenerateStaticBody(poly.points); } }
public void GenerateMap() { _map = JsonUtility.FromJson <MapJson>(_mapJson.ToString()); DestroyMap(); CreateLayer(); }
// 任务 public void ShowRenwuView(MapJson mapjson) { System.Action <Object> handler = (asset) => { if (asset != null) { GameObject renwuViewObject = (GameObject)GameObject.Instantiate(asset); RenwuView renwuView = renwuViewObject.GetComponent <RenwuView>(); renwuView.show(mapjson); NGUIUtility.SetParent(waitingParentT, renwuViewObject.transform); } }; StartCoroutine(BundleMgr.CreateObject(kResource.View, "RenwuView", "RenwuView", handler)); }
public void SetData(MapJson json, int mapIndex) // ÉèÖóɻÒÉ«ÐÇÐÇ { m_mapJson = json; m_mapIndex = mapIndex; spriteStar1.spriteName = SXingxing_Hui; spriteStar2.spriteName = SXingxing_Hui; spriteStar3.spriteName = SXingxing_Hui; spriteStar1.enabled = false; spriteStar2.enabled = false; spriteStar3.enabled = false; labelTitle.text = json.name; imageBtn.GetComponent <BoxCollider>().enabled = false; }
public void Write(Map map, Stream stream) { MapJson json = new MapJson(map); JsonSerializer serializer = new JsonSerializer(); serializer.Formatting = Formatting.Indented; serializer.NullValueHandling = NullValueHandling.Ignore; using (StreamWriter streamWriter = new StreamWriter(stream)) using (JsonWriter jsonWriter = new JsonTextWriter(streamWriter)) { serializer.Serialize(jsonWriter, json); } }
private void Button_Click_Gen_Map_Json(object sender, RoutedEventArgs e) { MapJson map = new MapJson(); if (json.md5 == null) { System.Windows.MessageBox.Show("你没有list怎么可以生成map???"); return; } map.md5 = json.md5; if (!Regex.IsMatch(TBoxMapName.Text, outputPattern)) { System.Windows.MessageBox.Show("不要给我乱搞"); return; } map.name = TBoxMapName.Text; map.width = maxWidth; map.height = maxHeight; map.content = new Dictionary <int, string>(); StringBuilder sb = new StringBuilder(); int lastV = 0; for (int i = 0; i <= finalIndex; i++) { var btn = buttonlist[i]; if (lastV != btn.Y) { map.content.Add(lastV, sb.ToString(0, sb.Length - 1)); sb.Clear(); lastV = btn.Y; if (lastV > maxHeight) { break; } } if (btn.C == null) { sb.Append(0); } else { sb.Append(btn.C.idx); } sb.Append(" "); } JsonHelp.MapToFile(map, fileDirectory); }
void CreateWorld() { var config = GetChild <ConfigEntity>(); string mapPath = config.GetString("Map"); StreamReader reader = new StreamReader(mapPath); var serializer = new DataContractJsonSerializer(typeof(MapJson)); MapJson map = (MapJson)serializer.ReadObject(reader.BaseStream); reader.Close(); GetChild <CollisionEntity>().CreateWorld(map.width, map.height); CreateStaticBodies(map); GetChild <PathfindingEntity>().Load(config.GetString("NavMesh")); }
public void show(MapJson mapjson) // 显示 { m_mapJson = mapjson; labelMapName.text = m_mapJson.name; labelMapDesc.text = m_mapJson.desc; // 描述 labelExp.text = string.Format(Globals.It.LanguageMgr.GetString(9), m_mapJson.exp); labelGold.text = string.Format(Globals.It.LanguageMgr.GetString(10), m_mapJson.coin); if (string.IsNullOrEmpty(m_mapJson.dropicon) || m_mapJson.dropicon == "\r") { labelWupin.text = Globals.It.LanguageMgr.GetString(11); } else { // Set Item.name labelWupin.text = ""; } labelDiren.text = Globals.It.LanguageMgr.GetString(12); }
public static WriteFileJson FromMaps(IEnumerable <InputActionMap> maps) { var mapCount = Enumerable.Count(maps); if (mapCount == 0) { return(new WriteFileJson()); } var mapsJson = new MapJson[mapCount]; var index = 0; foreach (var map in maps) { mapsJson[index++] = MapJson.FromMap(map); } return(new WriteFileJson { maps = mapsJson }); }
public Map Read(string path) { MapJson json = JsonConvert.DeserializeObject <MapJson>(File.ReadAllText(path)); return(json.Generate(path)); }
public void ConvertListToArray(List <Unit> unitList) { MapJson map = new MapJson(); map.ConvertListToJson(unitList); }
public List <Unit> ConvertArrayToList() { MapJson map = new MapJson(); return(map.ConvertJsonToList()); }
public static void MapToFile(MapJson json, string path) { ObjToFile(json, json.name + ".map", path); }
public override void Convert() { using (var stream = new BinaryReader(File.OpenRead(Path), Encode)) { var size = stream.BaseStream.Length; var list = new List <MapJson>(); var txt = new StringBuilder(); while (stream.BaseStream.Position < size) { var temp = new MapJson[64]; for (var j = 0; j < 64; j++) { temp[j] = new MapJson { LoopId = (ushort)j }; var range = new CoordRec { X1 = stream.ReadInt32(), Y1 = stream.ReadInt32(), X2 = stream.ReadInt32(), Y2 = stream.ReadInt32(), }; temp[j].Coord = range; } for (var j = 0; j < 64; j++) { temp[j].Name = Encode.GetString(stream.ReadBytes(28)).Trim('\u0000'); } for (var j = 0; j < 64; j++) { //temp[j].Desc = Encode.GetString(stream.ReadBytes(1024)).Trim('\u0000'); stream.ReadBytes(1024); } // 65536 for (var j = 0; j < 64; j++) { temp[j].Unk1 = stream.ReadInt32(); } for (var j = 0; j < 64; j++) { temp[j].Unk2 = stream.ReadInt32(); } for (var j = 0; j < 64; j++) { temp[j].Unk3 = stream.ReadByte(); } for (var j = 0; j < 64; j++) { temp[j].Unk4 = stream.ReadInt32(); } list.AddRange(temp.Where(mapJson => !string.IsNullOrEmpty(mapJson.Name))); } foreach (var map in list) { var newName = map.Name.Replace("'", "''").Trim(); txt.AppendLine($"INSERT INTO `data_maps` VALUES ({map.LoopId + 1}, '{newName}', " + $"{map.Coord.X1}, {map.Coord.Y1}, {map.Coord.X2}, {map.Coord.Y2}, " + $"{map.Unk1}, {map.Unk2}, {map.Unk3}, {map.Unk4});"); } SqlData = txt.ToString(); JsonData = JsonConvert.SerializeObject(list, Formatting.Indented); } }