You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
122 lines
3.3 KiB
122 lines
3.3 KiB
3 years ago
|
using UnityEngine;
|
||
|
using System.Collections;
|
||
|
using UnityEngine.UI;
|
||
|
using AX.NetworkSystem;
|
||
|
using AX.MessageSystem;
|
||
|
|
||
|
public struct TeacherLessonRequestPair
|
||
|
{
|
||
|
public int currentPage;
|
||
|
public int numberEachPage;
|
||
|
|
||
|
}
|
||
|
public class TeacherLessonControl : MonoBehaviour
|
||
|
{
|
||
|
|
||
|
// Use this for initialization
|
||
|
public int pageCount = 60;
|
||
|
public int currentPage = 1;
|
||
|
public int numberEachPage = 10;
|
||
|
public GameObject itemPrefab;
|
||
|
private int startPage = 1;
|
||
|
private int endPage;
|
||
|
void Start()
|
||
|
{
|
||
|
getPageDataRequest();
|
||
|
MessageDispatcher.AddListener("TEACHER_LESSON_REFRESH", pageChanged);
|
||
|
}
|
||
|
void OnDestroy()
|
||
|
{
|
||
|
MessageDispatcher.RemoveListener("TEACHER_LESSON_REFRESH", pageChanged);
|
||
|
}
|
||
|
// Update is called once per frame
|
||
|
void Update()
|
||
|
{
|
||
|
|
||
|
}
|
||
|
//请求服务端考试数据
|
||
|
void getPageDataRequest()
|
||
|
{
|
||
|
NetworkManager.Default.SendRequestAsync("TEACH_LESSON_REQUEST", new PagingRequestInfo { CurrentPage = currentPage, NumberPerPage = numberEachPage });
|
||
|
}
|
||
|
//刷新页码
|
||
|
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<Toggle>().group = GetComponent<ToggleGroup>();
|
||
|
item.GetComponent<QuestionPageMessage>().setPage(startPage);
|
||
|
if (startPage == currentPage)
|
||
|
{
|
||
|
item.GetComponent<Toggle>().isOn = true;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
//换页请求返回后刷新页码
|
||
|
private void pageChanged(IMessage message)
|
||
|
{
|
||
|
PagingReplyInfo<CoursewareInfo> pair = (PagingReplyInfo<CoursewareInfo>)(message.Data);
|
||
|
currentPage = pair.CurrentPage;
|
||
|
numberEachPage = pair.NumberPerPage;
|
||
|
pageCount = pair.PageCount;
|
||
|
if (currentPage < startPage)
|
||
|
{
|
||
|
changePagePanel(false);//向前刷新
|
||
|
}
|
||
|
else if (currentPage > endPage)
|
||
|
{
|
||
|
changePagePanel(true);//向后刷新
|
||
|
}
|
||
|
else //只改变选中页码
|
||
|
{
|
||
|
foreach (Transform child in transform)
|
||
|
{
|
||
|
if (child.GetComponent<QuestionPageMessage>().page == currentPage)
|
||
|
{
|
||
|
child.GetComponent<Toggle>().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();
|
||
|
}
|
||
|
}
|