// Start is called before the first frame update void Start() { //点击按钮 GetComponent <Button>().onClick.AddListener(OnClickMsg); //实例化聊天面板 chatControl = Instantiate(chatPanelPerfab.gameObject, UI_ChatPanelManagers.GetChatPanelInstance.GetComponent <RectTransform>().rect.size, Quaternion.identity).GetComponent <UI_ChatPanelControl>(); //设置父级 chatControl.transform.SetParent(UI_ChatPanelManagers.GetChatPanelInstance.transform); //传递好友信息 chatControl.friendInfo = friendinfo; //添加到聊天面板管理 UI_ChatPanelManagers.GetChatPanelInstance.AddChatPanel(friendinfo.friend_id, chatControl); //设置名字 GetComponentInChildren <Text>().text = friendinfo.friend_name.ToString(); //实例话消息 foreach (FriendInfo.Content content in friendinfo.chat_message) { if (content.type == 0) { chatControl.CreateMyselfMsgText(content.msg); } else { chatControl.CreateFriendMsgText(content.msg); } } }
/// <summary> /// 添加面板 /// </summary> /// <param name="id"></param> /// <param name="uI_ChatPanel"></param> public void AddChatPanel(int id, UI_ChatPanelControl uI_ChatPanel) { //不包含则添加 if (!ui_ChatPanels.ContainsValue(uI_ChatPanel)) { ui_ChatPanels.Add(id, uI_ChatPanel); } }