Show / Hide Table of Contents

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 (searchInitialConstraints and 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.
Inheritance
Object
TesseraGenerator
Namespace: Tessera
Assembly: cs.temp.dll.dll
Syntax
public class TesseraGenerator : MonoBehaviour

Fields

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

initialConstraints

The initial constraints to be used, if searchInitialConstraints is false. This can be filled with objects returned from the GetInitialConstraint methods.

Declaration
public List<TesseraInitialConstraint> initialConstraints
Field Value
Type Description
List<TesseraInitialConstraint>

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

searchInitialConstraints

If true, then active tiles in the scene will be taken as initial constraints. If false, then initialConstraints is used instead.

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 TesseraTile skyBox
Field Value
Type Description
TesseraTile

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

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

center

The local position of the center of the area to generate.

Declaration
public Vector3 center { 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

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

GetInitialConstraint(TesseraTile)

Utility function that gets the initial constraint from a given tile. The tile should be aligned with the grid defined by this generator.

Declaration
public TesseraInitialConstraint GetInitialConstraint(TesseraTile tile)
Parameters
Type Name Description
TesseraTile tile

The tile to inspect

Returns
Type Description
TesseraInitialConstraint

Initial constraint for use with initialConstraints

GetInitialConstraint(TesseraTile, Matrix4x4)

Utility function that gets the initial constraint from a given tile at a given position. The tile should be aligned with the grid defined by this generator.

Declaration
public TesseraInitialConstraint GetInitialConstraint(TesseraTile tile, Matrix4x4 localToWorldMatrix)
Parameters
Type Name Description
TesseraTile tile

The tile to inspect

Matrix4x4 localToWorldMatrix

The matrix indicating the position and rotation of the tile

Returns
Type Description
TesseraInitialConstraint

Initial constraint for use with initialConstraints

GetInitialConstraints()

Utility function that represents what searchInitialConstraints does.

Declaration
public List<TesseraInitialConstraint> GetInitialConstraints()
Returns
Type Description
List<TesseraInitialConstraint>

Initial constraints for use with initialConstraints

Instantiate(TesseraTileInstance)

Declaration
public GameObject[] Instantiate(TesseraTileInstance instance)
Parameters
Type Name Description
TesseraTileInstance instance
Returns
Type Description
GameObject[]

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 iessentially the same as Unity's normal Instantiate method, but it respects instantiateChildrenOnly.

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.

Returns
Type Description
GameObject[]

The game objects created.

StartGenerate(TesseraGenerateOptions)

Asynchronously runs the generation process described in the class docs, for use with StartCoroutine.

Declaration
public IEnumerator StartGenerate(TesseraGenerateOptions options = null)
Parameters
Type Name Description
TesseraGenerateOptions options
Returns
Type Description
IEnumerator
Remarks

The default instantiation is still synchronous, so this can still cause frame glitches unless you override onCreate.

Back to top Generated by DocFX