This commit is contained in:
2025-02-12 15:12:00 +08:00
parent 51460d405a
commit 94e01a9baa
33 changed files with 3426 additions and 618 deletions
+41 -43
View File
@@ -22,13 +22,13 @@ namespace AibisDream
#region box组件
protected TypewriterByCharacter dialogText;
protected TextMeshProUGUI actorName;
protected GameObject nextArray;
protected GameObject choiceBox;
private TypewriterByCharacter _dialogText;
private TextMeshProUGUI _actorName;
private GameObject _nextArray;
private GameObject _choiceBox;
#endregion
private bool _skipLineDelay;
private Action _nextStep;
@@ -37,17 +37,21 @@ namespace AibisDream
protected GameObject choiceButtonPrefab;
protected virtual void Awake()
private void Awake()
{
LoadChoiceButton();
InitComponents();
AddSomeListener();
}
private void OnDestroy()
{
OnDialogViewerDestroy();
}
private void AddSomeListener()
{
// 对话显示后有一段延时不可跳过
dialogText.onTypewriterStart.AddListener(() =>
_dialogText.onTypewriterStart.AddListener(() =>
{
_skipLineDelay = true;
_ = CommonUtil.Delay(delayTime, () => { _skipLineDelay = false; });
@@ -56,17 +60,16 @@ namespace AibisDream
#region
protected virtual void LoadChoiceButton()
{
Debug.Log("无选项对话框");
}
private void InitComponents()
{
actorName = transform.Find(ActorName)?.gameObject.GetComponent<TextMeshProUGUI>();
dialogText = transform.Find(DialogText)?.gameObject.GetComponent<TypewriterByCharacter>();
nextArray = transform.Find(NextArray)?.gameObject;
choiceBox = transform.Find(ChoiceBox)?.gameObject;
_actorName = transform.Find(ActorName)?.gameObject.GetComponent<TextMeshProUGUI>();
_dialogText = transform.Find(DialogText)?.gameObject.GetComponent<TypewriterByCharacter>();
_nextArray = transform.Find(NextArray)?.gameObject;
_choiceBox = transform.Find(ChoiceBox)?.gameObject;
}
protected virtual void OnDialogViewerDestroy()
{
}
#endregion
@@ -91,33 +94,28 @@ namespace AibisDream
bool isAutoSkip = false)
{
gameObject.SetActive(true);
// // 没有dialogText说明不能显示对话,直接跳过
// if (!dialogText)
// {
// return;
// }
// 把原有对话清掉
ClearBox();
dialogText.gameObject.SetActive(true);
choiceBox?.SetActive(false);
_dialogText.gameObject.SetActive(true);
_choiceBox?.SetActive(false);
// 显示内容
ShowActorName(character);
dialogText.ShowText(dialogLine);
_dialogText.ShowText(dialogLine);
// 自动跳过的回调很难独立Remove,只能全部清空再注册,下策
dialogText.onTextShowed.RemoveAllListeners();
dialogText.onTextShowed.AddListener(() => nextArray.gameObject.SetActive(true));
dialogText.onTextShowed.AddListener(() => onTextShowed?.Invoke());
dialogText.onTextShowed.AddListener(() => EnumEventSystem.Global.Send(DialogEventEnum.LineShowed));
_dialogText.onTextShowed.RemoveAllListeners();
_dialogText.onTextShowed.AddListener(() => _nextArray.gameObject.SetActive(true));
_dialogText.onTextShowed.AddListener(() => onTextShowed?.Invoke());
_dialogText.onTextShowed.AddListener(() => EnumEventSystem.Global.Send(DialogEventEnum.LineShowed));
_nextStep = nextStep;
// 执行自动跳过结局
if (isAutoSkip)
{
dialogText.onTextShowed.AddListener(() => _ = CommonUtil.Delay(200, NextStep));
_dialogText.onTextShowed.AddListener(() => _ = CommonUtil.Delay(200, NextStep));
}
}
@@ -139,18 +137,18 @@ namespace AibisDream
{
gameObject.SetActive(true);
// 没有选择框直接不显示选项
if (!choiceBox)
if (!_choiceBox)
{
return;
}
// 把原有对话清掉
ClearBox();
choiceBox.SetActive(true);
dialogText.gameObject.SetActive(false);
_choiceBox.SetActive(true);
_dialogText.gameObject.SetActive(false);
// 销毁原来的按钮
foreach (Transform child in choiceBox.transform)
foreach (Transform child in _choiceBox.transform)
{
Destroy(child.gameObject);
}
@@ -160,7 +158,7 @@ namespace AibisDream
{
if (!option.IsAvailable) continue;
var choiceInstance = Instantiate(choiceButtonPrefab, choiceBox.transform);
var choiceInstance = Instantiate(choiceButtonPrefab, _choiceBox.transform);
choiceInstance.GetComponentInChildren<TextMeshProUGUI>().text = option.Line;
choiceInstance.GetComponent<Button>().onClick.AddListener(option.Select);
}
@@ -179,14 +177,14 @@ namespace AibisDream
return true;
}
if (dialogText.isShowingText)
if (_dialogText.isShowingText)
{
dialogText.SkipTypewriter();
_dialogText.SkipTypewriter();
return true;
}
else
{
nextArray.gameObject.SetActive(false);
_nextArray.gameObject.SetActive(false);
return false;
}
}
@@ -194,15 +192,15 @@ namespace AibisDream
private void ClearBox()
{
gameObject.SetActive(true);
dialogText?.ShowText("");
nextArray?.SetActive(false);
if (!actorName) actorName.text = "";
_dialogText?.ShowText("");
_nextArray?.SetActive(false);
if (!_actorName) _actorName.text = "";
}
private void ShowActorName(CharacterVo character)
{
if (!actorName) return;
actorName.text = character.GetActorName();
if (!_actorName) return;
_actorName.text = character.GetActorName();
}
}
}