/// <summary> /// 添加聊天信息 /// </summary> /// <param name="textList"></param> private void OnAddText(IEnumerable <ChatInfo> textList) { var list = textList.TakeLast(MaxChatNum).ToList(); //TODO 移除超出的聊天 Log.LogGroup(GameDefine.LogGroup.User_ZCX, "TextList count " + list.Count); float totalheight = 0; Vector3[] corners = m_panel.worldCorners; for (int i = 0; i < 4; ++i) { Vector3 v = corners[i]; v = m_trans_ChatItemRoot.InverseTransformPoint(v); corners[i] = v; } // float extents = 0; int childNum = m_lstCurrChannel.Count; // for (int i = 0; i < childNum; i++) // { // SingleChatItem item = m_lstCurrChannel[i]; // if (item != null) // { // extents += item.GetHeight(); // } // } //缓存最后一个 用于判断是否可以刷新 SingleChatItem lastChatItem = null; if (childNum > 0) { lastChatItem = m_lstCurrChannel[childNum - 1]; } // extents *= 0.5f; Vector3 center = Vector3.Lerp(corners[0], corners[2], 0.5f); //bool allWithinRange = true; //float ext2 = extents * 2f; bool flag = false; SingleChatItem chatitem = null; for (int i = 0; i < list.Count; i++) { var item = list[i]; chatitem = AddChatItem(item, ref m_lstChatItem, m_chatItemPrefab); if (chatitem != null) { chatitem.m_parent = this; //float height = chatitem.GetHeight(); m_fTotalHeight += chatitem.GetHeight(); Engine.Utility.Log.LogGroup("ZCX", "m_fTotalHeight :{0}", m_fTotalHeight); Transform t = chatitem.transform; float distance = t.localPosition.y - center.y; float offsetY = chatitem.GetOffsetY() - distance - m_panel.baseClipRegion.w * 0.5f + m_panel.clipSoftness.y; if (offsetY > 0) { totalheight = offsetY; } m_lstCurrChannel.Add(chatitem); if (!flag && chatitem.m_chatdata != null && m_chatManager.IsCanAutoPlayVoice(chatitem.m_chatdata.Channel) && !chatitem.m_chatdata.played && !GVoiceManger.Instance.IsPlaying) { flag = true; chatitem.PlayeVoice(); } } } if (totalheight > 0) { //可以立即刷新 if (CheckCanUpdateMsg(lastChatItem, center.y)) { Engine.Utility.Log.LogGroup("ZCX", "MoveRelative :{0}", totalheight); m_scrollview_ChatScrollView.MoveRelative(new Vector3(0, totalheight, 0)); } else { m_fMoveTotalHeight = totalheight; m_noreadMsg += list.Count; UpdateNoReadMsgTips(m_noreadMsg); } } }