ThreeDNav.cs 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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. private void Start()
  16. {
  17. CameraManager.SwitchCamera(0);
  18. InitButton();
  19. StaticLod.instance.OnFoucusStatic("TaoKou");
  20. }
  21. void InitButton()
  22. {
  23. btns = new List<Button>();
  24. Button[] bts = this.GetComponentsInChildren<Button>();
  25. for (int i = 0; i < bts.Length; i++)
  26. {
  27. btns.Add(bts[i]);
  28. }
  29. layers = new List<RectTransform>();
  30. for (int i = 0; i < content.transform.childCount; i++)
  31. {
  32. layers.Add(content.transform.GetChild(i).GetComponent<RectTransform>());
  33. }
  34. for (int i = 0; i < btns.Count; i++)
  35. {
  36. int index = i;
  37. btns[index].onClick.AddListener(() =>
  38. {
  39. for (int j = 0; j < layers.Count; j++)
  40. {
  41. layers[j].gameObject.SetActive(false);
  42. }
  43. for (int j = 0; j < btns.Count; j++)
  44. {
  45. btns[j].GetComponentInChildren<Text>().color = new Color32(137, 147, 173, 255);
  46. }
  47. btns[index].GetComponentInChildren<Text>().color = Color.white;
  48. Tweener tw = s_image.GetComponent<RectTransform>().DOLocalMoveX(targetPos[index].x, 0.3f);
  49. tw.SetEase(Ease.OutBack);
  50. if (index < layers.Count)
  51. {
  52. layers[index].gameObject.SetActive(true);
  53. }
  54. if (index == 4)
  55. {
  56. StaticLod.instance.OnFoucusStatic("Bird0");
  57. }
  58. else if (index == 1)
  59. {
  60. gCJK.OnBuYuanClick();
  61. }
  62. else
  63. {
  64. StaticLod.instance.OnFoucusStatic("TaoKou");
  65. }
  66. });
  67. }
  68. }
  69. private void Update()
  70. {
  71. znz.transform.rotation = Quaternion.Lerp(znz.transform.rotation, Quaternion.Euler(0, 0, CameraManager.instance.mainCamera.transform.localEulerAngles.y), Time.deltaTime * 4);
  72. }
  73. }