98 lines
2.2 KiB
C#
98 lines
2.2 KiB
C#
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using PixelCrushers;
|
|
using PixelCrushers.DialogueSystem;
|
|
using Sirenix.OdinInspector;
|
|
using UnityEngine;
|
|
using UnityEngine.Events;
|
|
|
|
namespace Beyond
|
|
{
|
|
public class EventSequencer : Saver
|
|
{
|
|
public bool m_useOnce = true;
|
|
public bool m_startOnEnable = false;
|
|
|
|
[Serializable]
|
|
public class EventData
|
|
{
|
|
public UnityEvent m_event;
|
|
public string barkString;
|
|
public float delay;
|
|
}
|
|
|
|
public EventData[] m_sequence;
|
|
|
|
public bool WasUsed
|
|
{
|
|
get => m_saveData.used;
|
|
}
|
|
|
|
private class SaveData
|
|
{
|
|
public bool used = false;
|
|
}
|
|
|
|
private SaveData m_saveData = new SaveData();
|
|
|
|
[Button("Test")]
|
|
private void Test()
|
|
{
|
|
}
|
|
|
|
[Button]
|
|
public void StartSequence()
|
|
{
|
|
if (m_useOnce && WasUsed)
|
|
return;
|
|
if (m_sequence == null || m_sequence.Length == 0)
|
|
return;
|
|
StopAllCoroutines();
|
|
StartCoroutine(SequenceCoroutine());
|
|
}
|
|
|
|
private IEnumerator SequenceCoroutine()
|
|
{
|
|
for (int i = 0; i < m_sequence.Length; i++)
|
|
{
|
|
var ev = m_sequence[i];
|
|
yield return new WaitForSecondsRealtime(ev.delay);
|
|
ev.m_event?.Invoke();
|
|
if (!string.IsNullOrEmpty(ev.barkString))
|
|
{
|
|
DialogueManager.BarkString(ev.barkString, Player.Instance.transform);
|
|
}
|
|
}
|
|
|
|
yield return null;
|
|
}
|
|
|
|
// Start is called before the first frame update
|
|
private void Start()
|
|
{
|
|
}
|
|
|
|
private void OnEnable()
|
|
{
|
|
if (m_startOnEnable)
|
|
{
|
|
StartSequence();
|
|
}
|
|
}
|
|
|
|
public override string RecordData()
|
|
{
|
|
return SaveSystem.Serialize(m_saveData);
|
|
}
|
|
|
|
public override void ApplyData(string s)
|
|
{
|
|
var data = SaveSystem.Deserialize<SaveData>(s);
|
|
if (data != null)
|
|
{
|
|
m_saveData = data;
|
|
}
|
|
}
|
|
}
|
|
} |