1

I want to use the Emoji's in my project. but as we all know that unity is not supporting the all emoji's. First I try to make the Sprite asset and with it I can use many emoji but the Emoji's with the complex Unicode like "1f3c3_1f3fb_200d_2642" this Emoji.

I want to use all the Emoji's in unity Using the TextMeshPro. Is there any way to make it happen in unity. Thanks in Advance.

derHugo
  • 83,094
  • 9
  • 75
  • 115
Rahmat Ali
  • 13
  • 8
  • 1
    Do you have a font that contains that emoji? – derHugo Jul 27 '23 at 06:42
  • 1
    I used the Two Approaches. – Rahmat Ali Jul 27 '23 at 06:47
  • 1
    1- I use the Images in the texture packer importer to make the sprite atlas and json file of the Selected Emoji's. the use this to make the sprite asset in the Unity and used this but unity Didn't handle the Complex Unicode. – Rahmat Ali Jul 27 '23 at 06:48
  • 1
    2- I used the Apple Emoji font to that unity has introduce the Emojis in text mesh pro 3.2.0-pre.4. but id is still not working with the all emoji's I contacted with the Team and they said they are Working on it. – Rahmat Ali Jul 27 '23 at 06:50
  • You can also use SVGs. @RahmatAli – Obscure021 Jul 27 '23 at 06:50
  • 1
    I look like Pretty Dumb to Ask But Will you explain this? – Rahmat Ali Jul 27 '23 at 06:51
  • Unity has a package that allows SVGs to be imported into Unity UI Toolkit. if you don't know about SVG refer to [Fireship Tutorial](https://www.youtube.com/watch?v=emFMHH2Bfvo&pp=ygUKc3ZnIHZzIHBuZw%3D%3D)]. I think it works for normal UI too. – Obscure021 Jul 27 '23 at 06:54
  • 1
    I am getting your Point but and I am using it in my game but the Unity cannot Understand the Complex Unicode. but the Simple Emoji like Face and fruit animals are Working fine but the Emoji's like flag and Skinned emoji has the Complex Unicode which is Difficult for unity to understand it now. – Rahmat Ali Jul 27 '23 at 06:55
  • 1
    It is not the Image Format Issue the Unity is not Able to Under the Complex Unicode. Thanks for Your Concern on this. – Rahmat Ali Jul 27 '23 at 06:58
  • What is the font you are using emoji font? – Obscure021 Jul 27 '23 at 06:59
  • 1
    I am using the Apple Emoji Font. I downloaded it from the Google. – Rahmat Ali Jul 27 '23 at 07:01
  • Try this font: [Noto Emoji](https://fonts.google.com/noto/specimen/Noto+Emoji/glyphs) – Obscure021 Jul 27 '23 at 07:02
  • 1
    I have Tried this one But it didn't show Anything. it shows only the Blank Input Field. – Rahmat Ali Jul 27 '23 at 07:04
  • 1
    I have [an enumerator class](https://gist.github.com/geniuszxy/9bb507f03eb17526d4f58f3c387031b3) that can extract emoji sequences from a string, you can use it to replace emoji sequences to sprite names which TMP supports. – shingo Jul 27 '23 at 07:04
  • 1
    Ok Thanks, @shingo But will you explain this a little more to me. – Rahmat Ali Jul 27 '23 at 07:09

1 Answers1

1

You should prepare your sprite asset first, here is an example that uses the EmojiIterator class to convert long emoji sequences to TMP's sprite tags.

static string ProcessText(string text)
{
    var itor = new EmojiIterator(text);
    var sb = new StringBuilder();
    while(itor.MoveNext())
    {
        if(itor.SequenceLength <= 2) //TMP can handle single emoji characters.
            sb.Append(itor.Sequence);
        else //use sprite asset
            sb.Append($@"<sprite name=""{ConvertToName(itor.Sequence)}"">"
    }
    return sb.ToString();
}

The ConvertToName method is used to convert a string like "\U0001f3c3\U0001f3fb\u200d\u2642" to "1f3c3_1f3fb_200d_2642".

static string ConvertToName(string text)
{
    var sb = new StringBuilder();
    for (int i = 0; i < text.Length; i++)
    {
        var j = char.ConvertToUtf32(text, i);
        if (j > 0xffff)
            i++;
        sb.Append(j.ToString("x"));
        sb.Append('_');
    }
    return sb.Length > 0 ? sb.ToString(0, sb.Length - 1) : "";
}
shingo
  • 18,436
  • 5
  • 23
  • 42
  • 1
    The StringBuilder() is not in the EmojiIterato? – Rahmat Ali Jul 27 '23 at 09:45
  • 1
    `StringBuilder` is a .net class. – shingo Jul 27 '23 at 11:02
  • 1
    I have tried your Approach, when I try to Write the Single character it works Fine but when I try to press the Emoji from keyboard it Stuck in Infinite Loop(While Loop). This is the Image link: https://drive.google.com/drive/folders/1eXPEOLV1QDkpNkUuA8Q9Pqe3ebiIJOat – Rahmat Ali Jul 27 '23 at 11:04
  • 1
    Please try to copy the class again, the code is outdated and I've updated it. – shingo Jul 27 '23 at 11:28
  • 1
    Thankyou the Code Works Perfectly. – Rahmat Ali Jul 27 '23 at 11:57
  • 1
    Can you accept my answer? – shingo Jul 27 '23 at 14:41
  • 1
    Hi! Sorry for the Late Response but there are Some Emoji's which is Not Working with this Approach, – Rahmat Ali Jul 31 '23 at 05:36
  • 1
    I have Accepted the Answer but there is Some Issue Will you help? Like the flag's The Flag just show the Yellow Question Mark Image when clicked on the Flag. – Rahmat Ali Jul 31 '23 at 05:37
  • 1
    What does "clicked on the Flag" mean? Do you know the emoji sequence of the flag? Was it found by the iterator? – shingo Jul 31 '23 at 07:11
  • 1
    Sorry for issue. Resolved it by myself I named the Emoji with the Unicode like "1f4gf-1fdhf" but In your Script the Name Shows of the Emoji is "1f4gf_1fdhf", there is the "_" so that's why it cannot get the name resolved it by my side. – Rahmat Ali Jul 31 '23 at 07:42
  • 1
    Will yo response on this thread Also thanks. https://stackoverflow.com/questions/76801039/how-to-set-the-glyph-by-value-of-sprite-asset-of-all-unity – Rahmat Ali Jul 31 '23 at 07:42
  • 1
    Hi Shingo, I am facing the Issue in which there are some Emoji's which have the name like"00ae_fe0f" and "26a0_fe0f", Your Component Could not get the name of these Emoji's. there are About 300 plus emoji's with this Unicode. I appreciate your Help from the Start. here's the reference Link: https://drive.google.com/file/d/1mirS0DTRqNHQUxlA5i7kq5ouhJk8TZh0/view?usp=drive_link – Rahmat Ali Aug 01 '23 at 06:19
  • Hi @shingo Thanks for your Help In past Regarding Emoji's Is there Any Update Regarding this. – Rahmat Ali Aug 21 '23 at 12:21
  • No, haven't you used the TMP built-in emoji solution? – shingo Aug 21 '23 at 13:55
  • Ok thank If you find or I Find the Solution to this Issue Let each other Know. – Rahmat Ali Aug 23 '23 at 07:17