Runtime Modification
You can of course modify maps at runtime. Here's a simple example code which will add new cells to a layer and execute a build process.
Please have a look at following samples for a more advanced approach:
Deep Rock Crystals URP
Runtime Editor URP
Refer to the API documentation for more:
APINamespace
using GiantGrey.TileWorldCreator;
Add & Remove Cells at runtime
public TileWorldCreatorManager manager;
// Register to blueprint layers ready event
// So we can then execute the build layers.
void OnEnable()
{
manager.OnBlueprintLayersReady += BuildMap;
}
void OnDisable()
{
manager.OnBlueprintLayersReady -= BuildMap;
}
public void AddCells()
{
HashSet<Vector2> positions = new HashSet<Vector2>;
// Add some positions
positions.Add(new Vector2(0.0f, 1.0f));
positions.Add(new Vector2(0.0f, 2.0f));
positions.Add(new Vector2(1.0f, 1.0f));
positions.Add(new Vector2(1.0f, 2.0f));
// Add cells to a layer (MyLayer)
manager.AddCellsToLayer("MyLayer", positions);
// Remove cells from a layer (MyLayer)
//manager.RemoveCellsFromLayer("MyLayer", positions);
// Execute all blueprint layers
manager.ExecuteBlueprintLayers();
}
// As soon as blueprint layers are ready, we call the ExecuteAllBuildLayers
void BuildMap()
{
manager.ExecuteBuildLayers(ExecutionMode.Normal);
}
Last updated