49 lines
1.9 KiB
C#
49 lines
1.9 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
// 씬에 배치하는 수동 트리거. Activate()가 호출되면 켜지고,
|
|
// DialogCondition의 RequiredTriggerIds에서 Id로 조회해 대화 활성화 조건으로 쓴다.
|
|
// 예: 계약서 서명(DrawablePaper.OnSigned) → 이 트리거 Activate → 서명 후 대화 활성화.
|
|
//
|
|
// 주의: 세이브에 기록되지 않는 런타임 상태다 (오브젝트가 비활성/파괴되면 꺼짐).
|
|
// 영구히 남아야 하는 진행은 기존처럼 대화 완료 기록/선택지 Code를 쓸 것.
|
|
public class StoryTrigger : MonoBehaviour
|
|
{
|
|
[Tooltip("조건에서 참조할 Id. 비워두면 오브젝트 이름 사용")]
|
|
[SerializeField] private string _triggerId;
|
|
|
|
[Tooltip("시작부터 켜진 상태로 둘지")]
|
|
[SerializeField] private bool _startActivated;
|
|
|
|
public string TriggerId => string.IsNullOrEmpty(_triggerId) ? name : _triggerId;
|
|
public bool IsActivated { get; private set; }
|
|
|
|
private static readonly Dictionary<string, StoryTrigger> _registry = new();
|
|
|
|
// 트리거가 꺼짐→켜짐으로 바뀌는 순간 TriggerId와 함께 호출 (SceneBgm 등에서 구독)
|
|
public static event Action<string> OnActivated;
|
|
|
|
private void Awake()
|
|
{
|
|
IsActivated = _startActivated;
|
|
}
|
|
|
|
private void OnEnable() => _registry[TriggerId] = this;
|
|
private void OnDisable() => _registry.Remove(TriggerId);
|
|
|
|
// UnityEvent에서 호출 (예: DrawablePaper.OnSigned)
|
|
public void Activate()
|
|
{
|
|
if (IsActivated) return;
|
|
IsActivated = true;
|
|
OnActivated?.Invoke(TriggerId);
|
|
}
|
|
|
|
public void Deactivate() => IsActivated = false;
|
|
|
|
// 해당 Id의 트리거가 씬에 있고 켜져 있는가 (DialogCondition에서 사용)
|
|
public static bool IsActive(string id)
|
|
=> _registry.TryGetValue(id, out var trigger) && trigger.IsActivated;
|
|
}
|