using UnityEngine; using System.Collections; using System.Collections.Generic; using AX.MessageSystem; public abstract class BaseExamManager : MonoBehaviour { protected GameObject ItemPrefab; protected List ExamList = new List(); 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); } /// /// 从服务器获取考试信息列表 /// 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().anchoredPosition = new Vector2(posX, posY); examItem.name = "examItem-" + counter; //examItem.GetComponent().Exam = ExamList[counter]; examItem.GetComponent().Exam = ExamList[counter]; counter++; } else { return; } } } } }