ChatBarChatView.cs 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. using UnityEngine;
  2. using UnityEngine.UI;
  3. using System.Collections;
  4. public class ChatBarChatView : View
  5. {
  6. public Text findFriendBtnLabel;
  7. public Transform container;
  8. public ChatBarChatItem itemPrefab;
  9. protected override void OnInitCompleted ()
  10. {
  11. if (!FollowManager.GetInstance ().initialized)
  12. {
  13. ListHelper.HideAll (container);
  14. FollowManager.GetInstance ().InitCompletion.AddListener (OnFollowersInit);
  15. FollowManager.GetInstance ().Init ();
  16. }
  17. else
  18. {
  19. OnFollowersInit ();
  20. }
  21. }
  22. protected override void OnDestroy ()
  23. {
  24. base.OnDestroy ();
  25. FollowManager.GetInstance ().InitCompletion.RemoveListener (OnFollowersInit);
  26. FollowManager.GetInstance ().FollowAdded.RemoveListener (OnFollowAdded);
  27. FollowManager.GetInstance ().FollowDeleted.RemoveListener (OnFollowDeleted);
  28. }
  29. private void OnFollowersInit()
  30. {
  31. FollowManager.GetInstance ().InitCompletion.RemoveListener (OnFollowersInit);
  32. FollowManager.GetInstance ().FollowAdded.AddListener (OnFollowAdded);
  33. FollowManager.GetInstance ().FollowDeleted.AddListener (OnFollowDeleted);
  34. OnVisibleChanged ();
  35. if (!ChatManager.GetInstance ().initialized)
  36. ChatManager.GetInstance ().Init ();
  37. }
  38. protected override void OnVisibleChanged ()
  39. {
  40. if(visible && FollowManager.GetInstance().initialized)
  41. {
  42. ListHelper.FillList<Follower> (container, FollowManager.GetInstance().GetFollowList(), itemPrefab);
  43. }
  44. }
  45. private void OnFollowAdded(int userId)
  46. {
  47. Follower follower = FollowManager.GetInstance ().GetFollower (userId);
  48. if(follower != null)
  49. {
  50. ListHelper.AddToList<Follower> (container, follower, itemPrefab);
  51. }
  52. }
  53. private void OnFollowDeleted(object follower)
  54. {
  55. ListHelper.Remove<Follower> (container, follower as Follower);
  56. }
  57. public void ShowFindFriendPanel()
  58. {
  59. ChatPanel.ShowFindFriend ();
  60. }
  61. }