159 lines
4.4 KiB
C#
159 lines
4.4 KiB
C#
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using Yarn.Unity;
|
|
|
|
namespace AibisDream
|
|
{
|
|
public class DialogController : Singleton<DialogController>
|
|
{
|
|
private DialogueRunner dialogueRunner;
|
|
|
|
private Dictionary<string, Action<YarnOption[]>> commandMap;
|
|
|
|
public bool quickRunMode;
|
|
|
|
private void Start()
|
|
{
|
|
dialogueRunner = GetComponentInChildren<DialogueRunner>();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 开启对话
|
|
/// </summary>
|
|
/// <param name="yarnProject">Yarn组</param>
|
|
public void StartDialog(YarnProject yarnProject)
|
|
{
|
|
dialogueRunner.SetProject(yarnProject);
|
|
dialogueRunner.StartDialogue("Start");
|
|
}
|
|
|
|
/// <summary>
|
|
/// 调用命令
|
|
/// </summary>
|
|
/// <param name="commandName">命令名</param>
|
|
/// <param name="options">选项</param>
|
|
public void InvokeOptionCommand(string commandName, YarnOption[] options)
|
|
{
|
|
if (commandName == null)
|
|
{
|
|
Debug.Log("命令名为空");
|
|
return;
|
|
}
|
|
|
|
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)
|
|
{
|
|
MainUIController.Instance.SwitchTV(picName);
|
|
}
|
|
|
|
[YarnCommand("indoor")]
|
|
public static void Indoor(float duration = 1)
|
|
{
|
|
MainUIController.Instance.TVFadeOut(duration);
|
|
}
|
|
|
|
[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, float duration = 1)
|
|
{
|
|
HideDialog();
|
|
yield return MainUIController.Instance.FadeInSync(duration);
|
|
yield return SceneLoader.Instance.LoadSceneAsync(sceneName);
|
|
yield return MainUIController.Instance.FadeOutSync(duration);
|
|
}
|
|
|
|
[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();
|
|
}
|
|
|
|
[YarnCommand("fade_in")]
|
|
public static IEnumerator FadeIn(float duration = 1)
|
|
{
|
|
return MainUIController.Instance.FadeInSync(duration);
|
|
}
|
|
|
|
[YarnCommand("fade_out")]
|
|
public static IEnumerator FadeOut(float duration = 1)
|
|
{
|
|
return MainUIController.Instance.FadeOutSync(duration);
|
|
}
|
|
|
|
#endregion
|
|
}
|
|
} |