using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.Events; /// /// 学员组类 /// public class GOGroup { List onlineStudents;//组内所有成员数据 OnlineStudent master;//组长 StudentContentCtrl contentCtrl; int groupNumber; UnityAction onDestory;//组销毁时 人员等于0时触发 public int GroupNumber { get { return groupNumber; } } /// /// 创建分组时 注入组员 设置分组 注册组销毁信息 自动指定队长 /// /// public GOGroup(List selectStudent,int groupNumber,UnityAction onDestory, StudentContentCtrl contentCtrl) { this.contentCtrl = contentCtrl; this.onlineStudents = selectStudent; this.groupNumber = groupNumber; for (int i = 0; i < onlineStudents.Count; i++) { contentCtrl.SetStudentGroupNumber(onlineStudents[i].ip, groupNumber); } this.onDestory = onDestory; master = selectStudent[0]; contentCtrl.SetGroupMaster(master.ip, true); } //设置新队长 public void SetMaster(OnlineStudent selectStudent) { if (selectStudent == master) return; else { contentCtrl.SetGroupMaster(master.ip, false); ;//移除此前的队长 master = selectStudent; contentCtrl.SetGroupMaster(master.ip, true);//新的队长显示标记 } } //移除组成员 public void Remove(OnlineStudent selectStudent) { contentCtrl.SetStudentGroupNumber(selectStudent.ip,-1);// onlineStudents.Remove(selectStudent); if (onlineStudents.Count == 0) //组人员清空 { onDestory?.Invoke(groupNumber); } else if (selectStudent == master)//移除组长时 自动分配给下一个人 { contentCtrl.SetGroupMaster(onlineStudents[0].ip, true); master = onlineStudents[0]; } } /// /// 获取组内所有成员数据 /// /// public List GetAllStudent() { return onlineStudents; } }