| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960 |
- using UnityEngine;
- namespace MazeGen
- {
- /// <summary>
- /// Placeholder marker for a single Exit, positioned just outside its owning room's
- /// edge in the exit's direction. Purely informational now that agents move
- /// autonomously - colored relative to whichever agent the camera is currently
- /// following, so the doors that actually matter stand out among a cluster of nearby
- /// rooms: green = usable from the followed agent's room, not yet leading anywhere
- /// explored; blue = usable from there but leads to an already-visited room; transparent
- /// gray = not on the followed room at all (or no agent is being followed).
- /// </summary>
- [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<SpriteRenderer>();
- sr.sprite = RoomView.SharedSquareSprite;
- sr.sortingOrder = 1;
- var col = GetComponent<CircleCollider2D>();
- col.radius = 0.5f;
- col.isTrigger = true;
- UpdateVisual(null, null);
- }
- /// <summary>
- /// Recolors this marker relative to whichever room the agent is currently standing
- /// in. `currentRoom`/`agent` may be null before the agent has spawned yet.
- /// </summary>
- public void UpdateVisual(Room currentRoom, MazeAgent agent)
- {
- var sr = GetComponent<SpriteRenderer>();
- 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;
- }
- }
- }
|