65 lines
1.4 KiB
C#
65 lines
1.4 KiB
C#
|
using System;
|
||
|
using UnityEngine;
|
||
|
|
||
|
#if UNITY_EDITOR
|
||
|
using UnityEditor;
|
||
|
#endif
|
||
|
|
||
|
[CreateAssetMenu(menuName = "KernelPanic/Dialogue/Dialogue System")]
|
||
|
public partial class DialogueSystem : ScriptableObject
|
||
|
{
|
||
|
[SerializeField] private DialogueSettings _settings;
|
||
|
|
||
|
// https://stackoverflow.com/questions/2282476/actiont-vs-delegate-event
|
||
|
public event EventHandler<DialogueLine> onDialogueLine;
|
||
|
|
||
|
public void PlayLine(string key)
|
||
|
{
|
||
|
DialogueLine dl;
|
||
|
dl.text = DialogueDatabase.ReadDialogue(key);
|
||
|
// TODO: get dialogue line duration from FMOD
|
||
|
dl.duration = _settings.HideAfter;
|
||
|
|
||
|
onDialogueLine?.Invoke(this, dl);
|
||
|
|
||
|
// TODO: tell FMOD to play the key
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public struct DialogueLine
|
||
|
{
|
||
|
public string text;
|
||
|
public float duration;
|
||
|
}
|
||
|
|
||
|
#region Editor
|
||
|
#if UNITY_EDITOR
|
||
|
|
||
|
[CustomEditor(typeof(DialogueSystem))]
|
||
|
public class DialogueSystemEditor : Editor
|
||
|
{
|
||
|
private DialogueSystem _dialogue;
|
||
|
private string _key;
|
||
|
|
||
|
private void OnEnable()
|
||
|
{
|
||
|
_dialogue = target as DialogueSystem;
|
||
|
}
|
||
|
|
||
|
public override void OnInspectorGUI()
|
||
|
{
|
||
|
base.OnInspectorGUI();
|
||
|
|
||
|
_key = EditorGUILayout.TextField("key", _key);
|
||
|
|
||
|
if (GUILayout.Button("Play Line"))
|
||
|
{
|
||
|
_dialogue.PlayLine(_key);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
#endif
|
||
|
#endregion
|
||
|
|