Updated comments
This commit is contained in:
@@ -87,9 +87,9 @@ public class MapGenManager : MonoBehaviour
|
||||
}
|
||||
}
|
||||
|
||||
/* ============================================================ */
|
||||
/* CORRIDORS */
|
||||
/* ============================================================ */
|
||||
/// <summary>
|
||||
/// Builds corridors and doors between rooms.
|
||||
/// </summary>
|
||||
private void BuildCorridors()
|
||||
{
|
||||
// Jediné dva směry, které musíme zkontrolovat z každé místnosti (right/up)
|
||||
@@ -109,9 +109,9 @@ public class MapGenManager : MonoBehaviour
|
||||
foreach (Vector2Int dir in directions)
|
||||
{
|
||||
Vector2Int nKey = cell + dir;
|
||||
if (!gridToRoom.TryGetValue(nKey, out GameObject roomB)) continue; // žádná sousední místnost
|
||||
if (!gridToRoom.TryGetValue(nKey, out GameObject roomB)) continue;
|
||||
|
||||
// Geometrie pro daný směr
|
||||
// Handle geometry
|
||||
Vector3 axis; float lenStraight, lenDoor; Quaternion rot;
|
||||
if (dir == Vector2Int.right)
|
||||
{
|
||||
@@ -128,18 +128,18 @@ public class MapGenManager : MonoBehaviour
|
||||
rot = Quaternion.identity;
|
||||
}
|
||||
|
||||
// Pozice stěn (počítáme od středu místnosti k jejímu okraji)
|
||||
// Wall calculation
|
||||
float halfA = Vector3.Scale(GetPrefabXZ(roomA), axis).magnitude * 0.5f;
|
||||
float halfB = Vector3.Scale(GetPrefabXZ(roomB), axis).magnitude * 0.5f;
|
||||
Vector3 wallA = roomA.transform.position + axis * halfA;
|
||||
Vector3 wallB = roomB.transform.position - axis * halfB;
|
||||
|
||||
// DVEŘE – pivot dveří do středu úsečky mezi okraji stěn
|
||||
// Doors
|
||||
Vector3 doorPos = (wallA + wallB) * 0.5f;
|
||||
GameObject doorGO = Instantiate(DoorCorridor, doorPos, rot, transform);
|
||||
DoorAnimation anim = doorGO.GetComponent<DoorAnimation>();
|
||||
|
||||
// REGISTRACE do obou místností
|
||||
// Register the corridor to both rooms
|
||||
RoomHandler rhA = roomA.GetComponent<RoomHandler>();
|
||||
RoomHandler rhB = roomB.GetComponent<RoomHandler>();
|
||||
if (dir == Vector2Int.right)
|
||||
@@ -171,19 +171,19 @@ public class MapGenManager : MonoBehaviour
|
||||
private void PlaceStraightSegments(
|
||||
Vector3 startEdge,
|
||||
Vector3 wallEdge,
|
||||
Vector3 direction, // normalizovaný (+/- axis)
|
||||
Vector3 direction,
|
||||
Quaternion rot,
|
||||
float len) // délka STANDARDNÍHO rovného segmentu
|
||||
float len)
|
||||
{
|
||||
const float EPS = 0.01f; // ≈1 cm tolerance
|
||||
const float EPS = 0.01f;
|
||||
float dist = Vector3.Distance(startEdge, wallEdge);
|
||||
if (dist < EPS) return; // nic netřeba
|
||||
if (dist < EPS) return;
|
||||
|
||||
int fullCount = Mathf.FloorToInt(dist / len);
|
||||
float remainder = dist - fullCount * len; // 0 .. len
|
||||
float remainder = dist - fullCount * len;
|
||||
|
||||
// -------- 1) CELÉ segmenty --------
|
||||
Vector3 firstPivot = startEdge + direction * (len * 0.5f); // hrana sedí na startEdge
|
||||
// Full segments
|
||||
Vector3 firstPivot = startEdge + direction * (len * 0.5f);
|
||||
for (int i = 0; i < fullCount; i++)
|
||||
{
|
||||
Vector3 pos = firstPivot + direction * (i * len);
|
||||
@@ -191,16 +191,14 @@ public class MapGenManager : MonoBehaviour
|
||||
Instantiate(prefab, pos, rot, transform);
|
||||
}
|
||||
|
||||
// -------- 2) POSLEDNÍ ZKRÁCENÝ segment (pokud je třeba) --------
|
||||
if (remainder > EPS) // zbylo něco > 1 cm
|
||||
// Short segment to fill the gap
|
||||
if (remainder > EPS)
|
||||
{
|
||||
// pivot tak, aby přední hrana nepřesáhla wallEdge
|
||||
Vector3 remPivot = wallEdge - direction * (remainder * 0.5f);
|
||||
GameObject last = Instantiate(CorridorStraightUnlit, remPivot, rot, transform);
|
||||
|
||||
// zmenšíme délku po místní ose Z (prefab je "dlouhý" po Z)
|
||||
Vector3 sc = last.transform.localScale;
|
||||
sc.z *= remainder / len; // poměr 0 .. 1
|
||||
sc.z *= remainder / len;
|
||||
last.transform.localScale = sc;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user