/// <summary> /// Sets the row info and init CombBulletTextInfo. /// </summary> private void SetRowInfo() { TextInfo = new CombBulletTextInfo() { SendTime = Time.realtimeSinceStartup, TextHeight = _textHeight, ImageWidth = _bodyImageWidth, ImageHeight = _bodyImageheight }; //目前只有图片一类非文本消息.... TextInfo.IsText = (null == _image); //找到对应行道的根节点row_{0},并且位置和父节点一致... var rowRoot = _displayer.GetRowRoot(this, out _timeGap); transform.SetParent(rowRoot, false); //大小不进行缩放》... transform.localScale = Vector3.one; }
/// <summary> /// Gets the row root.根据当前节点下是否有textinfo元素挂靠,没有的话就初始化一个.. /// 图片和视频居中... /// </summary> /// <returns>The row root.</returns> /// <param name="newTextInfo">New text info.</param> public Transform GetRowRoot(CombBulletTextInfo newTextInfo) { const int notFoundRowIndex = -1; int searchedRowIndex = notFoundRowIndex; //发送时间记为现在时间... newTextInfo.SendTime = Time.realtimeSinceStartup; // if (newTextInfo.IsText) { for (int rowIndex = 0; rowIndex < _currBulletTextInfoList.Length; rowIndex++) { var textInfo = _currBulletTextInfoList [rowIndex]; //if no bullet text info exist in this row, create the new directly. if (textInfo == null) { searchedRowIndex = rowIndex; break; } //没有空余节点就重复使用.... Debug.Log("textInfo.IsText:" + textInfo.IsText); Debug.Log("newTextInfo.IsText:" + newTextInfo.IsText); float l1 = (textInfo.IsText) ? textInfo.TextWidth : textInfo.ImageWidth; float l2 = (newTextInfo.IsText) ? newTextInfo.TextWidth : newTextInfo.ImageWidth; //float l1 = textInfo.TextWidth; //float l2 = newTextInfo.TextWidth; //发送时间间隔必须超过文本长度... float sentDeltaTime = newTextInfo.SendTime - textInfo.SendTime; var aheadTime = GetAheadTime(l1, l2); if (sentDeltaTime >= aheadTime) //fit and add. { searchedRowIndex = rowIndex; break; } //go on searching in next row. } } else { searchedRowIndex = _currBulletTextInfoList.Length / 2; if (_currBulletTextInfoList.Length > 6) { //手机图片有些太大了随机0-2.... int repairRowIndex = Random.Range(0, 3); searchedRowIndex = repairRowIndex; } } //找不到合适节点, 随机一个... if (searchedRowIndex == notFoundRowIndex) //no fit but random one row. { int repairRowIndex = Random.Range(0, _currBulletTextInfoList.Length); searchedRowIndex = repairRowIndex; } // _currBulletTextInfoList[searchedRowIndex] = newTextInfo; Transform root = _info.ScreenRoot.transform.Find(string.Format("row_{0}", searchedRowIndex)); return(root); }