ThreeDNav.cs 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. using DG.Tweening;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using UnityEngine;
  5. using UnityEngine.UI;
  6. public class ThreeDNav : MonoBehaviour
  7. {
  8. public Vector2[] targetPos;
  9. public Image s_image;
  10. public List<Button> btns;
  11. public List<RectTransform> layers;
  12. public GameObject content;
  13. public RectTransform znz;
  14. public GCJKLayer gCJK;
  15. public ObsPlayerPanel obsPlayerPanel;
  16. public static ThreeDNav instance;
  17. private void Awake()
  18. {
  19. instance = this;
  20. }
  21. private void Start()
  22. {
  23. CameraManager.SwitchCamera(0);
  24. InitButton();
  25. StaticLod.instance.OnFoucusStatic("TaoKou");
  26. }
  27. void InitButton()
  28. {
  29. btns = new List<Button>();
  30. Button[] bts = this.GetComponentsInChildren<Button>();
  31. for (int i = 0; i < bts.Length; i++)
  32. {
  33. btns.Add(bts[i]);
  34. }
  35. layers = new List<RectTransform>();
  36. for (int i = 0; i < content.transform.childCount; i++)
  37. {
  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. {
  51. btns[j].GetComponentInChildren<Text>().color = new Color32(137, 147, 173, 255);
  52. }
  53. obsPlayerPanel.gameObject.SetActive(false);
  54. btns[index].GetComponentInChildren<Text>().color = Color.white;
  55. Tweener tw = s_image.GetComponent<RectTransform>().DOLocalMoveX(targetPos[index].x, 0.3f);
  56. tw.SetEase(Ease.OutBack);
  57. if (index < layers.Count)
  58. {
  59. layers[index].gameObject.SetActive(true);
  60. }
  61. if (index == 4)
  62. {
  63. StaticLod.instance.OnFoucusStatic("Bird0");
  64. }
  65. else if (index == 1)
  66. {
  67. gCJK.OnBuYuanClick();
  68. }
  69. else
  70. {
  71. StaticLod.instance.OnFoucusStatic("TaoKou");
  72. }
  73. });
  74. }
  75. }
  76. public void ShowObsPanel(ObsData _data)
  77. {
  78. obsPlayerPanel.gameObject.SetActive(true);
  79. obsPlayerPanel.SetObsData(_data);
  80. obsPlayerPanel.SetTitle(_data.name);
  81. }
  82. private void Update()
  83. {
  84. znz.transform.rotation = Quaternion.Lerp(znz.transform.rotation, Quaternion.Euler(0, 0, CameraManager.instance.mainCamera.transform.localEulerAngles.y), Time.deltaTime * 4);
  85. }
  86. }