Class GridPlacer
This Unity component manages the grid placing during edit time and runtime.
It will automatically generate a mesh when the world starts, both in editor and in the game. It can also generate the mesh later by calling GenerateNow(Boolean).
Inheritance
Namespace: CarbideFunction.Wildtile
Syntax
public class GridPlacer : MonoBehaviour
Fields
generateOnStartUp
In which environments should this component immediately generate when it spawns? If disabled, other code must trigger GridPlacer to build.
Declaration
public GridPlacer.GenerateOnStartUp generateOnStartUp
Field Value
Type | Description |
---|---|
GridPlacer.GenerateOnStartUp |
maxCollapseSteps
How many wave function collapse steps will be performed before Wildtile believes it is in an infinite loop and stops the process.
You may need to increase this for large maps and/or large tilesets.
Declaration
public int maxCollapseSteps
Field Value
Type | Description |
---|---|
System.Int32 |
maxInGameSecondsPerFrame
When using GenerateOverTime(GridPlacer.OnGenerationComplete) in game, GridPlacer will attempt to run the generation for this number of seconds each frame.
GridPlacer will run its placement algorithm for at least this long before relinquishing control to other systems in Unity. GridPlacer will always take slightly longer than the specified amount.
If you are running a framerate critical game then you can reduce this budget to ensure that the framerate always stays above your target.
Conversely, raising the budget will reduce the real-time delay before the map is available. Unity will execute fewer gameloops, so more CPU time will be focused on GridPlacer.
This value is ignored whilst in editor - the value from your "Preferences → Wildtile → Maximum GridPlacer Seconds Per Frame In Editor" is used instead.
Declaration
public float maxInGameSecondsPerFrame
Field Value
Type | Description |
---|---|
System.Single |
maxPostprocessSteps
How many object placement/welding steps will be performed before Wildtile believes it is in an infinite loop and stops the process.
You may need to increase this for large maps and/or highly detailed tilesets.
Declaration
public int maxPostprocessSteps
Field Value
Type | Description |
---|---|
System.Int32 |
onFoundCollapsableState
Called when the collapse algorithm has added wildcards and found a collapsable state. It will now attempt to remove redundant wildcards.
This will only be called if the perfect collapse fails, which would be reported through onPerfectCollapseFailed.
Declaration
public GridPlacer.OnCollapseEvent onFoundCollapsableState
Field Value
Type | Description |
---|---|
GridPlacer.OnCollapseEvent |
onPerfectCollapseFailed
Called when the collapse algorithm finds that it cannot collapse the initial state without adding wildcards.
Declaration
public GridPlacer.OnCollapseEvent onPerfectCollapseFailed
Field Value
Type | Description |
---|---|
GridPlacer.OnCollapseEvent |
onPerfectCollapseSucceeded
Called when the collapse algorithm completes without adding any new wildcards.
Declaration
public GridPlacer.OnCollapseEvent onPerfectCollapseSucceeded
Field Value
Type | Description |
---|---|
GridPlacer.OnCollapseEvent |
onRemovedRedundantWildcards
Called when the collapse algorithm has removed wildcards and found a minimal-wildcard collapsable state.
This will only be called if the perfect collapse fails, which would be reported through onPerfectCollapseFailed.
This will be called after onFoundCollapsableState.
Declaration
public GridPlacer.OnCollapseEvent onRemovedRedundantWildcards
Field Value
Type | Description |
---|---|
GridPlacer.OnCollapseEvent |
seed
Changing the seed may cause the GridPlacer to place different tiles across the map. Tilesets must have multiple options for this to have any effect.
A GridPlacer with the same map, tileset, and seed will always place modules in the same way.
Declaration
public int seed
Field Value
Type | Description |
---|---|
System.Int32 |
showObjectsInHierarchy
Show generated level objects in the hierarchy view. All edits will be discarded when starting the game or changing scenes regardless of whether this option is checked or not.
Declaration
public bool showObjectsInHierarchy
Field Value
Type | Description |
---|---|
System.Boolean |
voxelGrid
This GridPlacer's map of voxels. It contains a 3D grid of voxels, and the GridPlacer will attempt to place modules around the borders between the filled and empty tiles.
Declaration
public VoxelGridAsset voxelGrid
Field Value
Type | Description |
---|---|
VoxelGridAsset |
Properties
IsGenerating
Returns true if this GridPlacer is currently at any stage of placing modules (e.g. collapsing the wave function, warping or welding models).
Declaration
public bool IsGenerating { get; }
Property Value
Type | Description |
---|---|
System.Boolean |
Tileset
Readonly access to the tileset that is used by this GridPlacer instance.
Declaration
public Tileset Tileset { get; }
Property Value
Type | Description |
---|---|
Tileset |
Methods
ClearChildren()
Destroy children of this GridPlacer's Transform.
GridPlacer creates modules as children of its Transform, so in normal operation this will destroy a GridPlacer-generated map. If other scripts modify the hierarchy (move GridPlacer generated objects out, add non-GridPlacer child objects) then this may have unintended behaviour.
Declaration
public void ClearChildren()
GenerateNow(Boolean)
Generates a new mesh of modules using the associated voxelGrid and tileset assets, and returns once the mesh is fully generated.
Declaration
public void GenerateNow(bool clearExisting = true)
Parameters
Type | Name | Description |
---|---|---|
System.Boolean | clearExisting | If true, clear all of this transform's children before generating the new mesh from the assets. |
GenerateOverTime(GridPlacer.OnGenerationComplete)
Starts generateing a new mesh of modules using the associated voxelGrid and tileset assets over time.
Declaration
public void GenerateOverTime(GridPlacer.OnGenerationComplete onGenerationComplete = null)
Parameters
Type | Name | Description |
---|---|---|
GridPlacer.OnGenerationComplete | onGenerationComplete | Called when the coroutine finishes creating the transformation of the voxel grid into models |
InterruptMeshGeneration()
Stop the generation that's currently in progress if there was one. This is silently ignored if there was no generation started, or if the generation has already completed.
Declaration
public void InterruptMeshGeneration()
SetTileset(Tileset)
Set this GridPlacer's tileset and prepare any internal state required when tilesets change.
Declaration
public void SetTileset(Tileset tileset)
Parameters
Type | Name | Description |
---|---|---|
Tileset | tileset |