コード例 #1
0
ファイル: Map.cs プロジェクト: jousonren/TileTerrainSystem
        /// <summary>
        /// 初始化默认地形
        /// </summary>
        public void InitinalMap()
        {
            string mapMsg = "";

            if (transform.childCount > 1)
            {
                for (int i = 0; i < chunks2.Count; i++)
                {
                    Destroy(chunks2[i].gameObject);
                }
                chunks  = new Dictionary <Vector3i, Chunk>();
                chunks2 = new List <Chunk>();
                number  = 0;
            }
            heightMap  = new float[(MapLength + 1) * (MapLength + 1)];
            textureMap = new int[MapLength * MapLength];
            byte[]            byteArray = new byte[(MapLength + 1) * (MapLength + 1) * 2];
            StudentCourseInfo info      = JsonMapper.ToObject <StudentCourseInfo>(Resources.Load <DefaultSceneInfo>("Config/DefaultSceneInfo").info);

            mapInfoFromInitinalDemo = info.code;
            JSONNode obj = JSON.Parse(mapInfoFromInitinalDemo);

            mapMsg    = obj["mapInfo"]["mapData"];
            byteArray = System.Convert.FromBase64String(mapMsg);
            for (int j = 0; j < MapLength + 1; j++)
            {
                for (int i = 0; i < MapLength + 1; i++)
                {
                    byteMsg[0] = byteArray[(i + j * (MapLength + 1)) * 2];
                    byteMsg[1] = byteArray[(i + j * (MapLength + 1)) * 2 + 1];
                    TileTerrainMsgTool.ByteToTileMsg(byteMsg, out heightIntNumber, out heightFloatNumber, out TextureNumber);
                    if (i == MapLength || j == MapLength)
                    {
                        heightMap[i + j * (MapLength + 1)] = heightIntNumber - 6f + HeightIntToFloat(heightFloatNumber);
                    }
                    else
                    {
                        heightMap[i + j * (MapLength + 1)] = heightIntNumber - 6f + HeightIntToFloat(heightFloatNumber);
                        textureMap[i + j * MapLength]      = TextureNumber;
                    }
                }
            }
            for (int z = 0; z < 0 + ChunkWidth * chunkLineNumber; z += ChunkWidth)
            {
                for (int x = 0; x < 0 + ChunkWidth * chunkLineNumber; x += ChunkWidth)
                {
                    int xx = ChunkWidth * Mathf.FloorToInt(x / ChunkWidth);
                    int zz = ChunkWidth * Mathf.FloorToInt(z / ChunkWidth);
                    if (!ChunkExists(xx, 0, zz))
                    {
                        CreateChunk(new Vector3i(xx, 0, zz));
                    }
                }
            }
            LoadMapOver?.Invoke();
        }
コード例 #2
0
 public bool AddIntoInfoList()//将当前信息添加至总list中
 {
     if (StuNum == null)
     {
         return(false);               //此项目不存在,返回错误信息
     }
     else
     {
         for (int i = 0; i < StudentCourseInfo.ToArray().Length; i++) //遍历已存储信息,确保未被存储
         {
             if (StuNum == StudentCourseInfo[i].StuNum)               //若已存储此信息则更新之
             {
                 StudentCourseInfo.Remove(StudentCourseInfo[i]);
                 StudentCourseInfo.Add(this);
                 return(true);//更新完成
             }
         }
         StudentCourseInfo.Add(this);
         return(true);//添加成功
     }
 }