public static void saveMaterialTexCfg(string matName, ArrayList propNames, ArrayList texNames, ArrayList texPaths) { if (propNames == null || propNames.Count <= 0) { Debug.Log("There is no textures"); return; } if (!needSave(matName, propNames, texNames, texPaths)) { return; } Hashtable map = MapEx.getMap(CLMaterialPool.materialTexRefCfg, matName); if (map == null) { map = new Hashtable(); } map ["pp"] = propNames; map ["tn"] = texNames; map ["tp"] = texPaths; CLMaterialPool.materialTexRefCfg [matName] = map; MemoryStream ms = new MemoryStream(); B2OutputStream.writeObject(ms, CLMaterialPool.materialTexRefCfg); Directory.CreateDirectory(Path.GetDirectoryName(CLMaterialPool.materialTexRefCfgPath)); //File.WriteAllBytes (CLMaterialPool.materialTexRefCfgPath, ms.ToArray ()); byte[] bytes = ms.ToArray(); FileStream fs = new FileStream(CLMaterialPool.materialTexRefCfgPath, FileMode.OpenOrCreate); fs.Write(bytes, 0, bytes.Length); fs.Close(); }
static public void saveMap(Hashtable map, string outPath) { MemoryStream ms = new MemoryStream(); B2OutputStream.writeMap(ms, map); Directory.CreateDirectory(Path.GetDirectoryName(outPath)); File.WriteAllBytes(outPath, ms.ToArray()); }
static public void Json2Bio() { UnityEngine.Object[] objs = Selection.objects; int count = objs.Length; UnityEngine.Object obj = null; CLPanelLua panel = null; for (int i = 0; i < count; i++) { obj = objs [i]; string path = AssetDatabase.GetAssetPath(obj); //Selection表示你鼠标选择激活的对象 string jsonStr = File.ReadAllText(path); object map = JSON.JsonDecode(jsonStr); MemoryStream ms = new MemoryStream(); B2OutputStream.writeObject(ms, map); Directory.CreateDirectory(Path.GetDirectoryName(path)); File.WriteAllBytes(path + ".bio", ms.ToArray()); } }
void generateData() { if (editorCfg == null) { Debug.Log("Editor config is null"); return; } // 设置grid GridBase grid = new GridBase(); grid.init(Vector3.zero, editorCfg.size, editorCfg.size, 1); // 先把图的格式设置成RGBA32 Texture2D areaTex = editorCfg.oceanGidTexture; if (areaTex == null) { Debug.Log("oceanGid Texture is null"); return; } // 先取得大地图分区的数据 Color32[] colors = areaTex.GetPixels32(); Debug.Log("areaTex.width===" + areaTex.width); Debug.Log("colors.Length===" + colors.Length); // 区域块的index对应的val Hashtable areaMap = new Hashtable(); // 取得大地图与分区地图的比例,以例可以对换 int mapareaScale = editorCfg.size / areaTex.width; //地图分区块的网格 GridBase gridArea = new GridBase(); gridArea.init(Vector3.zero, areaTex.width, areaTex.width, mapareaScale); Color c; for (int i = 0; i < colors.Length - 1; i++) { c = colors[i]; int areaVal = 0; if (editorCfg.colors4MapArea.TryGetValue(c, out areaVal)) { areaMap[i] = areaVal; } else { Debug.LogError("get area val by color is nil!" + c + "==" + c * 255); } } //地图数据 Hashtable mapInfor = new Hashtable(); // 生成据点 int tmpSize = editorCfg.pageSize * 2; for (int i = tmpSize / 2; i < editorCfg.size; i += tmpSize) { for (int j = tmpSize / 2; j < editorCfg.size; j += tmpSize) { int index = grid.GetCellIndex(i, j); List <int> cells = grid.getCells(index, 5); int k = NumEx.NextInt(0, cells.Count); while (true) { if (k >= cells.Count) { k = 0; } if (mapInfor[(int)(cells[k])] == null) { mapInfor[(int)(cells[k])] = 1; break; } k++; } } } // 生成装饰 for (int i = editorCfg.pageSize / 2; i < editorCfg.size; i = i + editorCfg.pageSize) { for (int j = editorCfg.pageSize / 2; j < editorCfg.size; j = j + editorCfg.pageSize) { int index = grid.GetCellIndex(i, j); switch (NumEx.NextInt(0, 4)) { case 0: addIsland1(grid, index, mapInfor); break; case 1: addIsland2(grid, index, mapInfor); break; case 2: addIsland3(grid, index, mapInfor); break; default: addIsland4(grid, index, mapInfor); break; } } } //导出数据(会根据分区导出数据,这里会导出100份数据,方便加载) /* * 每个分区id对应一个文件,每个文件里存一个table,key是一屏的index,value是table2 * table2里的key是网格index,value是地块配置id */ string path = Application.dataPath + "/" + CLPathCfg.self.basePath + "/" + CLPathCfg.upgradeRes + "/priority/cfg/worldmap/maparea.cfg"; Directory.CreateDirectory(Path.GetDirectoryName(path)); MemoryStream ms = new MemoryStream(); B2OutputStream.writeObject(ms, areaMap); File.WriteAllBytes(path, ms.ToArray()); Debug.Log(path); for (int i = 0; i < areaTex.width; i++) { for (int j = 0; j < areaTex.width; j++) { int index = i * areaTex.width + j; Hashtable areaPageMap = new Hashtable(); List <int> pagesIndes = areaIndex2MapPageIndexs(grid, gridArea, index, mapareaScale); for (int p = 0; p < pagesIndes.Count; p++) { int center = pagesIndes[p]; List <int> cells = grid.getCells(center, editorCfg.pageSize); Hashtable map = new Hashtable(); for (int k = 0; k < cells.Count; k++) { if (mapInfor[cells[k]] != null) { map[cells[k]] = mapInfor[cells[k]]; } } areaPageMap[center] = map; } path = Application.dataPath + "/" + CLPathCfg.self.basePath + "/" + CLPathCfg.upgradeRes + "/priority/cfg/worldmap/" + index + ".cfg"; Directory.CreateDirectory(Path.GetDirectoryName(path)); ms = new MemoryStream(); B2OutputStream.writeObject(ms, areaPageMap); File.WriteAllBytes(path, ms.ToArray()); } } Debug.Log("total===" + mapInfor.Count); }