/// <summary> /// Unityのリッチテキストフォーマットのテキストを取得 /// </summary> /// <param name="index">文字の先頭インデックス</param> /// <param name="count">文字数</param> /// <returns>Unityのリッチテキストフォーマットのテキスト</returns> public string ToUnityRitchText(int index, int count) { int max = Mathf.Min(index + count, CharList.Count); string str = ""; Color lastColor = defaultColor; for (int i = index; i < max; ++i) { CharData c = CharList[i]; if (c.Color != lastColor) { if (lastColor != defaultColor) { str += "</color>"; } if (c.Color != defaultColor) { str += "<color=#" + ColorUtil.ToColorString(c.Color) + ">"; } } str += CharList[i].Char; lastColor = c.Color; } if (lastColor != defaultColor) { str += "</color>"; } return(str); }
/// <summary> /// 文字列の前後にカラーのリッチテキストタグを追加 /// </summary> /// <param name="str">文字列</param> /// <param name="colorKey">タグに設定するカラー</param> /// <returns></returns> public static string AddColorTag(string str, Color color) { return(AddColorTag(str, "#" + ColorUtil.ToColorString(color))); }