using UnityEngine; using System.Collections; using UnityEngine.UI; using AX.NetworkSystem; using AX.MessageSystem; public struct PaperPageRequestPair { public int currentPage; public int numberEachPage; public int Pattern; } public class PaperPageControl : MonoBehaviour { // Use this for initialization public int pageCount = 60; public int currentPage = 1; public int numberEachPage = 10; public GameObject itemPrefab; protected int startPage = 1; protected int endPage; public virtual void Start() { getPageDataRequest(); MessageDispatcher.AddListener("PAPER_PAGE_REFRESH", pageChanged); } public virtual void OnDestroy() { MessageDispatcher.RemoveListener("PAPER_PAGE_REFRESH", pageChanged); } // Update is called once per frame void Update() { } public void ResetPageData() { currentPage = 1; getPageDataRequest(); } //请求服务端考试数据 public virtual void getPageDataRequest() { NetworkManager.Default.SendRequestAsync("PAPER_PAGE_REQUEST", new PaperPageRequestPair { currentPage = currentPage, numberEachPage = numberEachPage,Pattern=(int)ExamInfoHelpClass.applicationMode }); } //刷新页码 protected void changePagePanel(bool flag) { foreach (Transform child in transform) { Destroy(child.gameObject); } if (flag) { startPage = currentPage; endPage = currentPage + 7; if (endPage > pageCount) { endPage = pageCount; } } else { endPage = currentPage; startPage = currentPage - 7; } for (int startPage = this.startPage; startPage <= endPage; startPage++) { GameObject item = Instantiate(itemPrefab) as GameObject; item.transform.parent = transform; //item.transform.localScale = new Vector3(1, 1, 1); item.name = "Item"; item.GetComponent().group = GetComponent(); item.GetComponent().setPage(startPage); if (startPage == currentPage) { item.GetComponent().isOn = true; } } } //换页请求返回后刷新页码 protected void pageChanged(IMessage message) { PagingReplyInfo pair = (PagingReplyInfo)(message.Data); currentPage = pair.CurrentPage; numberEachPage = pair.NumberPerPage; pageCount = pair.PageCount; if (currentPage < startPage) { changePagePanel(false);//向前刷新 } else if (currentPage > endPage || currentPage == 1) { changePagePanel(true);//向后刷新 } else //只改变选中页码 { foreach (Transform child in transform) { if (child.GetComponent().page == currentPage) { child.GetComponent().isOn = true; } } } } public void selectPage(int page) { currentPage = page; getPageDataRequest(); } public void upPage() { if (currentPage == 1) return; currentPage--; getPageDataRequest(); } public void downPage() { if (currentPage == pageCount || pageCount==0) return; currentPage++; getPageDataRequest(); } }