using System.Collections; using System.Collections.Generic; using System.Linq; using TMPro; using UnityEngine; public class JiShuZhenDiPage : UIPageBtnEventBase { public List myPages=new List(); public CustomTMPDropdown 定位方式; public TextMeshProUGUI 定位方式text; public CustomTMPDropdown 获取方式; public Transform 读取方式tips; public GameObject xunbeiBtn; public TextMeshProUGUI xunbeiTip; public GameObject daohangMsg; public CustomTMPDropdown 阵地数据; int xunbeiTime; private void Awake() { 定位方式.onValueChanged.AddListener(OnDropChange); 获取方式.onValueChanged.AddListener(OnReadChange); xunbeiTime = 280; } public void OnDropChange(int index) { 定位方式text.text= 定位方式.options[index].text; } public void OnReadChange(int value) { ShowReadTip(value); } /// /// 根据不同的寻北方式确定不同的寻北时间 /// /// public void ChangeXunBeiTime(int index) { if (index == 0) { xunbeiTime = 280; } else { xunbeiTime = 895; } } public void UpdateZhenDiShuJu(int index) { Manager181Logic.Instance.zhenDiShuJuType = 阵地数据.options[index].text; } 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(); 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())); return; } } IEnumerator UpdateTime(TextMeshProUGUI timeText) { for (int i = xunbeiTime; 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 targets) { DeactivateAllObjects(myPages); } public void DeactivateAllObjects(List targetObjects) { foreach (var obj in targetObjects.Where(obj => obj != null)) { obj.SetActive(false); foreach (Transform child in obj.transform) { child.gameObject.SetActive(false); } } } /// /// 本界面的F1设置 /// 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; /// /// 切换到下一个元素 /// 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); } } /// /// 切换到上一个元素 /// 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); } }