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