Files
Ipseity-Demo/Assets/_Content/Scripts/Features/Hallucination/Runtime/HallucinationTriggerZone.cs
T

66 lines
2.6 KiB
C#

using UnityEngine;
using Unheimlich.Core.Events;
namespace Unheimlich.Features.Hallucination
{
/// <summary>
/// Self-contained zone that triggers a hallucination effect when the player enters.
/// Ghost-word spawn removed — words live on FloatingLabel components in the scene.
/// SetEvent() lets InfiniteStaircaseController inject the right event per slot at runtime.
/// </summary>
public class HallucinationTriggerZone : TriggerZoneBase
{
[Header("Zone Behaviour")]
[SerializeField] private bool _retriggerable = false;
[SerializeField] private float _delay = 0f;
[Header("Sanity")]
[Tooltip("Insanity added when the zone fires, on top of any SanityCost on the event.")]
[SerializeField, Range(0f, 1f)] private float _insanityAmount = 0f;
[Header("Hallucination Event")]
[Tooltip("Overridable at runtime via SetEvent().")]
[SerializeField] private HallucinationEvent _hallucinationEvent;
[Header("Debug")]
[SerializeField] private bool _debugMode;
protected override bool IsRetriggerable => _retriggerable;
protected override void OnPlayerEntered(Collider playerCollider)
{
if (_delay > 0f) Invoke(nameof(Fire), _delay);
else Fire();
}
/// <summary>Overrides the event at runtime. Pass null to disable.</summary>
public void SetEvent(HallucinationEvent hallucinationEvent) =>
_hallucinationEvent = hallucinationEvent;
/// <summary>Fires the hallucination. Can be called from external scripts or UnityEvents.</summary>
public void Fire()
{
if (HallucinationManager.Instance == null)
{
Debug.LogError("[HallucinationTriggerZone] HallucinationManager not found!", this);
return;
}
if (_insanityAmount > 0f)
{
HallucinationManager.Instance.AddInsanity(_insanityAmount);
if (_debugMode) Debug.Log($"[HallucinationTriggerZone] +{_insanityAmount:F2} insanity.", this);
}
if (_hallucinationEvent != null)
{
HallucinationManager.Instance.TriggerHallucinationEvent(_hallucinationEvent);
if (_debugMode) Debug.Log($"[HallucinationTriggerZone] Event: {_hallucinationEvent.Label}", this);
}
else if (_debugMode)
{
Debug.Log($"[HallucinationTriggerZone] No event on '{gameObject.name}'.", this);
}
}
}
}