|
|
using UnityEngine;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine.UI;
|
|
using LuaInterface;
|
|
|
|
using System.Text.RegularExpressions;
|
|
using System.Text;
|
|
using UnityEngine.Events;
|
|
using UnityEngine.EventSystems;
|
|
namespace LuaFramework {
|
|
public class InlineSpriteManager : Manager
|
|
{
|
|
public SpriteAsset m_spriteAsset;
|
|
//private float sprite_width = 70f;
|
|
//private float sprite_height = 48f;
|
|
private float wRatio = 48f / 70f;
|
|
private float hRatio = 70f / 48f;
|
|
/// <summary>
|
|
/// 用正则取<#name>
|
|
/// </summary>
|
|
private static readonly Regex m_inputTagRegex =
|
|
new Regex(@"<#(.+?)>", RegexOptions.Singleline);
|
|
|
|
void Start()
|
|
{
|
|
if (m_spriteAsset == null)
|
|
{
|
|
m_spriteAsset = Resources.Load("asset/face_all") as SpriteAsset;
|
|
}
|
|
}
|
|
|
|
public void PackageInlineText(InlieText text, string content)
|
|
{
|
|
if (content.Trim() == null || content.Trim() == "")
|
|
return;
|
|
|
|
InlieText tempChatText = text;
|
|
|
|
#region 解析输入表情正则
|
|
string _TempInputText = "";
|
|
int _TempMatchIndex = 0;
|
|
bool matching_success = false;
|
|
foreach (Match match in m_inputTagRegex.Matches(content.Trim()))
|
|
{
|
|
for (int i = 0; i < m_spriteAsset.listSpriteInfor.Count; i++)
|
|
{
|
|
if (m_spriteAsset.listSpriteInfor[i].name == match.Groups[1].Value)
|
|
{
|
|
matching_success = true;
|
|
break;
|
|
}
|
|
}
|
|
if (matching_success == true)
|
|
{
|
|
_TempInputText += content.Trim().Substring(_TempMatchIndex, match.Index - _TempMatchIndex);
|
|
_TempInputText += "<quad name=" + match.Groups[1].Value + " size=25 width=" + hRatio + " height=" + 1 + " />";
|
|
_TempMatchIndex = match.Index + match.Length;
|
|
matching_success = false;
|
|
}
|
|
|
|
}
|
|
_TempInputText += content.Trim().Substring(_TempMatchIndex, content.Trim().Length - _TempMatchIndex);
|
|
#endregion
|
|
|
|
|
|
tempChatText.text = tempChatText.GetOutputText(_TempInputText);
|
|
tempChatText.SetVerticesDirty();
|
|
}
|
|
}
|
|
}
|