OnePicNav.cs 4.2 KB

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