update
This commit is contained in:
@@ -31,6 +31,12 @@ namespace Baba_yaga.GameSetup.MazeRework
|
||||
|
||||
private List<MazeReworkCellType[,]> _grids = new List<MazeReworkCellType[,]>();
|
||||
|
||||
/// <summary>
|
||||
/// World-space position of the Beginning (Start) cell on floor 0.
|
||||
/// Available after GenerateAndSpawn() completes. Fallback is Vector3.zero.
|
||||
/// </summary>
|
||||
public static Vector3 BeginningWorldPosition { get; private set; } = Vector3.zero;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
GenerateAndSpawn();
|
||||
@@ -119,6 +125,10 @@ namespace Baba_yaga.GameSetup.MazeRework
|
||||
float yOffset = i * floorHeight;
|
||||
spawner.Spawn(_grids[i], yOffset, mazeContainer);
|
||||
}
|
||||
|
||||
// Compute and cache the world-space Beginning position from floor 0
|
||||
BeginningWorldPosition = FindBeginningWorldPosition(_grids[0]);
|
||||
Debug.Log($"[MazeReworkManager] Beginning world position set to: {BeginningWorldPosition}");
|
||||
}
|
||||
|
||||
private void GenerateConnections()
|
||||
@@ -184,5 +194,30 @@ namespace Baba_yaga.GameSetup.MazeRework
|
||||
type == MazeReworkCellType.Start ||
|
||||
type == MazeReworkCellType.End;
|
||||
}
|
||||
|
||||
private Vector3 FindBeginningWorldPosition(MazeReworkCellType[,] grid)
|
||||
{
|
||||
if (grid == null) return Vector3.zero;
|
||||
|
||||
int width = grid.GetLength(0);
|
||||
int depth = grid.GetLength(1);
|
||||
|
||||
for (int z = 0; z < depth; z++)
|
||||
{
|
||||
for (int x = 0; x < width; x++)
|
||||
{
|
||||
if (grid[x, z] == MazeReworkCellType.Start)
|
||||
{
|
||||
// Convert grid coordinates to world space using spawner spacing
|
||||
float spacing = spawner != null ? spawner.spacing : 3.0f;
|
||||
Vector3 containerOffset = mazeContainer != null ? mazeContainer.position : Vector3.zero;
|
||||
return containerOffset + new Vector3(x * spacing, 0f, z * spacing);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Debug.LogWarning("[MazeReworkManager] No Start cell found in the grid. Defaulting to Vector3.zero.");
|
||||
return Vector3.zero;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,6 +21,12 @@ namespace Baba_yaga.GameSetup.MazeRework
|
||||
[Tooltip("Prefab for U-Turn 'U' (Dead end - 1 path).")]
|
||||
public GameObject uTurnPrefab;
|
||||
|
||||
[Header("Special Modular Prefabs")]
|
||||
[Tooltip("Prefab for the Beginning cell (player spawn point). Auto-rotates based on neighbors.")]
|
||||
public GameObject beginningPrefab;
|
||||
[Tooltip("Prefab for the End cell (player exit point). Auto-rotates based on neighbors.")]
|
||||
public GameObject endPrefab;
|
||||
|
||||
[Header("Rotation Offsets (Degrees)")]
|
||||
[Tooltip("Rotation offset added to Hall 'I' prefab.")]
|
||||
public float hallRotationOffset = 0f;
|
||||
@@ -32,6 +38,10 @@ namespace Baba_yaga.GameSetup.MazeRework
|
||||
public float turnRotationOffset = 0f;
|
||||
[Tooltip("Rotation offset added to U-Turn 'U' prefab.")]
|
||||
public float uTurnRotationOffset = 0f;
|
||||
[Tooltip("Rotation offset added to Beginning prefab.")]
|
||||
public float beginningRotationOffset = 0f;
|
||||
[Tooltip("Rotation offset added to End prefab.")]
|
||||
public float endRotationOffset = 0f;
|
||||
|
||||
[Header("Spacing Settings")]
|
||||
[Tooltip("Physical distance between each grid cell center.")]
|
||||
@@ -50,6 +60,12 @@ namespace Baba_yaga.GameSetup.MazeRework
|
||||
{
|
||||
Debug.LogWarning("<b>[MazeReworkSpawner]</b> One or more modular hallway prefabs are not assigned in the Inspector! Please assign your Hall, HallDoubleRoom, HallT, turn, and U-Turn prefabs.", this);
|
||||
}
|
||||
|
||||
if (beginningPrefab == null)
|
||||
Debug.LogWarning("<b>[MazeReworkSpawner]</b> Beginning prefab is not assigned. The spawn point cell will fall back to modular hallway pieces.", this);
|
||||
|
||||
if (endPrefab == null)
|
||||
Debug.LogWarning("<b>[MazeReworkSpawner]</b> End prefab is not assigned. The exit point cell will fall back to modular hallway pieces.", this);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -91,7 +107,23 @@ namespace Baba_yaga.GameSetup.MazeRework
|
||||
continue;
|
||||
}
|
||||
|
||||
// Evaluate connectivity of path cells to select and rotate the modular hallway prefab
|
||||
// For Start and End cells, use their dedicated prefab if assigned,
|
||||
// then apply connectivity-based rotation so they face the correct open direction.
|
||||
if (type == MazeReworkCellType.Start && beginningPrefab != null)
|
||||
{
|
||||
(_, float baseRot) = GetModularPrefabAndRotation(grid, x, z, width, depth);
|
||||
SpawnPrefab(beginningPrefab, x, yOffset, z, baseRot + beginningRotationOffset, container, "Beginning");
|
||||
continue;
|
||||
}
|
||||
|
||||
if (type == MazeReworkCellType.End && endPrefab != null)
|
||||
{
|
||||
(_, float baseRot) = GetModularPrefabAndRotation(grid, x, z, width, depth);
|
||||
SpawnPrefab(endPrefab, x, yOffset, z, baseRot + endRotationOffset, container, "End");
|
||||
continue;
|
||||
}
|
||||
|
||||
// All other path cells: evaluate connectivity to select and rotate the modular hallway prefab
|
||||
(GameObject modularPrefab, float yRotation) = GetModularPrefabAndRotation(grid, x, z, width, depth);
|
||||
if (modularPrefab != null)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user