OnePicNav.cs 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. using DG.Tweening;
  2. using System;
  3. using System.Collections;
  4. using System.Collections.Generic;
  5. using System.Xml;
  6. using Unity.VisualScripting;
  7. using UnityEngine;
  8. using UnityEngine.UI;
  9. public class OnePicNav : MonoBehaviour
  10. {
  11. public static OnePicNav instance;
  12. public Vector2[] targetPos;
  13. public List<Button> btns;
  14. public Image s_image;
  15. public List<RectTransform> layers;
  16. public GameObject content;
  17. public RectTransform znz;
  18. public RectTransform[] runtimePointStatic;
  19. public List<Transform> runtimePointStaticBind;
  20. public GameObject shaPan;
  21. public GameObject bingMapItemCol;
  22. public int lastIndex = -99;
  23. // Start is called before the first frame update
  24. void Start()
  25. {
  26. instance = this;
  27. InitButton();
  28. }
  29. void InitButton() {
  30. shaPan = GameObject.FindGameObjectWithTag("ShaPan");
  31. Debug.Log(shaPan);
  32. runtimePointStaticBind.Add(shaPan.transform.Find("FixPoint").GetChild(0));
  33. runtimePointStaticBind.Add(shaPan.transform.Find("FixPoint").GetChild(1));
  34. runtimePointStaticBind.Add(shaPan.transform.Find("FixPoint").GetChild(2));
  35. CameraManager.SwitchCamera(1);
  36. btns = new List<Button>();
  37. Button[] bts = this.GetComponentsInChildren<Button>();
  38. for (int i = 0; i < bts.Length; i++) {
  39. btns.Add(bts[i]);
  40. }
  41. layers = new List<RectTransform>();
  42. for (int i = 0; i < content.transform.childCount; i++) {
  43. layers.Add(content.transform.GetChild(i).GetComponent<RectTransform>());
  44. }
  45. layers[0].gameObject.SetActive(true);
  46. for (int i = 0; i < btns.Count; i++)
  47. {
  48. int index = i;
  49. btns[index].onClick.AddListener(() =>
  50. {
  51. OnButtnClick(index);
  52. });
  53. }
  54. }
  55. public void OnButtnClick(int index) {
  56. if (lastIndex == index)
  57. return;
  58. if (lastIndex > -1) {
  59. layers[lastIndex].GetComponent<YZTRootLayer>().OnUILeave();
  60. }
  61. for (int j = 0; j < layers.Count; j++)
  62. {
  63. layers[j].gameObject.SetActive(false);
  64. }
  65. for (int j = 0; j < btns.Count; j++)
  66. {
  67. btns[j].GetComponentInChildren<Text>().color = new Color32(137, 147, 173, 255);
  68. }
  69. btns[index].GetComponentInChildren<Text>().color = Color.white;
  70. lastIndex = index;
  71. Tweener tw = s_image.GetComponent<RectTransform>().DOLocalMoveX(targetPos[index].x, 0.3f);
  72. tw.SetEase(Ease.OutBack);
  73. if (index < layers.Count)
  74. if (index == 0 || index == 2 || index == 5)
  75. {
  76. if (layers[index].GetComponent<YZTRootLayer>().viewMode == ViewMode.miniMap)
  77. {
  78. CameraManager.SwitchCamera(1);
  79. }
  80. else
  81. {
  82. CameraManager.SwitchCamera(0);
  83. }
  84. }
  85. else
  86. {
  87. CameraManager.SwitchCamera(0);
  88. }
  89. layers[index].gameObject.SetActive(true);
  90. }
  91. public void SwitchToGlobalWeather()
  92. {
  93. OnButtnClick(2);
  94. layers[2].GetComponent<GCJKLayer>().OnGlobalWeatherClick();
  95. }
  96. public void SwitchToGlobalWaterHeight()
  97. {
  98. OnButtnClick(5);
  99. layers[5].GetComponent<SWYJLayer>().OnGlobalSWBtnClick();
  100. }
  101. // Update is called once per frame
  102. void LateUpdate()
  103. {
  104. if (CameraManager.instance.mainCamera.enabled)
  105. znz.transform.rotation = Quaternion.Lerp(znz.transform.rotation, Quaternion.Euler(0, 0, CameraManager.instance.mainCamera.transform.localEulerAngles.y), Time.deltaTime * 4);
  106. else
  107. znz.transform.rotation = Quaternion.identity;
  108. for (int i = 0; i < runtimePointStatic.Length; i++)
  109. {
  110. bool cameraEnable = CameraManager.instance.secondCamera.enabled;
  111. runtimePointStatic[i].gameObject.SetActive(cameraEnable);
  112. if (cameraEnable)
  113. runtimePointStatic[i].anchoredPosition = CameraManager.instance.secondCamera.WorldToScreenPoint(runtimePointStaticBind[i].transform.position) * 1920.0f / Screen.width;
  114. }
  115. if (CameraManager.instance.mainCamera.transform.position.y > 3200)
  116. {
  117. if (CameraManager.instance.mainCamera.enabled)
  118. {
  119. bingMapItemCol.gameObject.SetActive(true);
  120. bingMapItemCol.GetComponent<CanvasGroup>().alpha = Mathf.Lerp(0, 1, Mathf.Abs(CameraManager.instance.mainCamera.transform.position.y - 3200)/600.0f);
  121. }
  122. else {
  123. bingMapItemCol.gameObject.SetActive(false);
  124. }
  125. }
  126. else {
  127. bingMapItemCol.gameObject.SetActive(false);
  128. }
  129. }
  130. }