139 lines
3.9 KiB
C#
139 lines
3.9 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("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
|
||
}
|
||
}
|
||
|