Class TesseraGenerator
GameObjects with this behaviour contain utilities to generate tile based levels using Wave Function Collapse (WFC). Call Generate(TesseraGenerateOptions) or StartGenerate(TesseraGenerateOptions) to run. The generation takes the following steps:
- Inspect the tiles in tiles and work out how they rotate and connect to each other.
- Setup any initial constraints that fix parts of the generation (initialConstraints).
- Fix the boundary of the generation if skyBox is set.
- Generate a set of tile instances that fits the above tiles and constraints.
- Optionally retries or backtrack.
- Instantiates the tile instances.
Namespace: Tessera
Assembly: cs.temp.dll.dll
Syntax
public class TesseraGenerator : MonoBehaviour
Fields
algorithm
Controls the algorithm used internally for Wave Function Collapse.
Declaration
public TesseraWfcAlgorithm algorithm
Field Value
| Type | Description |
|---|---|
| TesseraWfcAlgorithm |
backtrack
If set, backtracking will be used during generation. Backtracking can find solutions that would otherwise be failures, but can take a long time.
Declaration
public bool backtrack
Field Value
| Type | Description |
|---|---|
| Boolean |
contradictionTile
Game object to show in cells that cannot be solved.
Declaration
public GameObject contradictionTile
Field Value
| Type | Description |
|---|---|
| GameObject |
failureMode
Controls what is output when the generation fails.
Declaration
public FailureMode failureMode
Field Value
| Type | Description |
|---|---|
| FailureMode |
filterSurfaceSubmeshTiles
If true, and a surfaceMesh is set with multiple submeshes (materials), then use surfaceSubmeshTiles.
Declaration
public bool filterSurfaceSubmeshTiles
Field Value
| Type | Description |
|---|---|
| Boolean |
recordUndo
Records undo/redo when run by pressing the Generate button in the Inspector.
Declaration
public bool recordUndo
Field Value
| Type | Description |
|---|---|
| Boolean |
retries
If backtracking is off, how many times to retry generation if a solution cannot be found.
Declaration
public int retries
Field Value
| Type | Description |
|---|---|
| Int32 |
scaleUncertainyTile
If true, the uncertainty tiles shrink as the solver gets more certain.
Declaration
public bool scaleUncertainyTile
Field Value
| Type | Description |
|---|---|
| Boolean |
searchInitialConstraints
If true, then active tiles in the scene will be taken as initial constraints. If false, then no initial constraints are used. Using initialConstraints overrides either outcome.
Declaration
public bool searchInitialConstraints
Field Value
| Type | Description |
|---|---|
| Boolean |
skyBox
If set, this tile is used to define extra initial constraints for the boundary.
Declaration
public TesseraTileBase skyBox
Field Value
| Type | Description |
|---|---|
| TesseraTileBase |
stepLimit
How many steps to take before retrying from the start.
Declaration
public int stepLimit
Field Value
| Type | Description |
|---|---|
| Int32 |
surfaceMesh
If set, then tiles are generated on the surface of this mesh instead of a regular grid.
Declaration
public Mesh surfaceMesh
Field Value
| Type | Description |
|---|---|
| Mesh |
surfaceOffset
Height above the surface mesh that the bottom layer of tiles is generated at.
Declaration
public float surfaceOffset
Field Value
| Type | Description |
|---|---|
| Single |
surfaceSmoothNormals
Controls how normals are treated for meshes deformed to fit the surfaceMesh.
Declaration
public bool surfaceSmoothNormals
Field Value
| Type | Description |
|---|---|
| Boolean |
surfaceSubmeshTiles
A list of tiles to filter each submesh of surfaceMesh to. Ignored unless filterSurfaceSubmeshTiles is true.
Declaration
public List<TileList> surfaceSubmeshTiles
Field Value
| Type | Description |
|---|---|
| List<TileList> |
tiles
The list of tiles eligable for generation.
Declaration
public List<TileEntry> tiles
Field Value
| Type | Description |
|---|---|
| List<TileEntry> |
tileSize
The stride between each cell in the generation. "big" tiles may occupy a multiple of this tile size.
Declaration
public Vector3 tileSize
Field Value
| Type | Description |
|---|---|
| Vector3 |
uncertaintyTile
Game object to show in cells that have yet to be fully solved.
Declaration
public GameObject uncertaintyTile
Field Value
| Type | Description |
|---|---|
| GameObject |
Properties
bounds
The area of generation. Setting this will cause the size to be rounded to a multiple of tileSize
Declaration
public Bounds bounds { get; set; }
Property Value
| Type | Description |
|---|---|
| Bounds |
CellType
Indicates the cell type of the tiles set up.
Declaration
public ICellType CellType { get; }
Property Value
| Type | Description |
|---|---|
| ICellType |
center
The local position of the center of the area to generate.
Declaration
public Vector3 center { get; set; }
Property Value
| Type | Description |
|---|---|
| Vector3 |
origin
Declaration
public Vector3 origin { get; set; }
Property Value
| Type | Description |
|---|---|
| Vector3 |
palette
Inherited from the first tile in tiles.
Declaration
public TesseraPalette palette { get; }
Property Value
| Type | Description |
|---|---|
| TesseraPalette |
size
The size of the generator area, counting in cells each of size tileSize.
Declaration
public Vector3Int size { get; set; }
Property Value
| Type | Description |
|---|---|
| Vector3Int |
Methods
Clear()
Clears previously generated content.
Declaration
public void Clear()
Generate(TesseraGenerateOptions)
Synchronously runs the generation process described in the class docs.
Declaration
public TesseraCompletion Generate(TesseraGenerateOptions options = null)
Parameters
| Type | Name | Description |
|---|---|---|
| TesseraGenerateOptions | options |
Returns
| Type | Description |
|---|---|
| TesseraCompletion |
GetCellTypes()
For validation purposes
Declaration
public IList<ICellType> GetCellTypes()
Returns
| Type | Description |
|---|---|
| IList<ICellType> |
GetInitialConstraintBuilder()
Declaration
public TesseraInitialConstraintBuilder GetInitialConstraintBuilder()
Returns
| Type | Description |
|---|---|
| TesseraInitialConstraintBuilder |
GetMissizedTiles()
For validation purposes
Declaration
public IEnumerable<TesseraTileBase> GetMissizedTiles()
Returns
| Type | Description |
|---|---|
| IEnumerable<TesseraTileBase> |
Instantiate(TesseraTileInstance, Transform)
Utility function that instantiates a tile instance in the scene.
This is the default function used when you do not pass onCreate to the Generate method.
It is essentially the same as Unity's normal Instantiate method with extra features:
- respects instantiateChildrenOnly
- applies mesh transformations (Pro only)
Declaration
public static GameObject[] Instantiate(TesseraTileInstance instance, Transform parent)
Parameters
| Type | Name | Description |
|---|---|---|
| TesseraTileInstance | instance | The instance being created. |
| Transform | parent | The game object to parent the new game object to. This does not affect the world position of the instance |
Returns
| Type | Description |
|---|---|
| GameObject[] | The game objects created. |
Regenerate(TesseraGenerateOptions)
Runs Clear, then Generate
Declaration
public TesseraCompletion Regenerate(TesseraGenerateOptions options = null)
Parameters
| Type | Name | Description |
|---|---|---|
| TesseraGenerateOptions | options |
Returns
| Type | Description |
|---|---|
| TesseraCompletion |
StartGenerate(TesseraGenerateOptions)
Asynchronously runs the generation process described in the class docs, for use with StartCoroutine.
Declaration
public EnumeratorWithResult<TesseraCompletion> StartGenerate(TesseraGenerateOptions options = null)
Parameters
| Type | Name | Description |
|---|---|---|
| TesseraGenerateOptions | options |
Returns
| Type | Description |
|---|---|
| EnumeratorWithResult<TesseraCompletion> |
Remarks
The default instantiation is still synchronous, so this can still cause frame glitches unless you override onCreate.