Update
This commit is contained in:
81
Assets/Scripts/GameSetup/Maze/MazeManager.cs
Normal file
81
Assets/Scripts/GameSetup/Maze/MazeManager.cs
Normal file
@@ -0,0 +1,81 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Hallucinate.GameSetup.Maze
|
||||
{
|
||||
/// <summary>
|
||||
/// Central controller for the Maze system.
|
||||
/// Manages algorithm selection, debug speed, and regeneration.
|
||||
/// </summary>
|
||||
public class MazeManager : MonoBehaviour
|
||||
{
|
||||
public enum AlgorithmType { Recursive, Wilsons, Prims, Crawler }
|
||||
|
||||
[Header("System Settings")]
|
||||
[SerializeField] private AlgorithmType selectedAlgorithm;
|
||||
[SerializeField] private int width = 30;
|
||||
[SerializeField] private int depth = 30;
|
||||
|
||||
[Header("Debug Settings")]
|
||||
[SerializeField] private bool debugMode = true;
|
||||
[Range(0.001f, 0.5f)]
|
||||
[SerializeField] private float visualizationInterval = 0.05f;
|
||||
|
||||
[Header("References")]
|
||||
[SerializeField] private MazeRenderer mazeRenderer;
|
||||
[SerializeField] private Transform mazeContainer;
|
||||
|
||||
private MazeGrid _grid;
|
||||
private Coroutine _generationCoroutine;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
Regenerate();
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (Input.GetKeyDown(KeyCode.R))
|
||||
{
|
||||
Regenerate();
|
||||
}
|
||||
}
|
||||
|
||||
[ContextMenu("Regenerate")]
|
||||
public void Regenerate()
|
||||
{
|
||||
if (_generationCoroutine != null)
|
||||
{
|
||||
StopCoroutine(_generationCoroutine);
|
||||
}
|
||||
|
||||
mazeRenderer.Clear();
|
||||
_grid = new MazeGrid(width, depth);
|
||||
mazeRenderer.Initialize(_grid, mazeContainer);
|
||||
|
||||
IMazeAlgorithm algorithm = GetAlgorithm(selectedAlgorithm);
|
||||
|
||||
if (debugMode)
|
||||
{
|
||||
_generationCoroutine = StartCoroutine(algorithm.GenerateStepByStep(_grid, visualizationInterval));
|
||||
}
|
||||
else
|
||||
{
|
||||
algorithm.Generate(_grid);
|
||||
}
|
||||
}
|
||||
|
||||
private IMazeAlgorithm GetAlgorithm(AlgorithmType type)
|
||||
{
|
||||
return type switch
|
||||
{
|
||||
AlgorithmType.Recursive => new RecursiveAlgorithm(),
|
||||
AlgorithmType.Wilsons => new WilsonsAlgorithm(),
|
||||
AlgorithmType.Prims => new PrimsAlgorithm(),
|
||||
AlgorithmType.Crawler => new CrawlerAlgorithm(),
|
||||
_ => new RecursiveAlgorithm()
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user