216 lines
5.5 KiB
C#
216 lines
5.5 KiB
C#
using System.Collections;
|
||
using System.Collections.Generic;
|
||
using System.Linq;
|
||
using TMPro;
|
||
using UnityEngine;
|
||
|
||
public class JiShuZhenDiPage : UIPageBtnEventBase
|
||
{
|
||
public List<GameObject> myPages=new List<GameObject>();
|
||
|
||
|
||
public CustomTMPDropdown 定位方式;
|
||
public TextMeshProUGUI 定位方式text;
|
||
public CustomTMPDropdown 获取方式;
|
||
public Transform 读取方式tips;
|
||
public GameObject xunbeiBtn;
|
||
public TextMeshProUGUI xunbeiTip;
|
||
public GameObject daohangMsg;
|
||
|
||
private void Awake()
|
||
{
|
||
定位方式.onValueChanged.AddListener(OnDropChange);
|
||
获取方式.onValueChanged.AddListener(OnReadChange);
|
||
}
|
||
|
||
public void OnDropChange(int index)
|
||
{
|
||
定位方式text.text= 定位方式.options[index].text;
|
||
}
|
||
|
||
public void OnReadChange(int value)
|
||
{
|
||
ShowReadTip(value);
|
||
}
|
||
|
||
|
||
void ShowReadTip(int currectIndex)
|
||
{
|
||
for (int i = 0; i < 读取方式tips.childCount; i++)
|
||
{
|
||
读取方式tips.GetChild(i).gameObject.SetActive(false);
|
||
}
|
||
读取方式tips.GetChild(currectIndex).gameObject.SetActive(true);
|
||
}
|
||
|
||
private void OnEnable()
|
||
{
|
||
enter181 = FindObjectOfType<Enter181Page>();
|
||
for (int i = 0; i < myPages.Count; i++)
|
||
{
|
||
myPages[i].SetActive(false);
|
||
}
|
||
myPages[0].SetActive(true);
|
||
myPages[0].transform.GetChild(0).gameObject.SetActive(true);
|
||
currentIndex = 0;
|
||
}
|
||
|
||
public override void OnF1Click()
|
||
{
|
||
base.OnF1Click();
|
||
F1Event();
|
||
//F1需要根据不同的界面执行不同的逻辑,待定
|
||
}
|
||
|
||
public override void OnF2Click()
|
||
{
|
||
base.OnF2Click();
|
||
|
||
if (xunbeiBtn.activeInHierarchy == false)
|
||
return;
|
||
//F2需要根据不同的界面执行不同的逻辑,待定
|
||
if (myPages[currentIndex].name == "4-惯导寻北") //点击F2后出现寻北时间
|
||
{
|
||
xunbeiTip.text = "惯导状态:正在寻北";
|
||
myPages[currentIndex].transform.GetChild(1).gameObject.SetActive(true);
|
||
StartCoroutine(UpdateTime(myPages[currentIndex].transform.GetChild(1).GetComponent<TextMeshProUGUI>()));
|
||
return;
|
||
}
|
||
|
||
}
|
||
|
||
IEnumerator UpdateTime(TextMeshProUGUI timeText)
|
||
{
|
||
for (int i = 896; i >= 0; i--)
|
||
{
|
||
timeText.text = "寻北时间:" + i;
|
||
yield return new WaitForSeconds(0.016f); // 每秒更新
|
||
//yield return null;
|
||
}
|
||
yield return new WaitForSeconds(1);
|
||
myPages[currentIndex].transform.GetChild(1).gameObject.SetActive(false);
|
||
xunbeiTip.text = "惯导状态:导航";
|
||
daohangMsg.SetActive(true);
|
||
}
|
||
|
||
|
||
public override void OnF3Click()
|
||
{
|
||
base.OnF3Click();
|
||
//F3是上一页
|
||
Previous();
|
||
//if (currentIndex == 3)
|
||
// myPages[3].transform.GetChild(1).gameObject.SetActive(false);
|
||
|
||
}
|
||
|
||
public override void OnF4Click()
|
||
{
|
||
base.OnF4Click();
|
||
Next();
|
||
//if (currentIndex == 3)
|
||
// myPages[3].transform.GetChild(1).gameObject.SetActive(false);
|
||
}
|
||
|
||
public Enter181Page enter181;
|
||
public override void OnF5Click() {
|
||
|
||
base.OnF5Click();
|
||
enter181.OnShow();
|
||
ResetPage(myPages);
|
||
//gameObject.SetActive(false);
|
||
Destroy(gameObject);
|
||
}
|
||
|
||
void ResetPage(List<GameObject> targets)
|
||
{
|
||
DeactivateAllObjects(myPages);
|
||
}
|
||
|
||
public void DeactivateAllObjects(List<GameObject> targetObjects)
|
||
{
|
||
|
||
foreach (var obj in targetObjects.Where(obj => obj != null))
|
||
{
|
||
obj.SetActive(false);
|
||
|
||
|
||
foreach (Transform child in obj.transform)
|
||
{
|
||
child.gameObject.SetActive(false);
|
||
}
|
||
}
|
||
}
|
||
|
||
|
||
|
||
/// <summary>
|
||
/// 本界面的F1设置
|
||
/// </summary>
|
||
void F1Event()
|
||
{
|
||
switch (myPages[currentIndex].name)
|
||
{
|
||
case "1-系统巡检":
|
||
|
||
myPages[currentIndex].transform.GetChild(0).gameObject.SetActive(false);
|
||
myPages[currentIndex].transform.GetChild(1).gameObject.SetActive(true);
|
||
break;
|
||
|
||
case "4-惯导寻北":
|
||
//点击后显示寻北按钮
|
||
xunbeiBtn.SetActive(true);
|
||
//myPages[currentIndex].transform.GetChild(1).gameObject.SetActive(true); //打开寻北text --可能要做时间变化
|
||
break;
|
||
}
|
||
}
|
||
|
||
private int currentIndex = 0;
|
||
|
||
/// <summary>
|
||
/// 切换到下一个元素
|
||
/// </summary>
|
||
public void Next()
|
||
{
|
||
if (myPages == null || myPages.Count == 0) return;
|
||
|
||
// 如果是最后一个元素,则不进行操作
|
||
if (currentIndex >= myPages.Count - 1) return;
|
||
|
||
// 隐藏当前元素
|
||
if (myPages[currentIndex] != null)
|
||
myPages[currentIndex].SetActive(false);
|
||
|
||
currentIndex++;
|
||
|
||
// 显示下一个元素
|
||
if (myPages[currentIndex] != null)
|
||
{
|
||
myPages[currentIndex].SetActive(true);
|
||
//默认打开第一个子界面
|
||
myPages[currentIndex].transform.GetChild(0).gameObject.SetActive(true);
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 切换到上一个元素
|
||
/// </summary>
|
||
public void Previous()
|
||
{
|
||
if (myPages == null || myPages.Count == 0) return;
|
||
|
||
// 如果是第一个元素,则不进行操作
|
||
if (currentIndex <= 0) return;
|
||
|
||
// 隐藏当前元素
|
||
if (myPages[currentIndex] != null)
|
||
myPages[currentIndex].SetActive(false);
|
||
|
||
currentIndex--;
|
||
|
||
// 显示上一个元素
|
||
if (myPages[currentIndex] != null)
|
||
myPages[currentIndex].SetActive(true);
|
||
}
|
||
}
|