コード例 #1
0
    } // Core loop of the algorithm

    private void Collapse(Vector2Int coords)
    {
        int x = coords.x, y = coords.y;

        var gridPos = grid[x + width * y];

        float totalWeight = 0;

        foreach (var possibleTile in gridPos)
        {
            totalWeight += inputReader.GetTileWeight(possibleTile.Module);
        }

        float randVal = UnityEngine.Random.Range(0f, 1f) * totalWeight;

        foreach (var possibleTile in gridPos)
        {
            randVal -= inputReader.GetTileWeight(possibleTile.Module);
            if (randVal <= 0)
            {
                grid[x + width * y] = new[] { possibleTile };
                //GameObject.Instantiate(possibleTile.Module.gameObject, new Vector3(x - (width / 2), height - (y + 1), 0), Quaternion.identity);
                //outputTilemap.SetTile(new Vector3Int(x - (width / 2), height - (y + 1), 0), possibleTile.Module);
                break;
            }
        }

        //Debug.Log("Collapsed at " + coords + ", " + grid[x + width * y].Length + " TotalWeight: " + totalWeight);
    } // collapses the position in grid to a single tile