Esempio n. 1
0
    private void TextSize(NPCData data)
    {
        if (data.currentConv[data.currentText].visable)
        {
            Transform parent = data.text.transform.parent;
            parent.GetComponent <CanvasGroup>().alpha = 1;
            Sprite sprite = data.currentConv[data.currentText].textBackground;
            parent.GetComponent <Image>().sprite = sprite != null ? sprite : defaultBackground;
        }
        else
        {
            data.text.transform.parent.GetComponent <CanvasGroup>().alpha = 0;
            return;
        }
        Vector2 boxSize = textPrefab.transform.GetChild(0).GetComponent <RectTransform>().sizeDelta;
        float   width   = data.currentConv[data.currentText].size.x;

        if (width != 0)
        {
            boxSize.x = width;
        }
        if (data.currentConv[data.currentText].size.y != 0)
        {
            boxSize.y = data.currentConv[data.currentText].size.y;
        }
        data.text.rectTransform.sizeDelta = boxSize;
        //data.text.transform.parent.GetComponent<RectTransform>().sizeDelta = new Vector2(boxSize.x / 125, boxSize.y / 100);               //Temp removed to fix speechBubble size

        Vector3 pos        = data.originalPos;
        Vector2 textOffset = data.currentConv[data.currentText].offset;

        pos.x += data.offset.x + textOffset.x;
        pos.y += (data.GetComponent <CapsuleCollider2D>().size.y + data.GetComponent <CapsuleCollider2D>().offset.y) + data.offset.y + textOffset.y;
        pos.z  = -4;
        data.text.transform.parent.position = pos;

        int fontSize = data.fontSize > 0 ? data.fontSize : 64;

        data.text.text     = data.currentConv[data.currentText].text;
        data.text.fontSize = fontSize;
        float height     = data.text.rectTransform.rect.height;
        float prefHeight = data.text.preferredHeight;
        int   times      = 0;

        while (prefHeight > height)
        {
            data.text.fontSize = data.text.fontSize - 8;
            prefHeight         = data.text.preferredHeight;

            times++;
            if (times > 10)
            {
                data.text.fontSize = 8;
                break;
            }
        }
        data.text.text = "";

        if (data.currentConv[data.currentText].shake)
        {
            data.shake();
        }

        data.setMoodAnimation(data.currentConv[data.currentText].mood);
    }