Ejemplo n.º 1
0
    private void SetRowInfo()
    {
        if (_textContent.Contains("2"))
        {
            return;
        }
        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 (textInfo == null)
            {
                searchedRowIndex = rowIndex;
                break;
            }
            float l1            = textInfo.TextWidth;
            float l2            = newTextInfo.TextWidth;
            float sentDeltaTime = newTextInfo.SendTime - textInfo.SendTime;

            var aheadTime = GetAheadTime(l1, 20);

            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);
    }