コード例 #1
0
ファイル: HexGrid.cs プロジェクト: Joffyn/HexGridGame
    public void Load(BinaryReader reader, int header)
    {
        ClearPath();
        ClearUnits();

        int x = 20, z = 15;

        if (header >= 1)
        {
            x = reader.ReadInt32();
            z = reader.ReadInt32();
        }
        if (!CreateMap(x, z))
        {
            return;
        }
        for (int i = 0; i < cells.Length; i++)
        {
            cells[i].Load(reader);
        }
        for (int i = 0; i < chunks.Length; i++)
        {
            chunks[i].Refresh();
        }
        if (header >= 2)
        {
            int unitCount = reader.ReadInt32();
            for (int i = 0; i < unitCount; i++)
            {
                HexUnit.Load(reader, this);
            }
        }
    }
コード例 #2
0
    private void LoadUnit(System.IO.BinaryReader reader)
    {
        HexUnit unit = Instantiate(unitPrefab);

        unit.Load(reader, this);
        unitList.Add(unit);
    }
コード例 #3
0
    public void Load(BinaryReader reader)
    {
        ClearPath();
        ClearUnits();

        bool originalImmediateMode = m_hexCellShaderData.ImmediateMode;

        m_hexCellShaderData.ImmediateMode = true;

        for (int i = 0; i < m_cells.Count; i++)
        {
            m_cells[i].Load(reader);
        }

        for (int i = 0; i < m_gridChunks.Length; i++)
        {
            m_gridChunks[i].Refresh();
        }


        int unitCount = reader.ReadInt32();

        for (int i = 0; i < unitCount; i++)
        {
            HexUnit.Load(reader, this);
        }
        m_hexCellShaderData.ImmediateMode = originalImmediateMode;
    }
コード例 #4
0
ファイル: Team.cs プロジェクト: Tuto96/GridTemplateProject
 public void Load(BinaryReader reader, int header)
 {
     if (header >= 2)
     {
         teamIndex = reader.ReadByte();
         int unitCount = reader.ReadInt32();
         for (int i = 0; i < unitCount; i++)
         {
             HexUnit.Load(reader, header);
         }
     }
 }
コード例 #5
0
    /// <summary>
    /// 读取
    /// </summary>
    /// <param name="reader"></param>
    /// <param name="header"></param>
    public void Load(MyReader reader, int header)
    {
        //if (coroutine != null)
        //{
        //    StopCoroutine(coroutine);
        //}
        ClearMap();
        int x = 20, z = 15;

        if (header >= SaveLoadModule.version_1)
        {
            x = reader.ReadInt32();
            z = reader.ReadInt32();
        }

        bool isWrapping = header >= SaveLoadModule.version_5 && reader.ReadBoolean();

        if (x != cellCountX || z != cellCountZ || wrapping != isWrapping)
        {
            if (!CreateMap(x, z, isWrapping))
            {
                return;
            }
        }


        var originalImmediateMode = cellShaderData.ImmediateMode;

        cellShaderData.ImmediateMode = true;
        foreach (var item in cells)
        {
            item.Load(reader, header);
        }

        foreach (var item in cells)
        {
            item.RefreshPosition();
            item.Refresh();
        }

        if (header >= SaveLoadModule.version_2)
        {
            int unitCount = reader.ReadInt32();
            for (int i = 0; i < unitCount; i++)
            {
                HexUnit.Load(reader, this);
            }
        }

        cellShaderData.ImmediateMode = originalImmediateMode;
    }
コード例 #6
0
    public void Load(BinaryReader reader, int header)
    {
        ClearPath();
        ClearUnits();

        int x = 20, z = 15;

        if (header >= 1)
        {
            x = reader.ReadInt32();
            z = reader.ReadInt32();
        }
        bool wrapping = header >= 5 ? reader.ReadBoolean() : false;

        if (x != cellCountX || z != cellCountZ || this.wrapping != wrapping)
        {
            if (!CreateMap(x, z, wrapping))
            {
                return;
            }
        }

        bool originalImmediateMode = cellShaderData.ImmediateMode;

        cellShaderData.ImmediateMode = true;

        for (int i = 0; i < cells.Length; i++)
        {
            cells[i].Load(reader, header);
        }

        for (int i = 0; i < chunks.Length; i++)
        {
            chunks[i].Refresh();
        }

        if (header >= 2)
        {
            int unitCount = reader.ReadInt32();
            for (int i = 0; i < unitCount; i++)
            {
                HexUnit.Load(reader, this);
            }
        }

        cellShaderData.ImmediateMode = originalImmediateMode;
    }
コード例 #7
0
    public void Load(BinaryReader reader, int header)
    {
        ClearPath();
        ClearUnits();
        int x = 20, z = 15;

        if (header >= 1)
        {
            x = reader.ReadInt32();
            z = reader.ReadInt32();
        }

        if ((x != this.cellCountX) || (z != this.cellCountZ))
        {
            if (!CreateMap(x, z))
            {
                return;
            }
        }

        bool originalImmediateMode = cellShaderData.ImmediateMode;

        cellShaderData.ImmediateMode = true;

        foreach (var c in this.cells)
        {
            c.Load(reader, header);
        }

        foreach (var c in this.chunks)
        {
            c.Refresh();
        }

        if (header >= 2)
        {
            var unitCount = reader.ReadInt32();

            for (var i = 0; i < unitCount; i++)
            {
                HexUnit.Load(reader, this);
            }
        }

        cellShaderData.ImmediateMode = originalImmediateMode;
    }
コード例 #8
0
    public void Load(BinaryReader reader)
    {
        ClearPath();         // Clear any pathfinding highlighting
        ClearUnits();        // Clear Units

        // Read map size
        int x = reader.ReadInt32();
        int z = reader.ReadInt32();

        Wrapping = reader.ReadBoolean();

        // If map different size then create new map else just overwrite old cell data
        if (x != CellCountX || z != CellCountZ)
        {
            if (!CreateMap(x, z, Wrapping))
            {
                return;
            }
        }

        bool originalImmediateMode = cellShaderData.ImmediateMode;

        // Avoid lag of transitioning the whole map to visible
        // If cells were already visible before then no transition needed now that we load the map
        cellShaderData.ImmediateMode = true;

        for (int i = 0; i < Cells.Length; i++)
        {
            Cells[i].Load(reader);
        }

        for (int i = 0; i < Chunks.Length; i++)
        {
            Chunks[i].Refresh();
        }

        int unitCount = reader.ReadInt32();

        for (int i = 0; i < unitCount; i++)
        {
            HexUnit.Load(reader, this);
        }

        cellShaderData.ImmediateMode = originalImmediateMode;         // Restore the option
    }
コード例 #9
0
ファイル: HexGrid.cs プロジェクト: JackeyZ/HexMap
    /// <summary>
    /// 从文件加载所有六边形数据
    /// </summary>
    /// <param name="writer"></param>
    /// <param name="header">地图版本号,可根据不同版本号作对应操作</param>
    public void Load(BinaryReader reader, int header)
    {
        bool originalImmediateMode = cellShaderData.ImmediateMode;

        // 战争迷雾立即过渡
        cellShaderData.ImmediateMode = true;

        // 清理之前的寻路路径
        ClearPath();

        // 清理移动单位
        ClearUnits();

        // 读取地图大小并创建对应大小的地图
        int x = reader.ReadInt32();
        int z = reader.ReadInt32();

        // 当加载的地图与当前场景的地图大小不一致的时候才重新创建地图
        if (x != cellCountX || z != cellCountZ)
        {
            if (!CreateMap(x, z))
            {
                return;
            }
        }
        for (int i = 0; i < cells.Length; i++)
        {
            cells[i].Load(reader, header);
        }

        // 存档版本2以上才有移动单位数据
        if (header >= 2)
        {
            // 读取移动单位
            int unitCount = reader.ReadInt32();
            for (int i = 0; i < unitCount; i++)
            {
                HexUnit.Load(reader, this);
            }
        }

        // 恢复战争迷雾过渡模式
        cellShaderData.ImmediateMode = originalImmediateMode;
    }
コード例 #10
0
    public void Load(BinaryReader reader, int header)
    {
        // StopAllCoroutines();
        ClearPath();
        ClearUnits();

        int x = 20, z = 15;

        if (header >= 1)
        {
            x = reader.ReadInt32();
            z = reader.ReadInt32();
        }
        if (x != cellCountX || z != cellCountZ)
        {
            if (!CreateMap(x, z))
            {
                return;
            }
        }

        for (int count = 0; count < hexCells.Length; count++)
        {
            hexCells[count].Load(reader);
        }

        for (int count = 0; count < chunks.Length; count++)
        {
            chunks[count].Refresh();
        }

        if (header >= 2)
        {
            int unitCount = reader.ReadInt32();
            for (int i = 0; i < unitCount; i++)
            {
                HexUnit.Load(reader, this);
            }
        }
    }
コード例 #11
0
    public void Load(BinaryReader reader, int header)
    {
        ClearPath();
        ClearUnits();
        int x = 20, y = 15;

        if (header >= 1)
        {
            x = reader.ReadInt32();
            y = reader.ReadInt32();
        }
        if ((x != cellCountX || y != cellCountY) && !CreateMap(x, y))
        {
            return;
        }

        bool originalImmediateMode = cellShaderData.ImmediateMode;

        cellShaderData.ImmediateMode = true;

        for (int c = 0; c < cells.Length; c++)
        {
            cells [c].Load(reader, header);
        }
        for (int c = 0; c < chunks.Length; c++)
        {
            chunks [c].Refresh();
        }

        if (header >= 2)
        {
            int unitCount = reader.ReadInt32();
            for (int i = 0; i < unitCount; i++)
            {
                HexUnit.Load(reader, this);
            }
        }

        cellShaderData.ImmediateMode = originalImmediateMode;
    }
コード例 #12
0
    /// <summary>
    /// Загрузка грида
    /// </summary>
    /// <param name="reader"></param>
    public void Load(BinaryReader reader, int header)
    {
        ClearPath();
        ClearUnits();

        //загрзка ландшафта(формат 0 и выше)

        //нулевой формат формат
        int x = 20, z = 15;

        //первый формат
        if (header >= 1)
        {
            x = reader.ReadInt32();
            z = reader.ReadInt32();
        }

        bool wrapping = header >= 5 ? reader.ReadBoolean() : false;

        //Заново карту при одинаковых параметрах грида не генерим
        if (x != cellCountX || z != cellCountZ || this.wrapping != wrapping)
        {
            if (!CreateMap(x, z, wrapping))
            {
                return;
            }
        }

        bool originalImmediateMode = cellShaderData.ImmediateMode;

        //отключение зон частичной видимости во время движения для уменьшения нагрузки во время загрузки
        cellShaderData.ImmediateMode = true;

        for (int i = 0; i < cells.Length; i++)
        {
            cells[i].Load(reader, header);
        }
        for (int i = 0; i < chunks.Length; i++)
        {
            chunks[i].Refresh();
        }

        //загрузка юнитов (формат шесть и выше)
        if (header >= 6)
        {
            int unitCount = reader.ReadInt32();
            for (int i = 0; i < unitCount; i++)
            {
                HexUnit.Load(reader, this, true);
            }
        }
        else if (header < 6)//загрузка юнитов (формат ниже шестого)
        {
            int unitCount = reader.ReadInt32();
            for (int i = 0; i < unitCount; i++)
            {
                HexUnit.Load(reader, this);
            }
        }

        cellShaderData.ImmediateMode = originalImmediateMode;
    }
コード例 #13
0
    public void Load(BinaryReader reader, int header)
    {
        ClearPath();
        ClearUnits();
        int x = 20, z = 15;

        if (header >= 1)
        {
            x = reader.ReadInt32();
            z = reader.ReadInt32();
        }
        bool wrapping = header >= 5 ? reader.ReadBoolean() : false;

        wrapping = false;
        if (x != cellCountX || z != cellCountZ || this.wrapping != wrapping)
        {
            if (!CreateMap(x, z, wrapping))
            {
                Debug.LogError("HexGrid Load() Error - ReCreateMap Failed!");
                return;
            }
        }

        bool originalImmediateMode = cellShaderData.ImmediateMode;

        cellShaderData.ImmediateMode = true;

        HexCell.showLabel = showLabel;
        for (int i = 0; i < cells.Length; i++)
        {
            cells[i].Load(reader, header);
        }

        // Unit数据现在该为其他地方读取了(参考RoomServer里的ActorManager.LoadBuffer())
        if (header >= 2 && header <= 6)
        {
            int unitCount = reader.ReadInt32();
            for (int i = 0; i < unitCount; i++)
            {
                HexUnit.Load(reader, this);
            }
        }

        // header version 6
        if (header >= 6)
        {        // 读取资源层resLayer的数据
            // Sand-0; Grass-1; Mud-2; Stone-3; Snow-4
            int[] terrainTypeCount = { 0, 0, 0, 0, 0 };
            for (int i = 0; i < cells.Length; i++)
            {
                terrainTypeCount[cells[i].TerrainTypeIndex]++;
            }

            Debug.Log($"HexGrid Load - Terrain Type Count - Sand:{terrainTypeCount[0]} - Grass:{terrainTypeCount[1]} - Mud:{terrainTypeCount[2]} - Stone:{terrainTypeCount[3]} - Snow:{terrainTypeCount[4]}");

            List <int> resList  = new List <int>();
            int        resCount = reader.ReadInt32();
            Debug.Log($"HexGrid Load - Res Count Total:{resCount}");
            int[] resTypeCount = { 0, 0, 0 };
            for (int i = 0; i < resCount; i++)
            {
                int index = reader.ReadInt32();
                var res   = resLayer[index];
                res.Load(reader, header);
                resList.Add(index);
                cells[index].UpdateFeatureLevelFromRes();

                resTypeCount[(int)resLayer[index].ResType]++;
            }

            string format = string.Format("HexGrid Load - Res Count Wood:{0}({1:P})", resTypeCount[0],
                                          resTypeCount[0] / (float)terrainTypeCount[1]);
            format += string.Format("Res Count Food:{0}({1:P})", resTypeCount[1],
                                    resTypeCount[1] / (float)terrainTypeCount[2]);
            format += string.Format("Res Count Iron:{0}({1:P})", resTypeCount[2],
                                    resTypeCount[2] / (float)terrainTypeCount[3]);
            Debug.Log(format);
        }

        // 把所有数据都变成模型
        for (int i = 0; i < chunks.Length; i++)
        {
            chunks[i].Refresh();
        }

        cellShaderData.ImmediateMode = originalImmediateMode;
    }