OnePicNav.cs 4.1 KB

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