气泡组件和配置项
This commit is contained in:
@@ -0,0 +1,118 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace AibisDream
|
||||
{
|
||||
public class DialogCanvasManager : Singleton<DialogCanvasManager>
|
||||
{
|
||||
private const string BubbleView = "Dialog Bubble View";
|
||||
private const string OldBoxView = "Dialog Box";
|
||||
|
||||
private const string QuickTalk = "Quick Talk";
|
||||
|
||||
private IDialogView _bubbleView;
|
||||
private IDialogView _oldBoxView;
|
||||
|
||||
private IDialogView _curView;
|
||||
|
||||
private GameObject _quickTalkButton;
|
||||
|
||||
protected override void Awake()
|
||||
{
|
||||
base.Awake();
|
||||
InitDialogViews();
|
||||
InitQuickTalkButton();
|
||||
// 默认为旧Box
|
||||
_curView = _bubbleView;
|
||||
}
|
||||
|
||||
#region 对话结束后隐藏
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
DialogController.OnDialogueComplete += HideDialog;
|
||||
}
|
||||
|
||||
private void OnDisable()
|
||||
{
|
||||
DialogController.OnDialogueComplete -= HideDialog;
|
||||
}
|
||||
|
||||
private void HideDialog()
|
||||
{
|
||||
_curView.HideDialog();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (Input.GetKeyDown(KeyCode.Q) && Input.GetKey(KeyCode.P) )
|
||||
{
|
||||
_quickTalkButton.SetActive(!_quickTalkButton.activeSelf);
|
||||
}
|
||||
}
|
||||
|
||||
private void InitDialogViews()
|
||||
{
|
||||
_bubbleView = transform.Find(BubbleView).GetComponent<IDialogView>();
|
||||
_oldBoxView = transform.Find(OldBoxView).GetComponent<IDialogView>();
|
||||
|
||||
_bubbleView.HideDialog();
|
||||
_oldBoxView.HideDialog();
|
||||
}
|
||||
|
||||
private void InitQuickTalkButton()
|
||||
{
|
||||
_quickTalkButton = transform.Find(QuickTalk).gameObject;
|
||||
_quickTalkButton.GetComponent<Button>().onClick.AddListener(SwitchQuickTalkMode);
|
||||
}
|
||||
|
||||
private void SwitchQuickTalkMode()
|
||||
{
|
||||
DialogController.Instance.quickRunMode = !DialogController.Instance.quickRunMode;
|
||||
_quickTalkButton.GetComponent<Image>().color =
|
||||
DialogController.Instance.quickRunMode ? Color.gray : Color.white;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 切换对话UI
|
||||
/// </summary>
|
||||
/// <param name="viewType">UI类型</param>
|
||||
/// <returns></returns>
|
||||
public IDialogView SwitchDialogView(DialogViewType viewType)
|
||||
{
|
||||
var newDlg = viewType switch
|
||||
{
|
||||
DialogViewType.Bubble => _bubbleView,
|
||||
DialogViewType.OldBox => _oldBoxView,
|
||||
_ => _oldBoxView
|
||||
};
|
||||
|
||||
if (_curView != newDlg)
|
||||
{
|
||||
_curView.HideDialog();
|
||||
_curView = newDlg;
|
||||
}
|
||||
|
||||
return _curView;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取当前正在使用的Dialog View
|
||||
/// </summary>
|
||||
/// <returns>当前正在使用的Dialog View</returns>
|
||||
/// <exception cref="Exception">未找到Canvas</exception>
|
||||
public static IDialogView GetCurView()
|
||||
{
|
||||
return Instance._curView;
|
||||
}
|
||||
}
|
||||
|
||||
public enum DialogViewType
|
||||
{
|
||||
Bubble, OldBox
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user