天津23维预案
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.
 
 
 
 
 
 

73 lines
2.2 KiB

using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using AX.MessageSystem;
public abstract class BaseExamManager : MonoBehaviour {
protected GameObject ItemPrefab;
protected List<ExaminationInfo> ExamList = new List<ExaminationInfo>();
protected float posX = 300;
protected float posY = -300;
protected string MESSAGETYPE;
void Awake()
{
InitMessageType();
MessageDispatcher.AddListener(MESSAGETYPE, GetData);
InitInfo();
//GetExamInfoFromServer();测试时赋值假数据
}
public abstract void InitMessageType();
public abstract void GetData(IMessage message);
//连接服务器,获取考试信息数据
public abstract void GetExamInfoFromServer();
//给预制体赋值(不同的预制体)
public abstract void InitInfo();
void Start()
{
}
void OnDestroy()
{
MessageDispatcher.RemoveListener(MESSAGETYPE, GetData);
}
/// <summary>
/// 从服务器获取考试信息列表
/// </summary>
protected void GenerateExamItem() //开始创建节点预设
{
int column = 4;//列数
int row = Mathf.CeilToInt((float)ExamList.Count / column);//行数
int counter = 0;
for (int i = 0; i < row; i++)
{
for (int j = 0; j < column; j++)
{
if (counter < ExamList.Count)
{
posX = 200 + 64 * (j + 1) + j * 400;
posY = -300 - i * 400;
GameObject examItem = Instantiate(ItemPrefab);
examItem.transform.SetParent(transform);
examItem.transform.localScale = new Vector3(1, 1, 1);
examItem.GetComponent<RectTransform>().anchoredPosition = new Vector2(posX, posY);
examItem.name = "examItem-" + counter;
//examItem.GetComponent<ExamItemManager>().Exam = ExamList[counter];
examItem.GetComponent<BaseItemManager>().Exam = ExamList[counter];
counter++;
}
else
{
return;
}
}
}
}
}