Files
aibis-dream/Assets/Scripts/Dialog System/DialogController.cs
T
2024-08-14 18:13:43 +08:00

139 lines
3.9 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.AddressableAssets;
using UnityEngine.SceneManagement;
using Yarn.Unity;
namespace AibisDream
{
public class DialogController : Singleton<DialogController>
{
private DialogueRunner dialogueRunner;
private Dictionary<string, Action<YarnOption[]>> commandMap = new Dictionary<string, Action<YarnOption[]>>();
private void Start()
{
dialogueRunner = GetComponentInChildren<DialogueRunner>();
}
/// <summary>
/// Ի
/// </summary>
/// <param name="yarnProject"></param>
public void StartDialog(YarnProject yarnProject)
{
dialogueRunner.SetProject(yarnProject);
dialogueRunner.StartDialogue("Start");
}
/// <summary>
/// ִָ
/// </summary>
/// <param name="commandName">ָ</param>
public void InvokeOptionCommand(string commandName, YarnOption[] options)
{
if (commandName == null) { }
if (commandMap.TryGetValue(commandName, out var action))
{
action(options);
}
else
{
Debug.LogWarning($"ûҵ {commandName} ");
}
}
/// <summary>
/// עѡָ
/// </summary>
/// <param name="commandName">ָ</param>
/// <param name="commandAction">ָ</param>
public void RegisterOptionCommand(string commandName, Action<YarnOption[]> commandAction)
{
if (commandMap.ContainsKey(commandName))
{
Debug.Log($" {commandName} δעעָ");
}
commandMap[commandName] = commandAction;
}
/// <summary>
/// жָ
/// </summary>
/// <param name="commandName">ָ</param>
public void RemoveOptionCommand(string commandName)
{
if (commandMap.ContainsKey(commandName))
{
commandMap.Remove(commandName);
}
else
{
Debug.Log($" {commandName} δעעָ");
}
}
#region
[YarnCommand("switch_tv")]
public static void SwitchTV(string picName)
{
Debug.Log($"switch_tv {picName}");
}
[YarnCommand("indoor")]
public static void Indoor()
{
MainUIController.Instance.HideMainUI();
}
[YarnCommand("character_into")]
public static void CharacterInto(string picName)
{
Debug.Log($"character_into {picName}");
}
[YarnCommand("character_moveto_fix")]
public static void CharacterMoveToFix()
{
Debug.Log("character_moveto_fix");
}
[YarnCommand("cover")]
public static void Cover()
{
Debug.Log("Cover");
}
[YarnCommand("load_scene")]
public static IEnumerator LoadScene(string sceneName)
{
yield return SceneLoader.Instance.LoadSceneAsync(sceneName);
}
[YarnCommand("unload_scene")]
public static IEnumerator UnloadScene(string sceneName)
{
yield return SceneLoader.Instance.UnloadSceneAsync(sceneName);
}
[YarnCommand("init_fix")]
public static void InitFix()
{
}
[YarnCommand("hide_dialog")]
public static void HideDialog()
{
DialogUiViewer.Instance.HideDialog();
}
#endregion
}
}