private void OnAddText(IEnumerable <ChatInfo> textList) { var list = textList.TakeLast(MaxChatNum).ToList(); Engine.Utility.Log.LogGroup("ZCX", "OnAddText : " + list.Count); if (list.Count <= 0) { return; } if (m_chatPanel == null) { //Engine.Utility.Log.Error("m_chatPanel为空!!!"); return; } Vector3[] corners = m_chatPanel.worldCorners; for (int i = 0; i < 4; ++i) { Vector3 v = corners[i]; v = m_trans_chatroot.InverseTransformPoint(v); corners[i] = v; } float totalheight = 0; Vector3 center = Vector3.Lerp(corners[0], corners[2], 0.5f); SingleChatItem chatitem = null; foreach (var item in list) { AddTimeTips(item.Timestamp); chatitem = AddChatItem(item, ref m_lstChatItem, m_chatItemPrefab); if (chatitem != null) { float height = chatitem.GetHeight(); m_fTotalHeight += chatitem.GetHeight(); Transform t = chatitem.transform; float distance = t.localPosition.y - center.y; float offsetY = chatitem.GetOffsetY() - distance - m_chatPanel.baseClipRegion.w * 0.5f + m_chatPanel.clipSoftness.y; if (offsetY > 0) { totalheight = offsetY; } m_lstCurrChannel.Add(chatitem); } } if (totalheight > 0) { m_chatScrollView.MoveRelative(new Vector3(0, totalheight, 0)); } }
bool CheckCanUpdateMsg(SingleChatItem chatitem, float centerY) { if (chatitem == null) { return(true); } float height = chatitem.GetHeight(); Transform t = chatitem.transform; float distance = t.localPosition.y - centerY; float offsetY = chatitem.GetOffsetY() - distance - m_chatPanel.baseClipRegion.w * 0.5f + m_chatPanel.clipSoftness.y; if (offsetY > height * 0.5f)//如果在panel外不能移动 { return(false); } return(true); }
/// <summary> /// 添加聊天信息 /// </summary> /// <param name="textList"></param> private void OnAddText(IEnumerable <ChatInfo> textList) { var list = textList.TakeLast(MaxChatNum).ToList(); //TODO 移除超出的聊天 float totalheight = 0; Vector3[] corners = m_chatPanel.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) { 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_chatPanel.baseClipRegion.w * 0.5f + m_chatPanel.clipSoftness.y; if (offsetY > 0) { totalheight = offsetY; } m_lstCurrChannel.Add(chatitem); } } 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)); } } if (null != m_scrollview_ChatScrollView) { NGUITools.MarkParentAsChanged(m_scrollview_ChatScrollView.gameObject); } }
/// <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); } } }