12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576 |
- using UnityEngine;
- using UnityEngine.UI;
- using System.Collections;
- using System.Collections.Generic;
- public class TeamBar : MonoBehaviour
- {
- public MenuUI menuUI;
- public TeamNick[] teamNickArr;
- public Text inviteBtnLabel;
- void Start()
- {
- InviteManager.GetInstance ().TeamUpdated.AddListener (OnTeamUpdate);
- OnTeamUpdate ();
- }
- void OnDestroy()
- {
- InviteManager.GetInstance ().TeamUpdated.RemoveListener (OnTeamUpdate);
- for(int i=0; i<teamNickArr.Length; i++)
- {
- teamNickArr [i].Dispose ();
- }
- }
- private void OnTeamUpdate()
- {
- int myId = Session.GetInstance ().myUserData.id;
- int index = 0;
- List<int> list = InviteManager.GetInstance ().GetTeamList ();
- for(int i=0; i<list.Count; i++)
- {
- int id = list [i];
- if(id != myId)
- {
- teamNickArr [index].SetData (id);
- teamNickArr [index].gameObject.SetActive (true);
- index++;
- }
- }
- for(int i=index; i<teamNickArr.Length; i++)
- {
- teamNickArr [i].gameObject.SetActive (false);
- }
- if(InviteManager.GetInstance().IsLeader(myId) || !InviteManager.GetInstance().IsInTeam(myId))
- {
- inviteBtnLabel.text = Language.GetStr("Invite", "inviteLabel");
- }
- else
- {
- inviteBtnLabel.text = Language.GetStr("Invite", "leaveLabel");
- }
- }
- public void Invite()
- {
- int myId = Session.GetInstance ().myUserData.id;
- if (!InviteManager.GetInstance().IsLeader(myId) && InviteManager.GetInstance().IsInTeam(myId)) {
- AlertPanel.Show (Language.GetStr("Invite", "teamLeftConfirm"), AlertPanel.YES|AlertPanel.NO, (AlertCloseEvent evt)=>{
- if(evt.detail == AlertPanel.YES)
- {
- Session.GetInstance().GetBattleSession().GetMessageManager().TeamLeft();
- }
- });
- } else {
- menuUI.inviteBar.Show ();
- }
- }
- }
|