Beispiel #1
0
    private void SetDiscMapTilesNeighbourhood()
    {
        int[] xNeighbor = new int[6] {
            0, 1, 1, 0, -1, -1
        };
        int[] yNeighbor = new int[6] {
            -1, -1, 0, 1, 1, 0
        };
        HexTile neighbor;

        foreach (HexTile h in Tiles)
        {
            if (h != null)
            {
                foreach (HexTile.eDirection d in Enum.GetValues(typeof(HexTile.eDirection)))
                {
                    neighbor = Tiles[h.AxialX + xNeighbor[(int)d], h.AxialY + yNeighbor[(int)d], h.Level];

                    h.SetNeighbour(neighbor, d);
                }

                HexTile.eLevel otherSide = h.Level == HexTile.eLevel.Up ? HexTile.eLevel.Down : HexTile.eLevel.Up;

                if (Tiles[h.AxialX, h.AxialY, otherSide] != null)
                {
                    h.OtherSide = Tiles[h.AxialX, h.AxialY, otherSide];
                }
            }
        }
    }
Beispiel #2
0
    public T this[int keyX, int keyY, HexTile.eLevel level]
    {
        get
        {
            if (keyX < MinX || keyX > MaxX ||
                keyY < MinY || keyY > MaxY)
            {
                return(default(T));
            }

            int levelIndex = level == HexTile.eLevel.Up ? 0 : 1;

            return(list[keyX - MinX, keyY - MinY, levelIndex]);
        }

        set
        {
            int levelIndex = level == HexTile.eLevel.Up ? 0 : 1;
            list[keyX - MinX, keyY - MinY, levelIndex] = value;
        }
    }
Beispiel #3
0
    private void GenerateRingMap(int ringMin, int ringMax, HexTile.eLevel level)
    {
        InitializeTileMatrix(-ringMax, ringMax, -ringMax, ringMax);

        HexTile h;

        //HexTile h = HexTile.CreateTile(this.transform, 0, 0, level);
        //h.GetComponentInChildren<Renderer>().sharedMaterial.color = Color.white;
        //Tiles[0, 0, level] = h;

        for (int r = ringMin; r <= ringMax; ++r)
        {
            for (int x = 0; x < r; ++x)
            {
                //North
                h = HexTile.CreateTile(this.transform, x, -r, level);
                Tiles[x, -r, level] = h;

                //NorthEast
                h = HexTile.CreateTile(this.transform, r, -r + x, level);
                Tiles[r, -r + x, level] = h;

                //SouthEast
                h = HexTile.CreateTile(this.transform, r - x, x, level);
                Tiles[r - x, x, level] = h;

                //South
                h = HexTile.CreateTile(this.transform, -x, r, level);
                Tiles[-x, r, level] = h;

                //SouthWest
                h = HexTile.CreateTile(this.transform, -r, r - x, level);
                Tiles[-r, r - x, level] = h;

                //NorthWest
                h = HexTile.CreateTile(this.transform, x - r, -x, level);
                Tiles[x - r, -x, level] = h;
            }
        }
    }