Example #1
0
    void CreateCell(int column, int row, bool load)
    {
        Vector3 position;

        position.x = (column + row * 0.5f - row / 2) * (HexCell.Geometry.innerRadius * 2f);
        position.y = 0f;
        position.z = row * (HexCell.Geometry.outerRadius * 1.5f);

        HexCell cell = cells[GetCellIndex(column, row)] = Instantiate <HexCell>(cellPrefab);

        cell.transform.SetParent(transform, false);
        cell.transform.localPosition = position;
        cell.coordinates             = HexCoordinates.FromOffsetCoordinates(column, row);
        cell.color  = HexCell.defaultColor;
        cell.row    = row;
        cell.column = column;

        if (load)
        {
            MapSerializer.CellProperties cellProperties = mapSerializer.GetValue(column, row);
            cell.SetType(cellProperties.m_Type);
        }

        Text label = Instantiate <Text>(cellLabelPrefab);

        label.rectTransform.SetParent(gridCanvas.transform, false);
        label.rectTransform.anchoredPosition = new Vector2(position.x, position.z);
        label.text = cell.coordinates.ToStringOnSeparateLines();
    }
Example #2
0
    public void SaveMap()
    {
        Debug.Assert((mapAsset != null), "Invalid map asset");
        if (mapAsset != null)
        {
            mapSerializer = new MapSerializer(width, height);

            for (int row = 0; row < height; row++)
            {
                for (int column = 0; column < width; column++)
                {
                    int     index = GetCellIndex(column, row);
                    HexCell cell  = cells[index];

                    MapSerializer.CellProperties cellProperties = new MapSerializer.CellProperties();
                    cellProperties.m_Type = cell.GetType();

                    mapSerializer.SetValue(column, row, cellProperties);
                }
            }

            mapSerializer.Save(mapAsset);
        }
    }