Skip to content

Commit

Permalink
edit read me
Browse files Browse the repository at this point in the history
  • Loading branch information
ahmdesmail0 committed Oct 17, 2022
1 parent befe0c2 commit 037f008
Showing 1 changed file with 17 additions and 9 deletions.
26 changes: 17 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,46 +43,54 @@ Keep in mind that the Building performance depends on two factors the size of th
### Runtime Example

```csharp
using UnityEngine;
using AutoLevel;

public class RuntimeExample : MonoBehaviour
{
[SerializeField]
public BlocksRepo repo;
[SerializeField]
public BoundsInt bounds;

private LevelData levelData;
private BlocksRepo.Runtime runtimeRepo;
private LevelMeshBuilder meshBuilder;
private LevelData levelData;
private LevelSolver solver;

private void OnEnable()
{
//generate blocks connections, variants and other configuration
repo.Generate();
BlocksRepo.Runtime runtimeRepo = repo.CreateRuntime();

//a container for the solver result
levelData = new LevelData(bounds);
meshBuilder = new LevelMeshBuilder(levelData,repo);
meshBuilder = new LevelMeshBuilder(levelData, runtimeRepo);

solver = new LevelSolver(bounds.size);
solver.repo = repo;
solver.levelData = levelData;
solver.SetRepo(runtimeRepo);
solver.SetlevelData(levelData);

//set the bottom boundary
solver.SetBoundary(
new GroupsBoundary(runtimeRepo.GetGroupIndex(BlocksRepo.SOLID_GROUP)), Direction.Down);
}

private void OnDisable()
{
repo.Clear();
runtimeRepo.Dispose();
meshBuilder.Dispose();
}

private void Update()
{
if (Input.GetKeyDown(KeyCode.R))
Rebuild();
Rebuild(bounds);
}

void Rebuild()
void Rebuild(BoundsInt bounds)
{
//solve the level, this will return the number of iteration it took,
//run the solver, this will return the number of iteration it took,
//0 means the solver has failed
var iterations = solver.Solve(bounds);
if (iterations > 0)
Expand Down

0 comments on commit 037f008

Please sign in to comment.