Example #1
0
    public void serilizeServerJceData()
    {
        //序列化服务器需要的数据
        MapLayerConfigServer jceData = new MapLayerConfigServer();

        jceData.iMAxY     = getRowNum();
        jceData.iMaxX     = getColNum();
        jceData.vectSlots = new List <MapSlotInfoServer>();

        for (int y = 0; y < jceData.iMAxY; y++)
        {
            for (int x = 0; x < jceData.iMaxX; x++)
            {
                MapSlotInfoServer jceTileData = new MapSlotInfoServer();

                //瓦片坐标
                jceTileData.iX = x;
                jceTileData.iY = y;

                jceTileData.iTerrainLayer   = getTerrainLayerId(x, y);    //草地
                jceTileData.iTerrainObject  = getTerrainObjectId(x, y);   //椰子树
                jceTileData.iTerrainType    = getTerrainObjectType(x, y); //树
                jceTileData.vectLogicLayers = getLayerId(x, y);

                jceData.vectSlots.Add(jceTileData);
            }
        }

        string path = Application.dataPath + "/slg_server_map.b";

        serilizeJceStruct(jceData, path);
    }
Example #2
0
    private void onClick()
    {
        //打开文件写
        string path = Application.dataPath + "/slg_client_map.b";

        if (forServer)
        {
            path = Application.dataPath + "/slg_server_map.b";
        }
        Debug.Log("b path:" + path);

        FileStream   fileStream   = File.Open(path, FileMode.Open, FileAccess.Read);
        BinaryReader binaryReader = new BinaryReader(fileStream);

        byte[]         bytes       = binaryReader.ReadBytes((int)fileStream.Length);
        JceInputStream inputStream = new JceInputStream(bytes);

        JceStruct jceData = null;

        if (forServer)
        {
            jceData = new MapLayerConfigServer();
        }
        else
        {
            jceData = new MapLayerConfigClient();
        }
        jceData.ReadFrom(inputStream);

        binaryReader.Close();
        fileStream.Close();

        StringBuilder builder = new StringBuilder();

        jceData.Display(builder, 0);
        Debug.Log(builder.ToString());
    }