public void Init(BulletScreenManager manager)
    {
        _manager = manager;

        _lineMax          = (int)(_manager.UsedScreenHeight / _manager.LineHeight);
        _lineArray        = new LineInfo[_lineMax];
        _lineElementArray = new List <BulletScreenTextElement> [_lineMax];

        for (int i = 0; i < _lineMax; i++)
        {
            LineInfo line = new LineInfo();
            line.borderPostion = _manager.ScreenWidth;
            line.lastSpeed     = _speedMax;
            line.movingCount   = 0;
            line.informedCount = 0;
            List <BulletScreenTextElement> lineElements = new List <BulletScreenTextElement>();
            for (int j = 0; j < _manager.LineMaxElement; j++)
            {
                BulletScreenTextElement bullet =
                    _manager.AddBulletScreenTextElement(new Vector2(_manager.ScreenWidth, -_manager.LineHeight * i), i);
                lineElements.Add(bullet);
            }
            _lineElementArray[i] = lineElements;
            _lineArray[i]        = line;
        }
    }
Example #2
0
    public static BulletScreenTextElement Create(BulletScreenDisplayer displayer, string textContent,
                                                 bool showBox = false,
                                                 ScrollDirection direction = ScrollDirection.RightToLeft)
    {
        BulletScreenTextElement instance = null;

        if (displayer == null)
        {
            Debug.Log("BulletScreenTextElement.Create(), displayer can not be null !");
            return(null);
        }

        if (textContent.Contains("1"))
        {
            // Debug.Log("ddd2222");
            GameObject go = Instantiate(displayer.TextElementPrefab) as GameObject;
            go.transform.SetParent(displayer.GetTempRoot());
            go.transform.localPosition = Vector3.up * 10000F;
            go.transform.localScale    = Vector3.one;
            instance              = go.AddComponent <BulletScreenTextElement>();
            instance._displayer   = displayer;
            instance._textContent = textContent;
            // instance._showBox = showBox;
            instance._showBox = true;

            //限制方向
            //instance._scrollDirection = direction;
            instance._scrollDirection = ScrollDirection.RightToLeft;
        }
        else if (textContent.Contains("2"))
        {
            //Debug.Log("ddd");
            GameObject go = Instantiate(displayer.HandElementPrefab) as GameObject;
            go.transform.SetParent(displayer.GetTempHandRoot());
            go.transform.localPosition = Vector3.up * 10000F;
            go.transform.localScale    = Vector3.one;
            instance              = go.AddComponent <BulletScreenTextElement>();
            instance._displayer   = displayer;
            instance._textContent = textContent;

            instance._showBox = showBox;
            instance._showBox = true;

            //限制方向
            instance._scrollDirection = direction;
            instance._scrollDirection = ScrollDirection.RightToLeft;
        }

        return(instance);
    }
Example #3
0
    private void InitBulletScreenTextElement()
    {
        if (_textElement == null)
        {
            Debug.LogWarning("弹幕元素为空");
            return;
        }
        //初始化Text组件
        _text = _textElement.GetComponent <Text>();
        if (_text == null)
        {
            Debug.LogWarning("弹幕元素未添加Text组件");
            return;
        }
        _text.rectTransform.pivot     = new Vector2(0, 1);
        _text.rectTransform.anchorMin = new Vector2(0f, 1f);
        _text.rectTransform.anchorMax = new Vector2(0f, 1f);
        _text.fontSize = _fontSize;
        //初始化ContentSizeFitter组件
        ContentSizeFitter fitter = _textElement.GetComponent <ContentSizeFitter>();

        if (fitter == null)
        {
            fitter = _textElement.AddComponent <ContentSizeFitter>();
        }
        fitter.horizontalFit = ContentSizeFitter.FitMode.PreferredSize;
        fitter.verticalFit   = ContentSizeFitter.FitMode.PreferredSize;
        //初始化BulletScreenTextElement组件
        BulletScreenTextElement bSTElement = _textElement.GetComponent <BulletScreenTextElement>();

        if (bSTElement == null)
        {
            _textElement.AddComponent <BulletScreenTextElement>();
        }
        _textElement.transform.SetParent(transform);
        _textElement.transform.localScale = Vector3.one;
        //获取文本高度
        StartCoroutine(GetTextElementHeight());
    }
Example #4
0
    public BulletScreenTextElement AddBulletScreenTextElement(Vector2 position, int lineIndex)
    {
        //创建TextGameObject
        GameObject newTextElement = Instantiate(_textElement) as GameObject;

        newTextElement.transform.SetParent(transform);
        newTextElement.transform.localScale = Vector3.one;
        newTextElement.SetActive(false);

        Text text = newTextElement.GetComponent <Text>();

        text.rectTransform.anchoredPosition = new Vector2(position.x, position.y);
        text.text = "";
        //设置弹幕运行的相关属性
        BulletScreenTextElement bullet = newTextElement.GetComponent <BulletScreenTextElement>();

        bullet.startPos  = position;
        bullet.lineIndex = lineIndex;
        bullet.Init();
        //弹幕开始运动
        return(bullet);
    }
 public void AddBullet(string textContent, bool showBox = false, ScrollDirection direction = ScrollDirection.RightToLeft)
 {
     // Debug.Log(textContent);
     BulletScreenTextElement.Create(this, textContent, showBox, direction);
 }