Example #1
0
    /**
     * @brief NGUIのカラータグの文字数を返す
     * return カラータグの文字数 [FFAA00]=8 [-]=3 それ以外は0
     */
    static public int ParseSymbol(string text, int index, List <Color> colors, bool premultiply)
    {
        int length = text.Length;

        if (index + 2 < length)
        {
            if (text[index + 1] == '-')
            {
                if (text[index + 2] == ']')
                {
                    if (colors != null && colors.Count > 1)
                    {
                        colors.RemoveAt(colors.Count - 1);
                    }
                    return(3);
                }
            }
            else if (index + 7 < length)
            {
                if (text[index + 7] == ']')
                {
                    if (colors != null)
                    {
                        Color c = HexColor.ToColor(text.Substring(index + 1, 6));

                        if (HexColor.FormColorString(c).Substring(1, 6) != text.Substring(index + 1, 6))
                        {
                            return(0);
                        }

                        c.a = colors[colors.Count - 1].a;
                        if (premultiply && c.a != 1f)
                        {
                            c = Color.Lerp(ColorUtil.COLOR_INVISIBLE, c, c.a);
                        }

                        colors.Add(c);
                    }
                    return(8);
                }
            }
        }
        return(0);
    }
Example #2
0
 /// <summary>
 /// 色のタグを付加する
 /// </summary>
 /// <param name="str"></param>
 /// <param name="color"></param>
 /// <returns></returns>
 public static string ColorTag(this string str, Color color)
 {
     return(string.Format("<color={0}>{1}</color>", HexColor.FormColorString(color), str));
 }