ThreeDNav.cs 1.9 KB

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