Files
2024-11-20 15:21:28 +01:00

74 lines
2.1 KiB
C#

using System;
using System.Collections;
using System.Collections.Generic;
using PixelCrushers;
using PixelCrushers.QuestMachine;
using UnityEngine;
namespace Beyond
{
[RequireComponent(typeof(BoxCollider))]
public class bAlertTrigger : MonoBehaviour
{
[SerializeField] private string m_alertHeaderText;
[SerializeField] private string m_alertBodyText;
[SerializeField] private bool m_showOnce = true;
private Collider m_collider;
private void OnEnable()
{
m_collider = GetComponent<BoxCollider>();
}
private void OnTriggerExit(Collider other)
{
ManageAlert();
if (m_showOnce)
{
m_collider.enabled = false;
}
}
private void ManageAlert()
{
List<QuestContent> content = new List<QuestContent>();
HeadingTextQuestContent headerContent =
ScriptableObject.CreateInstance<PixelCrushers.QuestMachine.Wrappers.HeadingTextQuestContent>() as
HeadingTextQuestContent;
StringField header = new StringField(m_alertHeaderText);
BodyTextQuestContent bodyContent =
ScriptableObject.CreateInstance<PixelCrushers.QuestMachine.Wrappers.BodyTextQuestContent>() as
BodyTextQuestContent;
StringField body = new StringField(m_alertBodyText);
headerContent.headingText = header;
bodyContent.bodyText = body;
content.Add(headerContent);
content.Add(bodyContent);
QuestMachine.defaultQuestAlertUI.ShowAlert("", content);
StartCoroutine(DelayedDestroyingSO(content));
}
private IEnumerator DelayedDestroyingSO(List<QuestContent> content)
{
UnityUIQuestAlertUI ui = QuestMachine.defaultQuestAlertUI as UnityUIQuestAlertUI;
if (ui == null)
{
yield break;
}
yield return new WaitForSeconds(ui.minDisplayDuration);
content.ForEach(Destroy);
}
}
}