ThreeDNav.cs 2.2 KB

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