| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using DG.Tweening;
- using UnityEngine.UI;
- namespace DTYJ
- {
- public class UIYuAnCtrl : MonoBehaviour
- {
- public static UIYuAnCtrl Instance;
- public RectTransform panel;
- public Button btn_pre, btn_next;
- public Text textInfo;
- private void Awake()
- {
- Instance = this;
- btn_pre.onClick.AddListener(OnPre);
- btn_next.onClick.AddListener(OnNext);
- Show(false);
- }
- private void OnPre()
- {
- --Index;
- }
- private void OnNext()
- {
- ++Index;
- }
- private List<string> listInfo = new List<string>() {"µÚÒ»²½", "µÚ¶þ²½", "µÚÈý²½" };
- private int _index = 0;
- private int Index
- {
- get { return _index; }
- set
- {
- _index = Mathf.Clamp(value, 0, listInfo.Count);
- btn_pre.interactable = _index > 0;
- btn_next.interactable = _index < listInfo.Count - 1;
- SetInfo();
- }
- }
- private void SetInfo()
- {
- if (Index >= 0 && Index < listInfo.Count)
- textInfo.text = $"{Index + 1}:{ listInfo[Index]}";
- else
- textInfo.text = "";
- }
- public void Init(List<string> list)
- {
- listInfo = list;
- Index = 0;
- }
- float closeX = 0.001f;
- public void Show(bool view)
- {
- gameObject.SetActive(view);
- panel.localScale = new Vector3(closeX, 1, 1);
- Index = 0;
- }
- public void OnClickUnfold()
- {
- panel.DOScaleX(panel.localScale.x == 1 ? closeX : 1, .5f);
- }
- }
- }
|