123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190 |
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.EventSystems;
- public abstract class BaseList : BaseWindow {
- private BaseView[] _baseViewList;
- public BaseView[] BaseViewList {
- get {
- if (_baseViewList==null) {
- _baseViewList = GetComponentsInChildren<BaseView>();
- }
- return _baseViewList;
- }
- }
- public List<BaseConfig> configs;
- public int SumPage { get; set; }
- public int CurrentPage { get; set; }
- //public int CurrentViewNum=1;
- [Header("Can Emplty")]
- public SCButton preButton;
- [Header("Can Emplty")]
- public SCButton nextButton;
- [Header("Can Emplty")]
- public TextMesh title;
- [Header("Can Emplty")]
- public TextMesh pageNum;
- [Header("Can Emplty")]
- public Mark marks;
-
- void UpdateButtonsStatus() {
- if (SumPage == 1) {
- if (nextButton && nextButton.gameObject.activeSelf == true) {
- nextButton.gameObject.SetActive(false);
- }
- if (preButton && preButton.gameObject.activeSelf == true) {
- preButton.gameObject.SetActive(false);
- }
- } else if (CurrentPage == SumPage) {
- if (nextButton && nextButton.gameObject.activeSelf == true) {
- nextButton.gameObject.SetActive(false);
- }
- if (preButton && preButton.gameObject.activeSelf == false) {
- preButton.gameObject.SetActive(true);
- }
- } else if (CurrentPage == 1) {
- if (nextButton && nextButton.gameObject.activeSelf == false) {
- nextButton.gameObject.SetActive(true);
- }
- if (preButton && preButton.gameObject.activeSelf == true) {
- preButton.gameObject.SetActive(false);
- }
- } else {
- if (nextButton && nextButton.gameObject.activeSelf == false) {
- nextButton.gameObject.SetActive(true);
- }
- if (preButton && preButton.gameObject.activeSelf == false) {
- preButton.gameObject.SetActive(true);
- }
- }
- }
- public override void Awake() {
- base.Awake();
- SCButtonAddListener();
- }
- public void SetTitle(string title) {
- if (this.title) {
- this.title.text = title;
- }
- }
- public virtual void UpdateConfigs(List<BaseConfig> configs)
- {
- if (configs == null) {
- configs = new List<BaseConfig>();
- }
- Debug.Log("pei" + 1);
- this.configs = configs;
- try {
- //configs[CurrentViewNum-1].Init();
- } catch (Exception e) {
- //Debug.Log(e);
- }
- ///重新计算SumPage
- int aPageMaxView = BaseViewList.Length;
- Debug.Log("pei" + aPageMaxView+"teng");
- int sumConfigCount = configs.Count;
- Debug.Log("pei" + sumConfigCount + "fei");
- SumPage = sumConfigCount / aPageMaxView + (((sumConfigCount % aPageMaxView) != 0) ? 1 : 0);
- Debug.Log("pei" + SumPage + "tengfei");
- if (SumPage == 0)
- SumPage = 1;
- CurrentPage = 1;
- //Debug.Log("sumConfigCount:"+ sumConfigCount +" UpdateConfigs:" +SumPage);
- Refresh();
- }
- public virtual void Refresh() {
- if (configs == null)
- return;
- Debug.Log(777);
- ///Reset BaseView
- foreach (BaseView item in BaseViewList) {
- item.gameObject.SetActive(false);
- item.UpdateConfig(null);
- }
- Debug.Log(888);
- ///填充BaseView
- for (int i = (CurrentPage - 1) * BaseViewList.Length, j = 0; j < ((CurrentPage == SumPage) ? (configs.Count - BaseViewList.Length * (CurrentPage - 1)) : BaseViewList.Length); i++, j++)
- {
- configs[i].Index = i;
- if (BaseViewList.Length > j)
- {
- BaseViewList[j].gameObject.SetActive(true);
- BaseViewList[j].UpdateConfig(configs[i]);
-
- }
- }
- Debug.Log(999);
- UpdateButtonsStatus();
- if (pageNum) {
- pageNum.text = CurrentPage + "/" + SumPage;
- }
- if(marks) {
- marks.RefreshMarks(SumPage, CurrentPage);
- }
-
- }
- public void SCButtonAddListener() {
- if (preButton) {
- preButton.onEnter.AddListener(PreButtonOnEnter);
- preButton.onClick.AddListener(PreButtonOnClick);
- preButton.onDown.AddListener(PreButtonOnDown);
- preButton.onUp.AddListener(PreButtonOnUp);
- preButton.onExit.AddListener(PreButtonOnExit);
- }
- if (nextButton) {
- nextButton.onEnter.AddListener(NextButtonOnEnter);
- nextButton.onClick.AddListener(NextButtonOnClick);
- nextButton.onDown.AddListener(NextButtonOnDown);
- nextButton.onUp.AddListener(NextButtonOnUp);
- nextButton.onExit.AddListener(NextButtonOnExit);
- }
-
- }
- public virtual void NextButtonOnEnter() {
- }
- public virtual void NextButtonOnDown() {
- }
- public virtual void NextButtonOnUp() {
- CurrentPage = (CurrentPage + 1) > SumPage ? SumPage : (CurrentPage + 1);
- Refresh();
- }
- public virtual void NextButtonOnExit() {
- }
- public virtual void NextButtonOnClick() {
- }
- public virtual void PreButtonOnEnter() {
- }
- public virtual void PreButtonOnDown() {
- }
- public virtual void PreButtonOnUp() {
- CurrentPage = (CurrentPage - 1) < 1 ? 1 : (CurrentPage - 1);
- Refresh();
- }
- public virtual void PreButtonOnExit() {
- }
- public virtual void PreButtonOnClick() {
- }
- }
|