OnePicNav.cs 5.3 KB

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