public void Event_reqUpdateFriendChatting(ulong dbid, string message) { Debug.Log("新接收的消息来自 : " + dbid + " 内容为 : " + message); List <string> list = MainInfoData.GetInstance().GetAllRecordsWithDBID(dbid); string mess_name = MainInfoData.GetInstance().GetChattingNameToDBID(dbid); message = mess_name + ": " + message; list.Add(message); MainInfoData.GetInstance().SetAllRecordsWithDBID(dbid, list); //来消息提示 if (cur_chattingDBID != dbid) { foreach (Transform child in friendListTr) { if (child.Find("Name").GetComponent <Text>().text == mess_name) { child.Find("ChattingTips").gameObject.SetActive(true); break; } } } else { UpdateChattingRecords(dbid); } }
public void Event_reqChangeNameCall(string callStr) { string tips; if (callStr == "success") { tips = "命名成功"; Debug.Log(tips); TipsOperation.ShowTips(tips); MainInfoData.GetInstance().Name = (KBEngineApp.app.player() as Account).Name; MainInfoData.GetInstance().UpdateOnceData(); CreateNameGO.SetActive(false); } else if (callStr == "repetition") { tips = "该名字已拥有, 请重新输入"; TipsOperation.ShowTips(tips); Debug.Log(tips); } else { tips = "未知错误 : " + callStr; TipsOperation.ShowTips(tips); Debug.LogError(tips); } }
//创建匹配房间 public void CreateMatchRoom() { Account account = KBEngineApp.app.player() as Account; account.baseCall("reqCreateMatchRoom"); MainInfoData.GetInstance().InRoom = true; }
//接受邀请 public void AcceptEnterRoom() { Account account = KBEngineApp.app.player() as Account; account.baseCall("reqEnterMatchRoom", reqID, reqName); reqMessageGO.SetActive(false); MainInfoData.GetInstance().InRoom = true; }
private void OnEnable() { Transform reqEnterTr = transform.Find("Main/ReqEnter"); Transform loogInfo = transform.Find("Main/LookInfo"); if (MainInfoData.GetInstance().InRoom) { reqEnterTr.GetComponent <Image>().color = Color.white; reqEnterTr.GetComponent <Button>().interactable = true; } else { reqEnterTr.GetComponent <Image>().color = Color.gray; reqEnterTr.GetComponent <Button>().interactable = false; } }
//点击好友单元 public void ClickFriendCell(GameObject go) { Account account = KBEngineApp.app.player() as Account; ulong dbid = account.Friend_list[int.Parse(go.name)].dbid; cur_chattingDBID = dbid; string needName = account.Friend_list[int.Parse(go.name)].name; Debug.Log("选择玩家 : " + needName); MainInfoData.GetInstance().SetChattingNameToDBID(dbid, needName); go.transform.Find("ChattingTips").gameObject.SetActive(false); //加载所有记录 if (!chattingGO.activeSelf) { chattingGO.SetActive(true); } UpdateChattingRecords(cur_chattingDBID); }
//发送聊天信息给客户端 public void SendChattingRecordsToFriend(InputField inputField) { string message = inputField.text; if (message == "") { Debug.Log("未输入内容"); return; } List <string> list = MainInfoData.GetInstance().GetAllRecordsWithDBID(cur_chattingDBID); list.Add("自己: " + message); MainInfoData.GetInstance().SetAllRecordsWithDBID(cur_chattingDBID, list); Account account = KBEngineApp.app.player() as Account; account.baseCall("sendChattingMessage", cur_chattingDBID, message); inputField.text = ""; UpdateChattingRecords(cur_chattingDBID); }
//刷新聊天记录 void UpdateChattingRecords(ulong dbid) { Transform content = chattingGO.transform.Find("ChattingRecords/Viewport/Content"); Transform childExample = content.Find("Example"); List <string> list = MainInfoData.GetInstance().GetAllRecordsWithDBID(dbid); int listCount = list.Count; for (int i = 0; i < listCount; i++) { Transform needTr = content.Find(i + ""); Color color; if (list[i].Split(':')[0] == "自己") { color = Color.red; } else { color = Color.white; } if (needTr) { needTr.Find("Text").GetComponent <Text>().text = list[i]; if (!needTr.gameObject.activeSelf) { needTr.gameObject.SetActive(true); } } else { needTr = Instantiate(childExample); needTr.SetParent(content); needTr.name = i.ToString(); needTr.Find("Text").GetComponent <Text>().text = list[i]; needTr.gameObject.SetActive(true); } needTr.GetComponent <Image>().color = color; //聊天框自适应文字 needTr.Find("Text").GetComponent <ContentSizeFitter>().SetLayoutVertical(); Vector2 size = needTr.transform.GetComponent <RectTransform>().sizeDelta; size.y = needTr.Find("Text").GetComponent <RectTransform>().sizeDelta.y + 10; needTr.transform.GetComponent <RectTransform>().sizeDelta = size; } //隐藏剩余聊天框 int num = content.childCount - listCount - 1; for (int i = 0; i < num; i++) { content.Find((i + listCount).ToString()).gameObject.SetActive(false); } //强制刷新UI属性 LayoutRebuilder.ForceRebuildLayoutImmediate(content.GetComponent <RectTransform>()); //每次设置最底部 ScrollRect scrollRect = chattingGO.transform.Find("ChattingRecords").GetComponent <ScrollRect>(); scrollRect.verticalNormalizedPosition = 0; }
private void OriginalSetting(Account account) { MainInfoData.GetInstance().Name = account.Name; MainInfoData.GetInstance().HeadIcon = null; MainInfoData.GetInstance().UpdateOnceData(); }
private void OnDestroy() { MainInfoData.GetInstance().UpdateData -= UpdateName; MainInfoData.GetInstance().UpdateData -= UpdateHeadIcon; }
public void UpdateHeadIcon() { headIcon.sprite = MainInfoData.GetInstance().HeadIcon; }
public void UpdateName() { nameText.text = MainInfoData.GetInstance().Name; }
private void Awake() { MainInfoData.GetInstance().UpdateData += UpdateName; MainInfoData.GetInstance().UpdateData += UpdateHeadIcon; }