173 lines
4.2 KiB
C#
173 lines
4.2 KiB
C#
using System.Collections;
|
||
using System.Collections.Generic;
|
||
using TMPro;
|
||
using UnityEngine;
|
||
using UnityEngine.UI;
|
||
|
||
public class MenuPageManager : UIPageBtnEventBase
|
||
{
|
||
public List<Button> buttons = new List<Button>();
|
||
public List<GameObject> showPages=new List<GameObject>();
|
||
private int currentIndex = 0;
|
||
|
||
public Color selectedColor = Color.yellow;
|
||
public Color unselectedColor = Color.black;
|
||
private GameObject currectSelectPage;
|
||
public BaoWenGuanLiPage baoWen;
|
||
|
||
|
||
private void Awake()
|
||
{
|
||
buttons[0].GetComponent<Outline>().effectColor = selectedColor;
|
||
}
|
||
|
||
private void OnEnable()
|
||
{
|
||
currectSelectPage = null;
|
||
baoWen.enabled = false;
|
||
}
|
||
public override void OnUpArrowClick()
|
||
{
|
||
base.OnUpArrowClick();
|
||
SelectPrevious();
|
||
}
|
||
public override void OnDownArrowClick()
|
||
{
|
||
base.OnDownArrowClick();
|
||
SelectNext();
|
||
}
|
||
|
||
public override void OnF3Click()
|
||
{
|
||
base.OnF3Click();
|
||
if (currectSelectPage != null)
|
||
{
|
||
currectSelectPage.SetActive(false);
|
||
currectSelectPage = null;
|
||
return;
|
||
}
|
||
if(currectSelectPage==null)
|
||
transform.parent.gameObject.SetActive(false);
|
||
|
||
}
|
||
|
||
public override void OnF4Click()
|
||
{
|
||
base.OnF4Click();
|
||
if (currectSelectPage != null)
|
||
currectSelectPage.transform.Find("Downtip").GetChild(1).GetComponent<TextMeshProUGUI>().text = "报文上报成功";
|
||
}
|
||
|
||
public override void OnF5Click()
|
||
{
|
||
BackMain();
|
||
}
|
||
|
||
public override void OnEnterBtnClick()
|
||
{
|
||
base.OnEnterBtnClick();
|
||
///打开对应的界面
|
||
GetCurrentButton().onClick?.Invoke();
|
||
|
||
}
|
||
|
||
|
||
/// <summary>
|
||
/// 切换到下一个按钮
|
||
/// </summary>
|
||
public void SelectNext()
|
||
{
|
||
if (buttons.Count == 0) return;
|
||
|
||
currentIndex = (currentIndex + 1) % buttons.Count;
|
||
UpdateButtonOutlines();
|
||
}
|
||
|
||
/// <summary>
|
||
/// 切换到上一个按钮
|
||
/// </summary>
|
||
public void SelectPrevious()
|
||
{
|
||
if (buttons.Count == 0) return;
|
||
|
||
currentIndex--;
|
||
if (currentIndex < 0) currentIndex = buttons.Count - 1;
|
||
UpdateButtonOutlines();
|
||
}
|
||
|
||
public void ShowPage()
|
||
{
|
||
|
||
if (currectSelectPage != null)
|
||
currectSelectPage.SetActive(false);
|
||
currectSelectPage =showPages.Find(x => x.name == GetCurrentButton().name);
|
||
currectSelectPage.SetActive(true);
|
||
currectSelectPage.transform.Find("Downtip").GetChild(1).GetComponent<TextMeshProUGUI>().text = "提示信息:‘上移’,‘下移’键切换焦点,按‘报文上报’键上报报文:F1返回报文查看";
|
||
}
|
||
|
||
public void BackMain()
|
||
{
|
||
if (currectSelectPage != null)
|
||
currectSelectPage.SetActive(false);
|
||
if (GetCurrentButton() != null)
|
||
GetCurrentButton().GetComponent<Outline>().effectColor = unselectedColor;
|
||
baoWen.BackToMain();
|
||
}
|
||
|
||
|
||
/// <summary>
|
||
/// 更新按钮的 Outline 颜色
|
||
/// </summary>
|
||
private void UpdateButtonOutlines()
|
||
{
|
||
for (int i = 0; i < buttons.Count; i++)
|
||
{
|
||
Outline outline = buttons[i].GetComponent<Outline>();
|
||
if (outline == null)
|
||
{
|
||
// 如果没有 Outline 组件则添加
|
||
outline = buttons[i].gameObject.AddComponent<Outline>();
|
||
}
|
||
|
||
outline.effectColor = (i == currentIndex) ? selectedColor : unselectedColor;
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 获取当前选中的按钮
|
||
/// </summary>
|
||
public Button GetCurrentButton()
|
||
{
|
||
if (buttons.Count == 0) return null;
|
||
return buttons[currentIndex];
|
||
}
|
||
|
||
/// <summary>
|
||
/// 设置当前选择的按钮索引
|
||
/// </summary>
|
||
public void SetCurrentIndex(int index)
|
||
{
|
||
if (index < 0 || index >= buttons.Count) return;
|
||
currentIndex = index;
|
||
UpdateButtonOutlines();
|
||
}
|
||
|
||
public GameObject GetCurrectPage()
|
||
{
|
||
return currectSelectPage;
|
||
}
|
||
|
||
public void HideGetCurrectPage()
|
||
{
|
||
currectSelectPage.SetActive(false);
|
||
currectSelectPage = null;
|
||
}
|
||
|
||
|
||
private void OnDisable()
|
||
{
|
||
currectSelectPage = null;
|
||
baoWen.enabled = true;
|
||
}
|
||
}
|