using UnityEngine; using UnityEngine.UI; using System.Collections; public class ChatView : View { public Text titleTxt; public Transform container; public ChatItem itemPrefab; private Follower follower; public FriendChatInput chatInput; protected override void OnDestroy () { base.OnDestroy (); if (follower != null) follower.OnMsgAdded.RemoveListener (OnAddMsg); } protected override void OnInitCompleted () { data = data; } public override object data { get { return base.data; } set { base.data = value; if(value == null || !initialized) { return; } int targetId = (int)value; chatInput.targetId = targetId; if (follower != null) follower.OnMsgAdded.RemoveListener (OnAddMsg); follower = FollowManager.GetInstance ().GetFollower (targetId); if (follower != null) { follower.OnMsgAdded.AddListener (OnAddMsg); ListHelper.FillList (container, follower.GetMsgList(), itemPrefab, ChatManager.MAX_FOLLOW); titleTxt.text = Language.GetStr ("ChatPanel", "chatWith").Replace("%NICK%", UserCache.GetNick(targetId)); } else { ListHelper.FillList (container, null, null); titleTxt.text = ""; } } } private void OnAddMsg(ChatMsg chatMsg) { ListHelper.AddToList (container, chatMsg, itemPrefab, ChatManager.MAX_FOLLOW); } public void ShowProfile() { if(data == null || !initialized) return; ProfilePanel.Show ((int)data); } }