133 lines
3.5 KiB
C#
133 lines
3.5 KiB
C#
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("init_fix")]
|
|
public static void InitFix()
|
|
{
|
|
|
|
}
|
|
|
|
[YarnCommand("hide_dialog")]
|
|
public static void HideDialog()
|
|
{
|
|
DialogUiViewer.Instance.HideDialog();
|
|
}
|
|
#endregion
|
|
}
|
|
}
|
|
|