| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162 |
- using UnityEngine;
- namespace MazeGen
- {
- /// <summary>
- /// 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.
- /// </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;
- }
- }
- }
|