public static void ExportLevelGrids() { var astart = GameObject.FindObjectOfType <AstarGridBase>(); if (astart == null) { EditorUtility.DisplayDialog("No Found", "No Foun AstarGridBase!", "OK"); return; } var grid = new Proto.MapGridData(); var list = new List <Proto.MapNode>(); for (var x = 0; x < astart.grid.maxX; x++) { for (var z = 0; z < astart.grid.maxZ; z++) { var n = new Proto.MapNode(); var node = astart.grid.grid[x, 0, z]; n.X = node.x; n.Y = node.y; n.Z = node.z; n.IsWalkable = node.isWalkable; list.Add(n); } } grid.Nodes = list; grid.MaxX = astart.grid.maxX; grid.MaxY = astart.grid.maxY; grid.MaxZ = astart.grid.maxZ; grid.Offset = new Proto.Vector3 { x = astart.grid.offsetX, y = astart.grid.offsetY, z = astart.grid.offsetZ }; grid.Size = new Proto.Vector3 { x = astart.grid.sizeX, y = astart.grid.sizeY, z = astart.grid.sizeZ }; var monsters = GameObject.FindObjectsOfType <MonsterGroupPosition>(); var player = GameObject.FindObjectOfType <PlayerBornPosition>(); foreach (var i in monsters) { var node = astart.grid.GetNodeFromVector3((int)i.transform.position.x, (int)i.transform.position.y, (int)i.transform.position.z); if (node == null) { continue; } grid.Monsters.Add(new Proto.MapMonsterGroup { Pos = new Proto.MapNode { X = node.x, Y = node.y, Z = node.z }, CanBeBoss = i.CanBeBoss }); } if (player != null) { var node = astart.grid.GetNodeFromVector3( (int)player.transform.position.x, (int)player.transform.position.y, (int)player.transform.position.z); if (node != null) { grid.Born = new Proto.MapNode { X = node.x, Y = node.y, Z = node.z }; } } using (var mem = new MemoryStream()) { using (var bw = new BinaryWriter(mem)) { grid.ToBinary(bw); } var fileName = EditorUtility.SaveFilePanel("Save grid", Application.dataPath, astart.name, "bin"); File.WriteAllBytes(fileName, mem.ToArray()); } }
public void LoadAllConfig(string configRoot) { this.ConfigRoot = configRoot.StartsWith("" + Path.DirectorySeparatorChar, StringComparison.Ordinal) ? configRoot : Path.Combine(AppDomain.CurrentDomain.BaseDirectory, configRoot); _magicData = new SyncDictionary <string, MagicData>(); _timeLines = new SyncDictionary <string, TimeLine>(); _aiTree = new SyncDictionary <string, TreeNode>(); _levels = new SyncDictionary <string, MapGridData>(); var magics = Directory.GetFiles(Path.Combine(ConfigRoot, "Magics"), "*.xml"); foreach (var i in magics) { var xml = File.ReadAllText(i, XmlParser.UTF8); var m = XmlParser.DeSerialize <Layout.MagicData>(xml); _magicData.Add(m.key, m); } var timeLines = Directory.GetFiles(Path.Combine(ConfigRoot, "Layouts"), "*.xml"); foreach (var i in timeLines) { var xml = File.ReadAllText(i, XmlParser.UTF8); var line = XmlParser.DeSerialize <TimeLine>(xml); _timeLines.Add("Layouts/" + Path.GetFileName(i), line); } var aitrees = Directory.GetFiles(Path.Combine(ConfigRoot, "AI"), "*.xml"); foreach (var i in aitrees) { var xml = File.ReadAllText(i, XmlParser.UTF8); var note = XmlParser.DeSerialize <TreeNode>(xml); _aiTree.Add("AI/" + Path.GetFileName(i), note); } var mapFiles = Directory.GetFiles(Path.Combine(ConfigRoot, "LevelGrids"), "*.bin"); foreach (var i in mapFiles) { var bytes = File.ReadAllBytes(i); var mapdata = new Proto.MapGridData(); using (var mem = new MemoryStream(bytes)) { using (var br = new BinaryReader(mem)) { mapdata.ParseFormBinary(br); } } _levels.Add(Path.GetFileName(i), mapdata); } var Manager = new ExcelToJSONConfigManager(this); var assemblyTypes = Manager.GetType().Assembly.GetTypes(); var mothed = Manager.GetType().GetMethod("GetConfigByID"); foreach (var i in assemblyTypes) { if (i.IsSubclassOf(typeof(JSONConfigBase))) { var m = mothed.MakeGenericMethod(i); m.Invoke(Manager, new object[] { 0 }); } } }