Ejemplo n.º 1
0
    void LoadLegacy(UnityEngine.Networking.NetworkReader reader)
    {
        int count = reader.ReadInt32();

        Util.Log($"loading {count} legacy cells");
        for (int i = 0; i < count; i++)
        {
            Cell            c    = new Cell(reader.ReadInt32(), reader.ReadInt32(), reader.ReadInt32());
            LegacyBlockInfo info = new LegacyBlockInfo();
            info.SetData(reader.ReadByte());

            CellValue block = new CellValue(info.GetBlockType(), info.GetBlockDirection(), BlockStyle.Stone);
            SetCell(block, c);
            Side westEdge = new Side(c.x, c.y, c.z, CellSide.West);
            SetSide(westEdge, info.WestWall(), BlockStyle.Stone);
            Side southEdge = new Side(c.x, c.y, c.z, CellSide.South);
            SetSide(southEdge, info.SouthWall(), BlockStyle.Stone);
        }
    }
Ejemplo n.º 2
0
    public void Deserialize(byte[] cellBytes)
    {
        Clear();

        // Util.Log($"loading terrain data of {cellBytes.Length} bytes");
        var reader = new UnityEngine.Networking.NetworkReader(cellBytes);
        // Again - kinda awkward to have the deserialize code here.
        int version = reader.ReadInt32();

        if (version == 0)
        {
            Util.LogWarning($"Ignoring terrain version 0");
        }
        else if (version == 1)
        {
            LoadLegacy(reader);
        }
        else if (version == TerrainDatabase.CurrentVersion)
        {
            int blockCount = reader.ReadInt32();
            // Util.Log($"reading {blockCount} blocks");
            for (int i = 0; i < blockCount; i++)
            {
                TerrainDatabase.BlockInfo info = new TerrainDatabase.BlockInfo();
                info.b0 = reader.ReadByte();
                info.b1 = reader.ReadByte();
                Cell c = ReadCell(reader);
                Debug.Assert(info.GetShape() != BlockShape.Empty);
                SetCell(info.ToBlock(), c);
            }

            System.Action <CellSide> LoadSideMap = (CellSide cellSide) =>
            {
                int count = reader.ReadInt32();
                // Util.Log($"Reading {count} {cellSide} walls");
                for (int i = 0; i < count; i++)
                {
                    TerrainDatabase.SideInfo info = new TerrainDatabase.SideInfo();
                    info.b0 = reader.ReadByte();
                    Cell c    = ReadCell(reader);
                    Side side = new Side
                    {
                        side = cellSide,
                        x    = c.x,
                        y    = c.y,
                        z    = c.z
                    };
                    SetSide(side, true, info.GetStyle());
                }
            };

            LoadSideMap.Invoke(CellSide.South);
            LoadSideMap.Invoke(CellSide.West);

            Debug.Assert(reader.ReadByte() == 42, "End-of-buffer sanity check failed!");
        }
        else
        {
            throw new System.Exception($"Given terrain of unknown version: {version}.");
        }
    }
Ejemplo n.º 3
0
 public virtual void Deserialize(UnityEngine.Networking.NetworkReader reader)
 {
     _setId = reader.ReadInt32();
     _currentVariantIndex = reader.ReadInt32();
     _panelLabel          = reader.ReadString();
 }