2017-01-16 12:12:37 am -08:00 •
Tóm tắt ngắn gọn: Sao chép đoạn mã và sử dụng bằng cách gõ
textToAddEmoji.Emojify(); winvip.club
|
|
<sprite=1><sprite=1><sprite=1>
|
|
using System.Linq;
public Dictionary<string,string> InitDict ()
{
emojiCodeJSONTextAsset = (TextAsset)Resources.Load(emojiCodeJSONPath, typeof(TextAsset));
deserializedEmojiCodeJSONObject = (Dictionary<string,object>)MiniJSON.Json.Deserialize(emojiCodeJSONTextAsset.text);
_reversedCodeEmojiDict = new Dictionary<string, string>();
List
foreach (string key in arrayOfAllKeys)
{
Dictionary<string,object> subDict = (Dictionary<string,object>)deserializedEmojiCodeJSONObject[key];
string code = (string)subDict["alpha_code"];
string unicodeKey = GetConvertedString(key);
_reversedCodeEmojiDict[code] = unicodeKey;
}
return _reversedCodeEmojiDict;
}
private static string GetConvertedString(string inputString) { char[] chars = { ‘-’ }; return string.Join(string.Empty, inputString.Split(chars).Select(hex => char.ConvertFromUtf32(Convert.ToInt32(hex, 16))).ToArray()); }
|
|
// Một RawImage cho mỗi emoji for (int j = 0; j < emojiReplacements.Count; j++) { int emojiIndex = emojiReplacements[j].pos; if (emojiIndex * 4 < textGen.verts.Count) { GameObject newRawImage = GameObject.Instantiate(this.rawImageToClone.gameObject); newRawImage.transform.SetParent(textToEdit.transform);
Vector2 locUpperLeft = new Vector2(textGen.verts[emojiIndex * 4].position.x, textGen.verts[emojiIndex * 4].position.y);
Vector2 locBottomRight = new Vector2(textGen.verts[emojiIndex * 4 + 2].position.x, textGen.verts[emojiIndex * 4 + 2].position.y);
Vector3 mid = (locUpperLeft + locBottomRight) / 2.0f;
Vector3 size = locBottomRight - locUpperLeft;
Rect inputRect = textToEdit.rectTransform.rect;
Vector2 textAnchorPivot = GetTextAnchorPivot(textToEdit.alignment);
Vector2 refPoint = Vector2.zero;
refPoint.x = (textAnchorPivot.x == 1 ? inputRect.xMax : inputRect.xMin);
refPoint.y = (textAnchorPivot.y == 0 ? inputRect.yMin : inputRect.yMax);
Vector2 roundingOffset = textToEdit.PixelAdjustPoint(refPoint) - refPoint;
IList<UIVertex> verts = textGen.verts;
FontData fontData = FontData.defaultFontData;
fontData.font = textToEdit.font;
float pixelsPerUnit = 0.0f;
var localCanvas = GameObject.Find("GameCanvas").GetComponent<Canvas>();
if (!localCanvas)
{
pixelsPerUnit = 1.0f;
}
else if (!textToEdit.font || textToEdit.font.dynamic)
{
pixelsPerUnit = localCanvas.scaleFactor;
}
else
{
pixelsPerUnit = textToEdit.font.fontSize / (float)fontData.fontSize;
}
float unitsPerPixel = 1 / pixelsPerUnit;
int vertCount = verts.Count - 4;
if (roundingOffset != Vector2.zero)
{
mid *= unitsPerPixel;
mid.x += roundingOffset.x;
mid.y += roundingOffset.y;
}
else
{
mid *= unitsPerPixel;
}
Debug.Log ("EMOJI mid X" + mid.x + " Y " + mid.y + " Z " + mid.z);
newRawImage.transform.localPosition = mid;
RawImage ri = newRawImage.GetComponent<RawImage>();
ri.uvRect = emojiRects[emojiReplacements[j].emoji];
ri.rectTransform.pivot = new Vector2(0.0f, 0.0f);
ri.rectTransform.localScale = Vector3.one;
ri.rectTransform.sizeDelta = Vector2.one * textToEdit.font.lineHeight * unitsPerPixel;
}
}
|
|
static public void Emojify (this UnityEngine.UI.Text self) { if (JZEmojiUITextManager.Instance.reversedCodeEmojiDict == null) { return; }
string currentCodeBasedString = self.text;
// Sử dụng regex để thay thế các alpha code bằng emoji Unicode tương ứng
Dictionary<string,string> map = (Dictionary<string,string>)JZEmojiUITextManager.Instance.reversedCodeEmojiDict;
var regex = new Regex(string.Join("|",map.Keys.ToArray()));
var newStr = regex.Replace(currentCodeBasedString, m => map[m.Value]);
// Thay thế các ký tự '\\' thành '\' để chuẩn hóa chuỗi Unicode
Regex regex1 = new Regex (@"\\U([0-9A-F]{4})", RegexOptions.IgnoreCase);
var newStrUnescape = regex1.Replace (newStr, match [99win club](/mas/9f90aa9d53b24c07.html) => ((char)int.Parse (match.Groups[1].Value,
NumberStyles.HexNumber)).ToString ());
JZEmojiUITextManager.Instance.StartCoroutine(JZEmojiUITextManager.Instance.SetUITextThatHasEmoji(self, newStrUnescape));
}
|
|
textToAddEmoji.Emojify();
|
|
Morning! Here is your new phone. :flag_us: You can reply to new messages by swiping cards to left or right. Different reply will lead to different impact on company valuation and staff happiness. Our goal is to hit $ 1 Billion valuation by the end of the year while keep our staff from leaving.
|
|