UIYuAnCtrl.cs 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using DG.Tweening;
  5. using UnityEngine.UI;
  6. namespace DTYJ
  7. {
  8. public class UIYuAnCtrl : MonoBehaviour
  9. {
  10. public static UIYuAnCtrl Instance;
  11. public RectTransform panel;
  12. public Button btn_pre, btn_next;
  13. public Text textInfo;
  14. private void Awake()
  15. {
  16. Instance = this;
  17. btn_pre.onClick.AddListener(OnPre);
  18. btn_next.onClick.AddListener(OnNext);
  19. Show(false);
  20. }
  21. private void OnPre()
  22. {
  23. --Index;
  24. }
  25. private void OnNext()
  26. {
  27. ++Index;
  28. }
  29. private List<string> listInfo = new List<string>() {"µÚÒ»²½", "µÚ¶þ²½", "µÚÈý²½" };
  30. private int _index = 0;
  31. private int Index
  32. {
  33. get { return _index; }
  34. set
  35. {
  36. _index = Mathf.Clamp(value, 0, listInfo.Count);
  37. btn_pre.interactable = _index > 0;
  38. btn_next.interactable = _index < listInfo.Count - 1;
  39. SetInfo();
  40. }
  41. }
  42. private void SetInfo()
  43. {
  44. if (Index >= 0 && Index < listInfo.Count)
  45. textInfo.text = $"{Index + 1}:{ listInfo[Index]}";
  46. else
  47. textInfo.text = "";
  48. }
  49. public void Init(List<string> list)
  50. {
  51. listInfo = list;
  52. Index = 0;
  53. }
  54. float closeX = 0.001f;
  55. public void Show(bool view)
  56. {
  57. gameObject.SetActive(view);
  58. panel.localScale = new Vector3(closeX, 1, 1);
  59. Index = 0;
  60. }
  61. public void OnClickUnfold()
  62. {
  63. panel.DOScaleX(panel.localScale.x == 1 ? closeX : 1, .5f);
  64. }
  65. }
  66. }