OnePicNav.cs 4.1 KB

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