OnePicNav.cs 4.0 KB

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