示例#1
0
    //修改文本
    private void changeTextStyle()
    {
        MTextFormatData data = TextFormatDefine.GetFormat(style);

        text.color          = data.color;
        text.fontSize       = data.fontSize;
        outline.enabled     = data.isOutline;
        outline.effectColor = data.effectColor;
        EditorUtility.SetDirty(outline);
        EditorUtility.SetDirty(text);
    }
示例#2
0
    //刷新文本显示 并保存
    private static void rushText(Transform item, string style, string textKey)
    {
        UnityEngine.UI.Text txt     = item.GetComponentInChildren <UnityEngine.UI.Text>();
        Outline             outline = item.GetComponentInChildren <Outline>();

        txt.text = LocalString.GetWord(textKey);
        MTextFormatData data = TextFormatDefine.GetFormat(style);

        txt.color           = data.color;
        txt.fontSize        = data.fontSize;
        outline.enabled     = data.isOutline;
        outline.effectColor = data.effectColor;
        EditorUtility.SetDirty(outline);
        EditorUtility.SetDirty(txt);
    }
示例#3
0
    //获取文本格式
    public static MTextFormatData GetFormat(string strFormat)
    {
        if (colorDic == null)
        {
            initColorDic();
        }

        MTextFormatData data = new MTextFormatData();

        Regex reg = new Regex("C[0-9]+");
        //返回一个结果集
        MatchCollection result     = reg.Matches(strFormat);
        bool            isStandard = true;

        //是否符合规则颜色
        if (result.Count > 0 && result.Count <= 2)
        {
            foreach (Match m in result)
            {
                if (!colorDic.ContainsKey(m.ToString()))
                {
                    isStandard = false;
                }
            }
        }
        else
        {
            isStandard = false;
        }
        if (strFormat == "" || !isStandard)
        {
            data.color       = defColor;
            data.fontSize    = defSize;
            data.isOutline   = false;
            data.effectColor = defColor;
        }
        else
        {
            data.color = colorDic[result[0].ToString()];
            if (result.Count == 2)
            {
                data.isOutline   = true;
                data.effectColor = colorDic[result[1].ToString()];
            }
            else
            {
                data.isOutline   = false;
                data.effectColor = defColor;
            }
            int   fontSize = defSize;
            Regex regF     = new Regex("F[0-9]+");
            Regex regNum   = new Regex("[0-9]+");
            Match resultF  = regF.Match(strFormat, 0);
            if (resultF.Success)
            {
                Match resultNum = regNum.Match(resultF.ToString(), 0);
                if (resultNum.Success)
                {
                    fontSize = System.Convert.ToInt32(resultNum.ToString());
                }
            }
            data.fontSize = fontSize;
        }

        return(data);
    }