This commit is contained in:
2026-07-04 02:52:36 +07:00
parent 4e4b990f8c
commit ddaf07ef2f
359 changed files with 1402384 additions and 1670 deletions

View File

@@ -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;
}
}
}

View File

@@ -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)
{

View File

@@ -472,7 +472,11 @@ namespace Baba_yaga.UI
private void SpawnPlayer(NetworkRunner runner, PlayerRef player)
{
Debug.Log($"[BasicSpawner] Spawning Player {player.PlayerId} at {Time.time}");
Vector3 spawnPosition = (player == runner.LocalPlayer) ? new Vector3(-8, 2, 0) : new Vector3(8, 2, 0);
// Use the maze Beginning (Start) cell world position. Falls back to Vector3.zero if maze not ready.
Vector3 spawnPosition = Baba_yaga.GameSetup.MazeRework.MazeReworkManager.BeginningWorldPosition;
spawnPosition.y += 1f; // Offset slightly above the floor surface
var networkPlayerObject = runner.Spawn(_playerPrefab, spawnPosition, Quaternion.identity, player);
// In Shared Mode, runner.Spawn automatically grants State Authority to the caller.