tk2dTextMesh.Commit C# (CSharp) Method

Commit() public method

Call commit after changing properties to commit the changes. This is deffered to a commit call as more than one operation may require rebuilding the buffers, eg. scaling and changing text. This will be wasteful if performed multiple times.
public Commit ( ) : void
return void
    public void Commit()
    {
        // Make sure instance is set up, might not be when calling from Awake.
        InitInstance();

        // make sure fonts dictionary is initialized properly before proceeding
        _fontInst.InitDictionary();

        // Can come in here without anything initalized when
        // instantiated in code
        if ((updateFlags & UpdateFlags.UpdateBuffers) != 0 || mesh == null)
        {
            Init();
        }
        else
        {
            if ((updateFlags & UpdateFlags.UpdateText) != 0)
            {
                FormatText();
                int target = FillTextData();
                for (int i = target; i < _maxChars; ++i)
                {
                    // was/is unnecessary to fill anything else
                    vertices[i * 4 + 0] = vertices[i * 4 + 1] = vertices[i * 4 + 2] = vertices[i * 4 + 3] = Vector3.zero;
                }

                mesh.vertices = vertices;
                mesh.uv = uvs;
                if (_fontInst.textureGradients)
                {
                    mesh.uv1 = uv2;
                }

                // comment this in for game if it becomes a problem
                mesh.RecalculateBounds();
            }

            if ((updateFlags & UpdateFlags.UpdateColors) != 0)
            {
                Color topColor = _color;
                Color bottomColor = _useGradient ? _color2 : _color;

                for (int i = 0; i < colors.Length; i += 4)
                {
                    colors[i + 0] = colors[i + 1] = topColor;
                    colors[i + 2] = colors[i + 3] = bottomColor;
                }
                mesh.colors = colors;
            }
        }

        updateFlags = UpdateFlags.UpdateNone;
    }

Usage Example

示例#1
0
    public void setPopupText(string text, Vector2 textGridPos)
    {
        _shouldHidePopupText = false;
        float textX = textGridPos.x;

        if (textX < 2)
        {
            textX = 2;
        }
        if (textX > 13)
        {
            textX = 13;
        }
        float textY = textGridPos.y + 1;

        _popupText.anchor = TextAnchor.LowerCenter;
        if (textY > Globals.ROOM_HEIGHT - 2)
        {
            textY             = textGridPos.y;
            _popupText.anchor = TextAnchor.UpperCenter;
        }
        Vector2 actualPos = toActualCoordinates(new Vector2(textX, textY));

        _popupText.transform.localPosition = new Vector3(actualPos.x, actualPos.y - Globals.CELL_SIZE / 2, _popupText.transform.localPosition.z);
        _popupText.text = text;
        _popupText.Commit();
        _popupText.gameObject.SetActive(true);
    }
All Usage Examples Of tk2dTextMesh::Commit