using UnityEngine; using UnityEngine.UI; using System.Collections; public class ChatBarChatView : View { public Text findFriendBtnLabel; public Transform container; public ChatBarChatItem itemPrefab; protected override void OnInitCompleted () { findFriendBtnLabel.text = Language.GetStr ("ChatPanel", "findMorePlayer"); if (!FollowManager.GetInstance ().initialized) { ListHelper.HideAll (container); FollowManager.GetInstance ().InitCompletion.AddListener (OnFollowersInit); FollowManager.GetInstance ().Init (); } else { OnFollowersInit (); } } protected override void OnDestroy () { base.OnDestroy (); FollowManager.GetInstance ().InitCompletion.RemoveListener (OnFollowersInit); FollowManager.GetInstance ().FollowAdded.RemoveListener (OnFollowAdded); FollowManager.GetInstance ().FollowDeleted.RemoveListener (OnFollowDeleted); } private void OnFollowersInit() { FollowManager.GetInstance ().InitCompletion.RemoveListener (OnFollowersInit); FollowManager.GetInstance ().FollowAdded.AddListener (OnFollowAdded); FollowManager.GetInstance ().FollowDeleted.AddListener (OnFollowDeleted); OnVisibleChanged (); if (!ChatManager.GetInstance ().initialized) ChatManager.GetInstance ().Init (); } protected override void OnVisibleChanged () { if(visible && FollowManager.GetInstance().initialized) { ListHelper.FillList (container, FollowManager.GetInstance().GetFollowList(), itemPrefab); } } private void OnFollowAdded(int userId) { Follower follower = FollowManager.GetInstance ().GetFollower (userId); if(follower != null) { ListHelper.AddToList (container, follower, itemPrefab); } } private void OnFollowDeleted(object follower) { ListHelper.Remove (container, follower as Follower); } public void ShowFindFriendPanel() { ChatPanel.ShowFindFriend (); } }