80 lines
2.1 KiB
C#
80 lines
2.1 KiB
C#
using System;
|
|
using AibisDream.Framework;
|
|
using AibisDream.Kit;
|
|
using AibisDream.Utility;
|
|
using TMPro;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
namespace AibisDream
|
|
{
|
|
public class CenterOption : MonoBehaviour, IDialogView
|
|
{
|
|
#region 索引
|
|
|
|
public GameObject choiceButtonPrefab;
|
|
|
|
#endregion
|
|
|
|
private TextParam _textParam;
|
|
|
|
private void Awake()
|
|
{
|
|
EnumEventSystem.Global.Register<DialogEventEnum, DialogText>(DialogEventEnum.OptionSelected,
|
|
_ => HideDialog());
|
|
}
|
|
|
|
public void ShowLine(string dialogLine, CharacterVo character, Action nextStep, string lineId, bool isAutoSkip = false)
|
|
{
|
|
Debug.Log("CenterOption只显示选项");
|
|
}
|
|
|
|
public void ShowOptions(DialogOption[] dialogueOptions)
|
|
{
|
|
gameObject.SetActive(true);
|
|
|
|
// 销毁原来的按钮
|
|
foreach (Transform child in transform)
|
|
{
|
|
Destroy(child.gameObject);
|
|
}
|
|
|
|
// 生成新按钮
|
|
foreach (var option in dialogueOptions)
|
|
{
|
|
if (!option.IsAvailable) continue;
|
|
|
|
var choiceInstance = Instantiate(choiceButtonPrefab, transform);
|
|
var optionText = choiceInstance.GetComponentInChildren<TextMeshProUGUI>();
|
|
optionText.text = option.Line;
|
|
optionText.characterSpacing = _textParam.charSpace;
|
|
choiceInstance.GetComponent<Button>().onClick.AddListener(() =>
|
|
{
|
|
HideDialog();
|
|
option.Select();
|
|
});
|
|
}
|
|
}
|
|
|
|
public void HideDialog()
|
|
{
|
|
gameObject.SetActive(false);
|
|
}
|
|
|
|
public bool TrySkipLine(bool isForceSkip)
|
|
{
|
|
// 无法跳过
|
|
return true;
|
|
}
|
|
|
|
public void NextStep()
|
|
{
|
|
// 无法继续
|
|
}
|
|
|
|
public void OnLocalizationChanged(string value)
|
|
{
|
|
_textParam = JsonUtil.ReadBeanByText<TextParam>(value);
|
|
}
|
|
}
|
|
} |