using UnityEngine;
namespace MazeGen
{
///
/// Placeholder marker for a single Exit, positioned just outside its owning room's
/// edge in the exit's direction. Colored relative to the agent's current room so the
/// doors that actually matter right now stand out among a cluster of nearby rooms:
/// green = usable from here, not yet leading anywhere explored; blue = usable from here
/// but leads to an already-visited room; transparent gray = not on the current room at
/// all (regardless of its own used/unused state). Click detection is driven externally
/// (see MazeSceneBuilder) via a raycast, not the legacy OnMouseDown message - that
/// message silently does nothing when the project's Active Input Handling is set to
/// "Input System Package (New)" only.
///
[RequireComponent(typeof(SpriteRenderer), typeof(CircleCollider2D))]
public class ExitMarker : MonoBehaviour
{
private static readonly Color UnexploredColor = Color.green;
private static readonly Color ExploredColor = new Color(0.25f, 0.55f, 1f);
private static readonly Color OtherRoomColor = new Color(0.5f, 0.5f, 0.5f, 0.6f);
public Exit ExitData { get; private set; }
public void Initialize(Room room, Exit exit)
{
ExitData = exit;
transform.position = (Vector2)room.Position + exit.Direction * (room.Radius + 0.35f);
transform.localScale = Vector3.one * 0.3f;
var sr = GetComponent();
sr.sprite = RoomView.SharedSquareSprite;
sr.sortingOrder = 1;
var col = GetComponent();
col.radius = 0.5f;
col.isTrigger = true;
UpdateVisual(null, null);
}
///
/// Recolors this marker relative to whichever room the agent is currently standing
/// in. `currentRoom`/`agent` may be null before the agent has spawned yet.
///
public void UpdateVisual(Room currentRoom, MazeAgent agent)
{
var sr = GetComponent();
bool isOnCurrentRoom = currentRoom != null && ExitData.OwnerRoomId == currentRoom.Id;
if (!isOnCurrentRoom)
{
sr.color = OtherRoomColor;
return;
}
bool leadsToExploredRoom = ExitData.ConnectedRoomId.HasValue
&& agent != null && agent.HasVisited(ExitData.ConnectedRoomId.Value);
sr.color = leadsToExploredRoom ? ExploredColor : UnexploredColor;
}
}
}