源战役客户端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

71 lines
2.4 KiB

  1. 
  2. using UnityEngine;
  3. using System.Collections;
  4. using System.Collections.Generic;
  5. using UnityEngine.UI;
  6. using LuaInterface;
  7. using System.Text.RegularExpressions;
  8. using System.Text;
  9. using UnityEngine.Events;
  10. using UnityEngine.EventSystems;
  11. namespace LuaFramework {
  12. public class InlineSpriteManager : Manager
  13. {
  14. public SpriteAsset m_spriteAsset;
  15. //private float sprite_width = 70f;
  16. //private float sprite_height = 48f;
  17. private float wRatio = 48f / 70f;
  18. private float hRatio = 70f / 48f;
  19. /// <summary>
  20. /// 用正则取<#name>
  21. /// </summary>
  22. private static readonly Regex m_inputTagRegex =
  23. new Regex(@"<#(.+?)>", RegexOptions.Singleline);
  24. void Start()
  25. {
  26. if (m_spriteAsset == null)
  27. {
  28. m_spriteAsset = Resources.Load("asset/face_all") as SpriteAsset;
  29. }
  30. }
  31. public void PackageInlineText(InlieText text, string content)
  32. {
  33. if (content.Trim() == null || content.Trim() == "")
  34. return;
  35. InlieText tempChatText = text;
  36. #region 解析输入表情正则
  37. string _TempInputText = "";
  38. int _TempMatchIndex = 0;
  39. bool matching_success = false;
  40. foreach (Match match in m_inputTagRegex.Matches(content.Trim()))
  41. {
  42. for (int i = 0; i < m_spriteAsset.listSpriteInfor.Count; i++)
  43. {
  44. if (m_spriteAsset.listSpriteInfor[i].name == match.Groups[1].Value)
  45. {
  46. matching_success = true;
  47. break;
  48. }
  49. }
  50. if (matching_success == true)
  51. {
  52. _TempInputText += content.Trim().Substring(_TempMatchIndex, match.Index - _TempMatchIndex);
  53. _TempInputText += "<quad name=" + match.Groups[1].Value + " size=25 width=" + hRatio + " height=" + 1 + " />";
  54. _TempMatchIndex = match.Index + match.Length;
  55. matching_success = false;
  56. }
  57. }
  58. _TempInputText += content.Trim().Substring(_TempMatchIndex, content.Trim().Length - _TempMatchIndex);
  59. #endregion
  60. tempChatText.text = tempChatText.GetOutputText(_TempInputText);
  61. tempChatText.SetVerticesDirty();
  62. }
  63. }
  64. }