TeamBar.cs 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. using UnityEngine;
  2. using UnityEngine.UI;
  3. using System.Collections;
  4. using System.Collections.Generic;
  5. public class TeamBar : MonoBehaviour
  6. {
  7. public MenuUI menuUI;
  8. public TeamNick[] teamNickArr;
  9. public Text inviteBtnLabel;
  10. void Start()
  11. {
  12. InviteManager.GetInstance ().TeamUpdated.AddListener (OnTeamUpdate);
  13. OnTeamUpdate ();
  14. }
  15. void OnDestroy()
  16. {
  17. InviteManager.GetInstance ().TeamUpdated.RemoveListener (OnTeamUpdate);
  18. for(int i=0; i<teamNickArr.Length; i++)
  19. {
  20. teamNickArr [i].Dispose ();
  21. }
  22. }
  23. private void OnTeamUpdate()
  24. {
  25. int myId = Session.GetInstance ().myUserData.id;
  26. int index = 0;
  27. List<int> list = InviteManager.GetInstance ().GetTeamList ();
  28. for(int i=0; i<list.Count; i++)
  29. {
  30. int id = list [i];
  31. if(id != myId)
  32. {
  33. teamNickArr [index].SetData (id);
  34. teamNickArr [index].gameObject.SetActive (true);
  35. index++;
  36. }
  37. }
  38. for(int i=index; i<teamNickArr.Length; i++)
  39. {
  40. teamNickArr [i].gameObject.SetActive (false);
  41. }
  42. if(InviteManager.GetInstance().IsLeader(myId) || !InviteManager.GetInstance().IsInTeam(myId))
  43. {
  44. inviteBtnLabel.text = Language.GetStr("Invite", "inviteLabel");
  45. }
  46. else
  47. {
  48. inviteBtnLabel.text = Language.GetStr("Invite", "leaveLabel");
  49. }
  50. }
  51. public void Invite()
  52. {
  53. int myId = Session.GetInstance ().myUserData.id;
  54. if (!InviteManager.GetInstance().IsLeader(myId) && InviteManager.GetInstance().IsInTeam(myId)) {
  55. AlertPanel.Show (Language.GetStr("Invite", "teamLeftConfirm"), AlertPanel.YES|AlertPanel.NO, (AlertCloseEvent evt)=>{
  56. if(evt.detail == AlertPanel.YES)
  57. {
  58. Session.GetInstance().GetBattleSession().GetMessageManager().TeamLeft();
  59. }
  60. });
  61. } else {
  62. menuUI.inviteBar.Show ();
  63. }
  64. }
  65. }