Esempio n. 1
0
    /// <summary>
    /// Sets the color hidden. This will not change the values in inspector, but its more efficent for changing vertex colors
    /// </summary>
    /// <param name='_topColor'>
    /// _top color.
    /// </param>
    public void SetColor(Color _topColor, Color _bottomColor)
    {
        switch (_privateProperties.fillColorStyle)
        {
        case FILL_COLOR_STYLE.single:
            _bottomColor = _topColor;
            break;

        case FILL_COLOR_STYLE.gradient:
            //Defulat behaviour. Nothing to do here
            break;

        case FILL_COLOR_STYLE.textureGradient:
            _topColor    = Color.white;
            _bottomColor = Color.white;
            break;
        }
        _privateProperties.fontColorTop    = _topColor;
        _privateProperties.fontColorBottom = _bottomColor;

        if (colors == null || textMesh == null)
        {
            return;
        }

        if (Application.isEditor)
        {
            if (!Application.isPlaying && GUIChanged == false)
            {
                return;
            }
        }
        parsingList = ParsingText(_privateProperties.text, _topColor, _bottomColor);

        int initalVertex = GetInitialVertexToColorize(TEXT_COMPONENT.Main);

        for (int _arrayPosition = 0; _arrayPosition < parsingList.Length; _arrayPosition++)
        {
            CustomFontParsing parsing = parsingList[_arrayPosition];
            colors[_arrayPosition + initalVertex]     = parsing.ColorTop;
            colors[_arrayPosition + initalVertex + 1] = parsing.ColorTop;
            colors[_arrayPosition + initalVertex + 2] = parsing.ColorBottom;
            colors[_arrayPosition + initalVertex + 3] = parsing.ColorBottom;
            initalVertex += 3;
        }
        textMesh.colors = colors;
    }
Esempio n. 2
0
    /// <summary>
    /// Creates the characters.
    /// </summary>
    /// <param name="alignmentPass"></param>
    /// <param name="characterPosition"></param>
    /// <param name="_offset"></param>
    /// <param name="_textComponent"></param>
    void CreateCharacters(ref int alignmentPass, ref int characterPosition, Vector3 _offset, TEXT_COMPONENT _textComponent)
    {
        ResetHelperVariables();
        for (int i = 0; i < parsingList.Length; i++)
        {
            CustomFontParsing parsing     = parsingList[i];
            Color             topColor    = parsing.ColorTop;
            Color             bottomColor = parsing.ColorBottom;
            switch (_textComponent)
            {
            case TEXT_COMPONENT.Shadow: topColor = bottomColor = _privateProperties.shadowColor; break;

            case TEXT_COMPONENT.Outline: topColor = bottomColor = _privateProperties.outlineColor; break;
            }
            if (!CreateCharacter(parsing.Char, characterPosition, _offset, topColor, bottomColor, parsing.Style))
            {
                break;
            }
            characterPosition++;
        }
        SetAlignment(alignmentPass++, characterLength);
    }
Esempio n. 3
0
    /// <summary>
    /// Sets the font material.
    /// </summary>
    void SetFontMaterial()
    {
        if (!dontOverrideMaterials)
        {
            Material customMaterial = null;
            if (_privateProperties.customDetailMaterial != null)
            {
                customMaterial = _privateProperties.customDetailMaterial;
            }
            else if (_privateProperties.fillColorStyle == FILL_COLOR_STYLE.textureGradient && _privateProperties.fillMaterial != null)
            {
                customMaterial = _privateProperties.fillMaterial;
            }

            if (customMaterial != null)
            {
                if (customMaterial.mainTexture != _privateProperties.font.material.mainTexture) //Check if the assigned font texture is OK
                {
                    customMaterial.mainTexture = _privateProperties.font.material.mainTexture;
                }
                if (_privateProperties.enableShadow || _privateProperties.enableOutline)
                {
                    textRenderer.sharedMaterials = new Material[2] {
                        MainFontMaterial, customMaterial
                    }
                }
                ;
                else
                {
                    textRenderer.sharedMaterials = new Material[1] {
                        customMaterial
                    }
                };
            }
            else
            {
                textRenderer.sharedMaterials = new Material[1] {
                    MainFontMaterial
                }
            };
        }
    }

    /// <summary>
    /// 텍스트를 파싱합니다.
    /// _updateTexureInfo 가 true이면 Font.RequestCharactersInTexture도 함께 실행합니다.
    /// Parsing Font Style, Color, Characters.
    /// <b>Bold</b>
    /// <i>Italic</i>
    /// <bi>Bold and Italic</bi>
    /// <color=#FFFFFF>Color</color>
    /// <gradient=#FF0000,#FFFF00>Gradient</gradient>
    /// </summary>
    /// <param name="text"></param>
    /// <param name="_updateTexureInfo"></param>
    /// <returns></returns>
    CustomFontParsing[] ParsingText(string text, Color colorTop, Color colorBottom, FontStyle fontStyle = FontStyle.Normal)
    {
        text = text.Replace(System.Environment.NewLine, "\n");
        if (fontStyle == FontStyle.Normal)
        {
            fontStyle = _privateProperties.fontStyle;
        }

        List <CustomFontParsing> ret = new List <CustomFontParsing>();

        int index  = 0;
        int length = text.Length;

        if (_privateProperties.richText)
        {
            string outText;
            string outValue;
            while (index < length)
            {
                if (CustomRichText.findTextIndex(text, "b", ref index, out outText, out outValue))
                {
                    ret.AddRange(ParsingText(outText, colorTop, colorBottom, FontStyle.Bold));
                }
                else if (CustomRichText.findTextIndex(text, "i", ref index, out outText, out outValue))
                {
                    ret.AddRange(ParsingText(outText, colorTop, colorBottom, FontStyle.Italic));
                }
                else if (CustomRichText.findTextIndex(text, "bi", ref index, out outText, out outValue))
                {
                    ret.AddRange(ParsingText(outText, colorTop, colorBottom, FontStyle.BoldAndItalic));
                }
                // 컬러 체크.
                // check color
                else if (CustomRichText.findTextIndex(text, "color", ref index, out outText, out outValue))
                {
                    Color parsingColor = CustomRichText.ConvertColor(outValue);
                    ret.AddRange(ParsingText(outText, parsingColor, parsingColor, fontStyle));
                }
                // 그라데이션 체크.
                // check gradient
                else if (CustomRichText.findTextIndex(text, "gradient", ref index, out outText, out outValue))
                {
                    string[] split = outValue.Split(",".ToCharArray());
                    if (split.Length > 1)
                    {
                        Color parsingColorTop    = CustomRichText.ConvertColor(split[0]);
                        Color parsingColorBottom = CustomRichText.ConvertColor(split[1]);
                        ret.AddRange(ParsingText(outText, parsingColorTop, parsingColorBottom, fontStyle));
                    }
                }
                else
                {
                    ret.Add(new CustomFontParsing(text[index], colorTop, colorBottom, fontStyle));
                }
                index++;
            }
        }
        else
        {
            while (index < length)
            {
                ret.Add(new CustomFontParsing(text[index], colorTop, colorBottom, fontStyle));
                index++;
            }
        }
        AnalizeText(ret); //Check for special characters

        return(ret.ToArray());
    }

    /// <summary>
    /// 해당 폰트스타일의 텍스쳐를 업데이트 합니다.
    /// update Texture Font Sytle
    /// </summary>
    /// <param name="fontStyle"></param>
    void updateTextureInfo(FontStyle fontStyle)
    {
        List <char> requestList = new List <char>();

        for (int i = 0; i < parsingList.Length; i++)
        {
            CustomFontParsing parsing = parsingList[i];
            if (fontStyle == parsing.Style)
            {
                requestList.Add(parsing.Char);
            }
        }
        if (requestList.Count > 0)
        {
            _privateProperties.font.RequestCharactersInTexture(new string(requestList.ToArray()), _privateProperties.fontSize, fontStyle);
        }
    }

    void PixelPerfect(bool isRefreshMesh)
    {
        if (_privateProperties.usePixelPerfect)
        {
            Vector3 cameraScreenPoints  = getTextCamera().WorldToScreenPoint(new Vector3(0f, 0f, transform.position.z));
            Vector3 cameraScreenPoints2 = getTextCamera().WorldToScreenPoint(new Vector3(0f, _privateProperties.size, transform.position.z));
            float   px       = cameraScreenPoints2.y - cameraScreenPoints.y;
            float   maxScale = Mathf.Max(transform.lossyScale.x, transform.lossyScale.y);
            int     fontSize = Mathf.RoundToInt(px * maxScale);
            if (_privateProperties.fontSize != fontSize)
            {
                _privateProperties.fontSize = fontSize;
                if (isRefreshMesh)
                {
                    RefreshMesh(true);
                }
            }
        }
    }