Exemplo n.º 1
0
    void RecalculateText()
    {
        if (TextComponent == null)
        {
            TextComponent = this.transform.Find("Text").GetComponent <TMPro.TextMeshProUGUI>();
        }
        if (RectTransform == null)
        {
            RectTransform = GetComponent <RectTransform>();
        }
        TextComponent.text = Text;
        Vector3[] vertices;
        TextComponent.ForceMeshUpdate();
        float textWidth = TextComponent.preferredWidth + Padding * 2;

        this.RectTransform.sizeDelta = new Vector3(textWidth, this.RectTransform.sizeDelta.y, 0f);
        TextComponent.ForceMeshUpdate();

        TMP_TextInfo textInfo       = TextComponent.textInfo;
        int          characterCount = textInfo.characterCount;

        if (characterCount == 0)
        {
            return;
        }

        float boundsMinX = TextComponent.bounds.min.x - Padding;
        float boundsMaxX = TextComponent.bounds.max.x + Padding;

        float fullWidth = textWidth + Padding * 2;
        float angle     = Angle * 100 / textWidth;

        for (int i = 0; i < characterCount; i++)
        {
            if (!textInfo.characterInfo[i].isVisible)
            {
                continue;
            }

            int vertexIndex   = textInfo.characterInfo[i].vertexIndex;
            int materialIndex = textInfo.characterInfo[i].materialReferenceIndex;
            vertices = textInfo.meshInfo[materialIndex].vertices;

            Vector3 charMidBaselinePos = new Vector2((vertices[vertexIndex + 0].x + vertices[vertexIndex + 2].x) / 2, textInfo.characterInfo[i].baseLine);

            float zeroToOnePos = (charMidBaselinePos.x - boundsMinX) / (boundsMaxX - boundsMinX);

            var quat = Quaternion.AngleAxis((zeroToOnePos - 0.5f) * angle, new Vector3(0f, 0f, -1f));
            vertices[vertexIndex + 0] = quat * vertices[vertexIndex + 0];
            vertices[vertexIndex + 1] = quat * vertices[vertexIndex + 1];
            vertices[vertexIndex + 2] = quat * vertices[vertexIndex + 2];
            vertices[vertexIndex + 3] = quat * vertices[vertexIndex + 3];
        }

        TextComponent.UpdateVertexData();
        SetVerticesDirty();
        SetMaterialDirty();
    }
Exemplo n.º 2
0
    static int ForceMeshUpdate(IntPtr L)
    {
        try
        {
            int count = LuaDLL.lua_gettop(L);

            if (count == 1 && TypeChecker.CheckTypes(L, 1, typeof(TMPro.TextMeshProUGUI)))
            {
                TMPro.TextMeshProUGUI obj = (TMPro.TextMeshProUGUI)ToLua.ToObject(L, 1);
                obj.ForceMeshUpdate();
                return(0);
            }
            else if (count == 2 && TypeChecker.CheckTypes(L, 1, typeof(TMPro.TextMeshProUGUI), typeof(bool)))
            {
                TMPro.TextMeshProUGUI obj = (TMPro.TextMeshProUGUI)ToLua.ToObject(L, 1);
                bool arg0 = LuaDLL.lua_toboolean(L, 2);
                obj.ForceMeshUpdate(arg0);
                return(0);
            }
            else
            {
                return(LuaDLL.luaL_throw(L, "invalid arguments to method: TMPro.TextMeshProUGUI.ForceMeshUpdate"));
            }
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e));
        }
    }
    static int ForceMeshUpdate(IntPtr L)
    {
        try
        {
            int count = LuaDLL.lua_gettop(L);

            if (count == 1)
            {
                TMPro.TextMeshProUGUI obj = (TMPro.TextMeshProUGUI)ToLua.CheckObject <TMPro.TextMeshProUGUI>(L, 1);
                obj.ForceMeshUpdate();
                return(0);
            }
            else if (count == 2)
            {
                TMPro.TextMeshProUGUI obj = (TMPro.TextMeshProUGUI)ToLua.CheckObject <TMPro.TextMeshProUGUI>(L, 1);
                bool arg0 = LuaDLL.luaL_checkboolean(L, 2);
                obj.ForceMeshUpdate(arg0);
                return(0);
            }
            else
            {
                return(LuaDLL.luaL_throw(L, "invalid arguments to method: TMPro.TextMeshProUGUI.ForceMeshUpdate"));
            }
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e));
        }
    }
Exemplo n.º 4
0
    private IEnumerator AnimationCoroutine()
    {
        isAnimating = true;
        text.ForceMeshUpdate();

        var textInfo          = text.textInfo;
        var visibleCharacters = textInfo.characterCount;

        float time    = 0.0f;
        float maxTime = visibleCharacters * speedPerCharacter;

        while (time < maxTime)
        {
            text.maxVisibleCharacters = Mathf.FloorToInt(time / speedPerCharacter);
            yield return(null);

            time += Time.deltaTime;
        }
        text.maxVisibleCharacters = visibleCharacters;
        isAnimating = false;
        yield break;
    }