/// <summary> /// 导出阻挡信息 /// </summary> /// <param name="path"></param> /// <returns></returns> private bool ExportTile(string path) { var json = NGUIJson.jsonEncode(new Hashtable() { { "tilexnum", Target.gridXNum }, { "tileynum", Target.gridZNum }, { "tiles", System.Array.ConvertAll(Target.grids, g => (uint)g) }, }); //Debug.Log(json); File.WriteAllText(path, json, new System.Text.UTF8Encoding(false)); return(true); }
/// <summary> /// 导出NPC摆放信息 /// </summary> /// <param name="path"></param> /// <returns></returns> private bool ExportNpc(string path) { var host = Target.transform.parent; var npc = host.GetComponentsInChildren <NpcEditor>(); var db = Table.Query <table.TableNpc>().ToDictionary(i => i.id); var error = from i in npc let id = (uint)i.baseId where db.ContainsKey(id) == false select i; if (error.Any()) { Debug.LogError("NPC表格中找不到对应id的NPC:\n" + string.Join("\n", (from i in error select string.Format("{0}\t{1}", i.baseId, i.transform.GetPath())).ToArray())); return(false); } var json = NGUIJson.jsonEncode(new Hashtable() { { "npcs", System.Array.ConvertAll(npc, i => { var grid = new MapGrid(i.transform.localPosition); return(new Hashtable() { { "id", i.baseId }, { "name", string.IsNullOrEmpty(i.alias) ? db[(uint)i.baseId].name : i.alias }, { "x", grid.x }, { "y", grid.z }, { "angle", (int)i.transform.localRotation.eulerAngles.y }, { "relivetime", i.relivetime }, { "rate", Mathf.Clamp(i.rate, 0, 100) }, }); }) }, }); //Debug.Log(json); File.WriteAllText(path, json, new System.Text.UTF8Encoding(false)); return(true); }