MailPanel.cs 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. using UnityEngine;
  2. using UnityEngine.UI;
  3. using System.Collections;
  4. using System.Collections.Generic;
  5. public class MailPanel : PopUpPanel {
  6. public Text title;
  7. public Transform listContainer;
  8. public MailItem itemPrefab;
  9. void Awake ()
  10. {
  11. title.text = Language.GetStr("MailPanel", "title");
  12. ListHelper.HideAll (listContainer);
  13. itemPrefab.mailPanel = this;
  14. }
  15. protected override void Shown ()
  16. {
  17. FillMsg (ChatManager.GetInstance ().GetMailMsgList());
  18. ChatManager.GetInstance ().MailMsgGot.AddListener (OnMailMsgGot);
  19. }
  20. private void FillMsg(List<ChatMsg> list)
  21. {
  22. ListHelper.FillList<ChatMsg> (listContainer, list, itemPrefab, ChatManager.MAX_MAIL);
  23. }
  24. private void OnMailMsgGot(ChatMsg chatMsg)
  25. {
  26. ListHelper.AddToList<ChatMsg> (listContainer, chatMsg, itemPrefab, ChatManager.MAX_MAIL);
  27. }
  28. override protected void Remove()
  29. {
  30. base.Remove ();
  31. currentPanel = null;
  32. ChatManager.GetInstance ().MailMsgGot.RemoveListener (OnMailMsgGot);
  33. }
  34. private static MailPanel currentPanel;
  35. public static MailPanel Show()
  36. {
  37. if (currentPanel != null) {
  38. currentPanel.gameObject.SetActive (true);
  39. PopUpManager.AddToMainCanvas (currentPanel.gameObject);
  40. }
  41. else
  42. currentPanel = PopUpManager.AddPopUp<MailPanel> (Resources.Load<GameObject> ("Prefabs/UI/MailPanel/MailPanel"), null, true);
  43. currentPanel.Open ();
  44. return currentPanel;
  45. }
  46. }