Example #1
0
 public HexagonData(HexCoordinates coordinates, Hexagon.TileType type, int xIndex, int zIndex)
 {
     this.coordinates = coordinates;
     this.type        = type;
     this.xIndex      = xIndex;
     this.zIndex      = zIndex;
 }
Example #2
0
    private void CreateCell(int x, int z, Hexagon.TileType type = Hexagon.TileType.Grass)
    {
        Vector3 position;

        position.x = (x + z * 0.5f - z / 2) * (GridSettings.INNER_RADIUS * 2f);
        position.y = 0f;
        position.z = z * (GridSettings.OUTER_RADIUS * 1.5f);
        HexagonData hexagonData = new HexagonData(HexCoordinates.FromOffsetCoordinates(x, z), type, x, z);

        InitializeCell(GetPrefabFromType(type), position, hexagonData);
    }
Example #3
0
    public void ChangeCellType(Vector3 position, Hexagon.TileType type)
    {
        position = transform.InverseTransformPoint(position);
        HexCoordinates coordinates = HexCoordinates.FromPosition(position);
        int            index       = Hexagon.Index(coordinates, width);
        Hexagon        cell        = cells[index];

        if (cell.HexagonData.Type == type)
        {
            return;
        }

        HexagonData data = new HexagonData(cell.HexagonData.Coordinates, type, cell.HexagonData.XIndex, cell.HexagonData.ZIndex);

        InitializeCell(GetPrefabFromType(type), cell.transform.localPosition, data, index);
        Destroy(cell.gameObject);
    }
Example #4
0
    private Hexagon GetPrefabFromType(Hexagon.TileType type)
    {
        Hexagon prefab;

        switch (type)
        {
        case Hexagon.TileType.Grass:
            prefab = grassHexagon;
            break;

        case Hexagon.TileType.Desert:
            prefab = dirtHexagon;
            break;

        default:
            prefab = grassHexagon;
            break;
        }

        return(prefab);
    }
Example #5
0
 public void SelectType(int index)
 {
     activeType = (Hexagon.TileType)index;
 }