| | |
| | | using System.Collections; |
| | | using System.Collections.Generic; |
| | | using System.Text.RegularExpressions; |
| | | using UnityEngine; |
| | | |
| | | public class ColorAnalysis : TRichAnalysis<ColorAnalysis> |
| | | { |
| | | public static Regex Color_Start_Regex = new Regex(@"<color=#([0-9a-zA-Z]+)>", RegexOptions.Singleline); |
| | | |
| | | public override string Analysis(string val, bool IsRich) |
| | | { |
| | | if (!Color_Start_Regex.IsMatch(val) || RichTextMgr.Inst.presentRichText == null) |
| | | { |
| | | return val; |
| | | } |
| | | int index = 0; |
| | | m_StringBuilder.Length = 0; |
| | | var _text = RichTextMgr.Inst.presentRichText; |
| | | if (_text.colorType == RichText.ColorType.Bright) |
| | | { |
| | | return val; |
| | | } |
| | | foreach (Match match in Color_Start_Regex.Matches(val)) |
| | | { |
| | | m_StringBuilder.Append(val.Substring(index, match.Groups[1].Index - index)); |
| | | m_StringBuilder.Append(GetColorMap(match.Groups[1].Value)); |
| | | index = match.Groups[1].Index + match.Groups[1].Length; |
| | | } |
| | | m_StringBuilder.Append(val.Substring(index, val.Length - index)); |
| | | return m_StringBuilder.ToString(); |
| | | } |
| | | |
| | | private string GetColorMap(string _value) |
| | | { |
| | | if (_value.Length > 6) |
| | | { |
| | | _value = _value.Substring(0, 6); |
| | | } |
| | | switch (_value.ToLower()) |
| | | { |
| | | case "109d06": |
| | | return "35e122"; |
| | | case "ff6701": |
| | | return "f8983b"; |
| | | case "006be3": |
| | | return "31cefb"; |
| | | case "ff0303": |
| | | return "fa0101"; |
| | | case "12a199": |
| | | return "13a199"; |
| | | case "686868": |
| | | return "f7f7f7"; |
| | | } |
| | | return _value; |
| | | } |
| | | |
| | | public override string CalculateTextIndex(string val, int index) |
| | | { |
| | | return string.Empty; |
| | | } |
| | | } |
| | | using System.Collections;
|
| | | using System.Collections.Generic;
|
| | | using System.Text.RegularExpressions;
|
| | | using UnityEngine;
|
| | |
|
| | | public class ColorAnalysis : TRichAnalysis<ColorAnalysis>
|
| | | {
|
| | | public static Regex Color_Start_Regex = new Regex(@"<color=#([0-9a-zA-Z]+)>", RegexOptions.Singleline);
|
| | |
|
| | | public override string Analysis(string val, bool IsRich)
|
| | | {
|
| | | if (!Color_Start_Regex.IsMatch(val) || RichTextMgr.Inst.presentRichText == null)
|
| | | {
|
| | | return val;
|
| | | }
|
| | | int index = 0;
|
| | | m_StringBuilder.Length = 0;
|
| | | var _text = RichTextMgr.Inst.presentRichText;
|
| | | if (_text.colorType == RichText.ColorType.Bright)
|
| | | {
|
| | | return val;
|
| | | }
|
| | | foreach (Match match in Color_Start_Regex.Matches(val))
|
| | | {
|
| | | m_StringBuilder.Append(val.Substring(index, match.Groups[1].Index - index));
|
| | | m_StringBuilder.Append(GetColorMap(match.Groups[1].Value));
|
| | | index = match.Groups[1].Index + match.Groups[1].Length;
|
| | | }
|
| | | m_StringBuilder.Append(val.Substring(index, val.Length - index));
|
| | | return m_StringBuilder.ToString();
|
| | | }
|
| | |
|
| | | private string GetColorMap(string _value)
|
| | | {
|
| | | if (_value.Length > 6)
|
| | | {
|
| | | _value = _value.Substring(0, 6);
|
| | | }
|
| | | switch (_value.ToLower())
|
| | | {
|
| | | case "109d06":
|
| | | return "35e122";
|
| | | case "ff6701":
|
| | | return "f8983b";
|
| | | case "006be3":
|
| | | return "31cefb";
|
| | | case "ff0303":
|
| | | return "fa0101";
|
| | | case "12a199":
|
| | | return "13a199";
|
| | | case "686868":
|
| | | return "f7f7f7";
|
| | | case "da48d5":
|
| | | return "ec4bf6";
|
| | | case "f6408d":
|
| | | return "ff7c7c";
|
| | | case "bb8800":
|
| | | return "ffde00";
|
| | | case "666666":
|
| | | return "dddddd";
|
| | | case "9460ff":
|
| | | return "7999ff";
|
| | | case "0066ff":
|
| | | return "00c6ff";
|
| | | case "00b337":
|
| | | return "66ff00";
|
| | | case "ff6600":
|
| | | return "ff9000";
|
| | | case "ff00f6":
|
| | | return "f000ff";
|
| | | }
|
| | | return _value;
|
| | | }
|
| | |
|
| | | public override string CalculateTextIndex(string val, int index)
|
| | | {
|
| | | return string.Empty;
|
| | | }
|
| | | }
|