| using System.Collections; | 
| using System.Collections.Generic; | 
| using UnityEngine; | 
|   | 
| public class RichTextMgr { | 
|   | 
|     private static RichTextMgr _inst = null; | 
|     public static RichTextMgr Inst { | 
|         get { | 
|             if (_inst == null) { | 
|                 _inst = new RichTextMgr(); | 
|                 _inst.Init(); | 
|             } | 
|             return _inst; | 
|         } | 
|     } | 
|   | 
|     private void Init() | 
|     { | 
|         // new RichMoveEvent(); | 
|         new RichTableEvent(); | 
|         new RichNormalEvent(); | 
|         // new RichFbEvent(); | 
|         new RichShowPlayerEvent(); | 
|     } | 
|   | 
|     public RichText presentRichText = null; | 
|     /// <summary> | 
|     /// Text 富文本解析 | 
|     /// </summary> | 
|     /// <param name="_text"></param> | 
|     /// <returns></returns> | 
|     public string Analysis(string _text,out List<ImgInfo> imgList,out List<HrefInfo> hrefList,RichText text=null) | 
|     { | 
|         imgList = new List<ImgInfo>(); | 
|         m_ImgInfoList = imgList; | 
|         hrefList = new List<HrefInfo>(); | 
|         m_HrefInfoList = hrefList; | 
|   | 
|         presentRichText = text; | 
|   | 
|         string result=GetAnalysis(_text); | 
|         //for (int i = 0; i < m_ImgInfoList.Count; i++) { | 
|             ImgAnalysis.Inst.CalculateTextIndex(result, 0); | 
|         //} | 
|         return result; | 
|     } | 
|   | 
|     public string Analysis(string val) | 
|     { | 
|         m_HrefInfoList = null; | 
|         m_ImgInfoList = null; | 
|   | 
|         return GetAnalysis(val); | 
|     } | 
|   | 
|     private string GetAnalysis(string val) | 
|     { | 
|         string result = ImgAnalysis.ReplaceFace(val); | 
|         try | 
|         { | 
|             result = ColorAnalysis.Inst.Analysis(result, true); | 
|             result = WordAnalysis.Inst.ReplaceSpace(result); | 
|             result = ImgAnalysis.Inst.Analysis(result, true); | 
|             result = WordAnalysis.Inst.Analysis(result, true); | 
|             result = HrefAnalysis.Inst.Analysis(result, true); | 
|             result = SuitNameAnalysis.Inst.Analysis(result, true); | 
|             result = HrefAnalysis.Inst.CalculateTextIndex(result, 0); | 
|         } | 
|         catch (System.Exception e) | 
|         { | 
|             Debug.LogError(e.Message+e.StackTrace); | 
|         } | 
|         return result; | 
|     } | 
|   | 
|     public class HrefInfo | 
|     { | 
|         public int start = 0; | 
|   | 
|         public int end = 0; | 
|   | 
|         public List<Rect> boxs=new List<Rect>(); | 
|         public List<int> lines = new List<int>(); | 
|   | 
|         public Dictionary<string, string> mSplits = new Dictionary<string, string>(); | 
|   | 
|         public List<RichTextEventEnum> mEvents = new List<RichTextEventEnum>(); | 
|   | 
|         public int start_cache_cnt = 0; | 
|         public int end_cache_cnt = 0; | 
|   | 
|         public bool unline = true; | 
|   | 
|         public Color unlineColor = Color.green; | 
|   | 
|         public bool fromAutoTask = false; | 
|   | 
|         public void Add(string key,string value) | 
|         { | 
|             if (!mSplits.ContainsKey(key)) { | 
|                 mSplits.Add(key, value); | 
|                 return; | 
|             } | 
|             mSplits[key] = value; | 
|         } | 
|   | 
|         public bool Execute(int index = 0) | 
|         { | 
|             if (mEvents.Count < 1) return false; | 
|             return RichTextMgr.Inst.ExecuteEvent(mEvents[index], this); | 
|         } | 
|     } | 
|   | 
|     public class ImgInfo | 
|     { | 
|         public float width; | 
|         public float height; | 
|         public int end; | 
|         public int index; | 
|         public int cacheCnt; | 
|   | 
|         public Sprite sprite; | 
|         public string spriteName; | 
|         public bool IsFace; | 
|         public float scale; //缩放图片的同时,二次缩放了图片在文本钟的占位大小,查看函数InverseToRichText | 
|   | 
|         public HrefInfo href = null; | 
|     } | 
|   | 
|     private List<ImgInfo> m_ImgInfoList; | 
|     public List<ImgInfo> GetImgList() | 
|     { | 
|         return m_ImgInfoList; | 
|     } | 
|   | 
|     private List<HrefInfo> m_HrefInfoList; | 
|     public List<HrefInfo> GetHrefList() | 
|     { | 
|         return m_HrefInfoList; | 
|     } | 
|   | 
|   | 
|     #region 富文本事件 | 
|     private static Dictionary<RichTextEventEnum, TRichTextEvent> m_RichEvents = new Dictionary<RichTextEventEnum, TRichTextEvent>(); | 
|     public void RegisterEvent(RichTextEventEnum type,TRichTextEvent evt) | 
|     { | 
|         if (!m_RichEvents.ContainsKey(type)) { | 
|             m_RichEvents.Add(type, evt); | 
|         } | 
|     } | 
|   | 
|     public bool ExecuteEvent(RichTextEventEnum type,HrefInfo href) | 
|     { | 
|         return m_RichEvents[type].Execute(type,href); | 
|     } | 
|   | 
|     public string GetDisplay(RichTextEventEnum type,Dictionary<string,string> dic) | 
|     { | 
|         return m_RichEvents[type].GetDisplay(type, dic); | 
|     } | 
|     #endregion | 
| } |