Exemplo n.º 1
0
    private void SetHandRowInfo()
    {
        if (_textContent.Contains("1"))
        {
            return;
        }

        var bulletHandTextInfo = new BulletHandTextInfo()
        {
            HandSendTime  = Time.realtimeSinceStartup,
            HandTextWidth = _textWidth
        };

        var rowRoot = _displayer.GetHandRowRoot(bulletHandTextInfo);

        transform.SetParent(rowRoot, false);
        transform.localScale = Vector3.one;
    }
    public Transform GetHandRowRoot(BulletHandTextInfo newTextInfo)
    {
        const int notFoundRowIndex = -1;
        int       searchedRowIndex = notFoundRowIndex;

        newTextInfo.HandSendTime = Time.realtimeSinceStartup;

        for (int rowIndex = 0; rowIndex < _currBulletHandTextInfoList.Length; rowIndex++)
        {
            var textInfo = _currBulletHandTextInfoList[rowIndex];
            //如果此行没有弹幕,直接创建新的
            if (textInfo == null)
            {
                searchedRowIndex = rowIndex;
                break;
            }
            float l1            = textInfo.HandTextWidth;
            float l2            = newTextInfo.HandTextWidth;
            float sentDeltaTime = newTextInfo.HandSendTime - textInfo.HandSendTime;

            var aheadTime = GetHandAheadTime(20, 11);

            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, _currBulletHandTextInfoList.Length);
            searchedRowIndex = repairRowIndex;
        }
        _currBulletHandTextInfoList[searchedRowIndex] = newTextInfo;
        Transform root = _info.HandScreenRoot.transform.Find(string.Format("row_{0}", searchedRowIndex));

        return(root);
    }