86 lines
2.1 KiB
C#
86 lines
2.1 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using TMPro;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
/// <summary>
|
|
/// 提示ui
|
|
/// </summary>
|
|
public class UI_TipPanel : BasePanel
|
|
{
|
|
/// <summary>
|
|
/// 提示文本
|
|
/// </summary>
|
|
public TextMeshProUGUI TipText;
|
|
|
|
/// <summary>
|
|
/// 上一步
|
|
/// </summary>
|
|
public Button Up;
|
|
/// <summary>
|
|
/// 下一步
|
|
/// </summary>
|
|
public Button Down;
|
|
|
|
|
|
public static List<string> Tips = new List<string>();
|
|
|
|
private int index = 0;
|
|
// Start is called before the first frame update
|
|
protected override void Awake()
|
|
{
|
|
base.Awake();
|
|
Up= GetControl<Button>("Up_Btn");
|
|
Down = GetControl<Button>("Down_Btn");
|
|
TipText = GetControl<TextMeshProUGUI>("TipText");
|
|
|
|
}
|
|
public override void ShowMe(int time = 0)
|
|
{
|
|
if (Tips.Count > 0)
|
|
{
|
|
index = 0; // 重置为第一个提示
|
|
TipText.text = Tips[0];
|
|
Debug.Log($"当前索引: {index}, 列表长度: {Tips.Count}");
|
|
//Debug.Log(Tips.Count);
|
|
}
|
|
else
|
|
{
|
|
TipText.text = "操作流程:";
|
|
}
|
|
base.ShowMe();
|
|
}
|
|
|
|
public override void HideMe(int time = 0)
|
|
{
|
|
base.HideMe();
|
|
Tips.Clear();
|
|
Debug.Log(Tips.Count);
|
|
}
|
|
|
|
protected override void OnClick(string btnName)
|
|
{
|
|
switch (btnName)
|
|
{
|
|
case"Up_Btn":
|
|
if (Tips.Count == 0) return; // 列表为空时直接返回
|
|
|
|
index = Mathf.Max(0, index - 1); // 确保index不小于0
|
|
TipText.text = Tips[index];
|
|
Up.gameObject.SetActive(index > 0);
|
|
Down.gameObject.SetActive(true);
|
|
break;
|
|
case "Down_Btn":
|
|
if (Tips.Count == 0)
|
|
return;
|
|
|
|
index = Mathf.Min(Tips.Count - 1, index + 1); // 确保index不超过最大值
|
|
TipText.text = Tips[index];
|
|
Down.gameObject.SetActive(index < Tips.Count - 1);
|
|
Up.gameObject.SetActive(true);
|
|
break;
|
|
}
|
|
}
|
|
}
|