private void SetRowInfo() { var bulletTextInfo = new BulletTextInfo() { SendTime = Time.realtimeSinceStartup, TextWidth = _textWidth }; var rowRoot = _displayer.GetRowRoot(bulletTextInfo); transform.SetParent(rowRoot, false); transform.localScale = Vector3.one; }
public Transform GetRowRoot(BulletTextInfo newTextInfo) { const int notFoundRowIndex = -1; int searchedRowIndex = notFoundRowIndex; newTextInfo.SendTime = Time.realtimeSinceStartup; 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; } 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. } 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); }