Files
Ipseity-Demo/Assets/Unheimlich_POC/Scripts/World/Environment/StaircaseSegment.cs
T

54 lines
2.4 KiB
C#

using UnityEngine;
using Unheimlich.Features.Hallucination;
using Unheimlich.Features.Dialogue.UI;
namespace Unheimlich.World.Environment
{
/// <summary>
/// Sits on each stair-segment prefab and acts as the single configuration point
/// for the InfiniteStaircaseController.
///
/// Responsibilities:
/// - Holds a reference to the segment's FloatingLabel (set in prefab).
/// - Holds a reference to the segment's HallucinationTriggerZone (set in prefab).
/// - Exposes Configure() so the controller can push the right word and event
/// at spawn time without any GetComponent chains on the controller side.
/// </summary>
public class StaircaseSegment : MonoBehaviour
{
[Header("References")]
[Tooltip("FloatingLabel present on this prefab. Assign in the prefab inspector.")]
[SerializeField] private FloatingLabel _floatingLabel;
[Tooltip("HallucinationTriggerZone present on this prefab. Assign in the prefab inspector.")]
[SerializeField] private HallucinationTriggerZone _triggerZone;
// ─── Public API ────────────────────────────────────────────────────────
/// <summary>
/// Called by InfiniteStaircaseController right after this segment is spawned.
/// Sets the word on the FloatingLabel and overrides the HallucinationEvent on the zone.
/// </summary>
/// <param name="word">Text to display. Null or empty = label keeps its prefab default.</param>
/// <param name="hallucinationEvent">Event to fire when the player enters the zone. Null = no event.</param>
public void Configure(string word, HallucinationEvent hallucinationEvent)
{
if (_floatingLabel != null && !string.IsNullOrEmpty(word))
_floatingLabel.SetText(word);
if (_triggerZone != null)
_triggerZone.SetEvent(hallucinationEvent);
}
// ─── Editor helpers ────────────────────────────────────────────────────
#if UNITY_EDITOR
private void Reset()
{
_floatingLabel = GetComponentInChildren<FloatingLabel>();
_triggerZone = GetComponentInChildren<HallucinationTriggerZone>();
}
#endif
}
}