110 lines
2.7 KiB
C#
110 lines
2.7 KiB
C#
using Michsky.UI.Reach;
|
|
using TMPro;
|
|
using UnityEngine;
|
|
using UnityEngine.Events;
|
|
using UnityEngine.UI;
|
|
|
|
namespace UI.Narration
|
|
{
|
|
public class NarrationPanelView : MonoBehaviour
|
|
{
|
|
[Header("Root")]
|
|
[SerializeField] private GameObject root;
|
|
|
|
[Header("Text")]
|
|
[SerializeField] private TMP_Text narrationText;
|
|
|
|
[Header("Continue Button")]
|
|
[SerializeField] private ButtonManager continueButton;
|
|
[SerializeField] private Button fallbackContinueButton;
|
|
[SerializeField] private string continueLabel = "继续";
|
|
[SerializeField] private string finishLabel = "确认";
|
|
|
|
public UnityEvent onContinue = new UnityEvent();
|
|
|
|
UnityAction onContinueAction;
|
|
|
|
void Awake()
|
|
{
|
|
if (root == null) { root = gameObject; }
|
|
}
|
|
|
|
void OnEnable()
|
|
{
|
|
BindButton();
|
|
}
|
|
|
|
void OnDisable()
|
|
{
|
|
UnbindButton();
|
|
}
|
|
|
|
void BindButton()
|
|
{
|
|
UnbindButton();
|
|
onContinueAction = RaiseContinue;
|
|
|
|
if (continueButton != null)
|
|
{
|
|
continueButton.onClick.AddListener(onContinueAction);
|
|
}
|
|
else if (fallbackContinueButton != null)
|
|
{
|
|
fallbackContinueButton.onClick.AddListener(onContinueAction);
|
|
}
|
|
}
|
|
|
|
void UnbindButton()
|
|
{
|
|
if (onContinueAction == null) { return; }
|
|
|
|
if (continueButton != null)
|
|
{
|
|
continueButton.onClick.RemoveListener(onContinueAction);
|
|
}
|
|
|
|
if (fallbackContinueButton != null)
|
|
{
|
|
fallbackContinueButton.onClick.RemoveListener(onContinueAction);
|
|
}
|
|
|
|
onContinueAction = null;
|
|
}
|
|
|
|
void RaiseContinue()
|
|
{
|
|
onContinue.Invoke();
|
|
}
|
|
|
|
public void Show()
|
|
{
|
|
if (root != null) { root.SetActive(true); }
|
|
}
|
|
|
|
public void Hide()
|
|
{
|
|
if (root != null) { root.SetActive(false); }
|
|
}
|
|
|
|
public void SetText(string text)
|
|
{
|
|
if (narrationText != null) { narrationText.text = text; }
|
|
}
|
|
|
|
public void SetIsLastPage(bool isLastPage)
|
|
{
|
|
string label = isLastPage ? finishLabel : continueLabel;
|
|
|
|
if (continueButton != null)
|
|
{
|
|
continueButton.SetText(label);
|
|
}
|
|
else if (fallbackContinueButton != null)
|
|
{
|
|
var tmp = fallbackContinueButton.GetComponentInChildren<TMP_Text>(true);
|
|
if (tmp != null) { tmp.text = label; }
|
|
}
|
|
}
|
|
}
|
|
}
|