Ejemplo n.º 1
0
        public static IEnumerator ProcessAsync(string text)
        {
            didProcessAsync = false;
            if (rootEmojiAsset == null)
            {
                yield break;
            }

            if (string.IsNullOrEmpty(text))
            {
                yield break;
            }

            List <string> detectedEmojis = new List <string>();

            string emojiText = null;

            while ((emojiText = EmojiTexture.GetFirstEmoji(text)) != null)
            {
                text = text.Substring(text.IndexOf(emojiText, System.StringComparison.Ordinal));

                if (!string.IsNullOrEmpty(emojiText))
                {
                    int             spriteIndex = -1;
                    TMP_SpriteAsset spriteAsset = TMP_SpriteAsset
                                                  .SearchForSpriteByUnicode(rootEmojiAsset, char.ConvertToUtf32(emojiText, 0), true, out spriteIndex);
                    if (spriteAsset == null)
                    {
                        detectedEmojis.Add(emojiText);
                    }
                    text = text.Substring(emojiText.Length);
                }
                else
                {
                    break;
                }
            }

            if (detectedEmojis.Count > 0)
            {
                yield return(GithubHelper.Initialize());
            }

            foreach (var detectedEmoji in detectedEmojis)
            {
                string hex = char.ConvertToUtf32(detectedEmoji, 0).ToString("X");

                if (GithubHelper.IsValid(hex))
                {
                    yield return(emojiTexture.SetGithubEmoji(hex));

                    if (emojiTexture.didDownloadTexture)
                    {
                        PushSprite(emojiTexture);
                        didProcessAsync = true;
                    }
                }
            }

            //If the texture has unsaved changes, we apply them here
            //And make it non readable if it is full
            if (textureNeedsApply)
            {
                var makeNoLongerReadable = currentEmojiIndex == SHEET_TILES * SHEET_TILES;
                ((Texture2D)currentEmojiAsset.spriteSheet).Apply(false, makeNoLongerReadable);
                textureNeedsApply = false;
            }
        }