Example #1
0
        public TileMapBlockJsonData GetJsonData(string outputPath)
        {
            string jsonStr = File.ReadAllText(outputPath);

            if (string.IsNullOrEmpty(jsonStr))
            {
                return(null);
            }
            TileMapBlockJsonData tileMapBlockJsonData = JsonUtility.FromJson <TileMapBlockJsonData>(jsonStr);
            int width  = tileMapBlockJsonData.xMax - tileMapBlockJsonData.xMin + 1;
            int height = tileMapBlockJsonData.yMax - tileMapBlockJsonData.yMin + 1;

            tileMapBlockJsonData.ways = GetWays(tileMapBlockJsonData.wayList, width, height);
            return(tileMapBlockJsonData);
        }
Example #2
0
        //构建json数据
        public void BuildJsonData(int xMin, int yMin, int xMax, int yMax, bool[,] _ways, string outputPath)
        {
#if UNITY_EDITOR
            //初始化数据
            TileMapBlockJsonData tileMapBlockJsonData = new TileMapBlockJsonData
            {
                xMin    = xMin,
                yMin    = yMin,
                xMax    = xMax,
                yMax    = yMax,
                wayList = BuildWays(_ways)
            };
            FileStream fs   = new FileStream(outputPath, FileMode.Create);
            byte[]     data = System.Text.Encoding.Default.GetBytes(JsonUtility.ToJson(tileMapBlockJsonData));
            //开始写入
            fs.Write(data, 0, data.Length);
            //清空缓冲区、关闭流
            fs.Flush();
            fs.Close();
#endif
        }