コード例 #1
0
    // Randomly selects 'uniqueTileCount' number of tile definitions from the tileset and spawns 'totalTileCount' number of them.
    // If totalTileCount is an odd number this will leave a null entry in the array to ensure there are always 2 of every type of tile.
    SpriteTileInfo[] GetRandomTilePairs(int uniqueTileCount, int totalTileCount)
    {
        if (uniqueTileCount > _tileSet.Length)
        {
            Debug.LogWarning("GridController: Not enough unique tiles in tileSet.");
            uniqueTileCount = _tileSet.Length;
        }

        // Shuffle the tileset so we just grab random one from the front of the array
        SpriteTileInfo[] tiles = new SpriteTileInfo[totalTileCount];
        _tileSet.Shuffle();
        int j = 0;

        // Copy tileset info into the array two at a time
        for (int i = 0; i < tiles.Length - 1; i += 2)
        {
            SpriteTileInfo info = _tileSet[j++];
            tiles[i]     = info;
            tiles[i + 1] = info;
            if (j >= uniqueTileCount)
            {
                j = 0;
            }
        }

        // Shuffle the final results into random order
        tiles.Shuffle();

        return(tiles);
    }
コード例 #2
0
 // Update the tile to display the given SpriteTileInfo
 public void SetSpriteTileInfo(SpriteTileInfo info)
 {
     _info            = info;
     _renderer.sprite = _info != null ? _info.sprite : null;
     SetHighlighted(highlighted);
 }