Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice
  4. Dismiss Notice

Displaying Emoji

Discussion in 'UGUI & TextMesh Pro' started by markofevil3, Mar 15, 2016.

  1. markofevil3

    markofevil3

    Joined:
    Mar 18, 2013
    Posts:
    2
    Hi, Is there any text plugin allow displaying Emoji on Label using dynamic font? I tried TextMesh and NGUI but they only support displaying image on Label using Bitmap Font.
     
  2. splash5

    splash5

    Joined:
    Nov 8, 2014
    Posts:
    13
    Unity has some problem handing unicode surrogate pair.
    So it just not possible to show emoji correctly even if you set the right font.
     
  3. pleclerc

    pleclerc

    Joined:
    Mar 3, 2016
    Posts:
    1
    Hi,

    I just wrapped up a task for work about getting full emoji support for mobile devices. If anyone is interested, here's what we did:

    - Using TextMesh Pro, with the sprite atlas support.

    - Created a very large atlas (2048x2048) of 32x32 sprites: one for each emoji icon (emoji wikipeda page shows the unicode range for all emojis). The sheet contains all the emojis for a specific group (for eg: emoticons) in the exact order of their unicodes, so it's an easy 1 to 1 match between a unicode and its corresponding sprite.

    - Created a quick import script for the sprite because the Unity sprite packer window will take about 10 mins to slice the 2048x2048 image in packs of 32x32 (I wouldn't actually know how to make it this slow to be honest, That's a feat in itself ^^). The quick import script does it in about 30 secs (that's still so slow ; ;)

    - Added a ParseText function to Tmp_Text in TextMesh Pro that basically parses a string and looks for any UTF16 (encoded on 1 char in c#) that is within the range of emoji as added in the previous step. If it finds it, it replaces the UTF16 char by <sprite=X> (the TextMesh Pro command to display a specific sprite), where X is basically UnicodeValue - UnicodeOffsetToSprite0.
    The function also parses UTF16 (on 2 chars) by checking: char.IsHighSurrogate and if that's true, form a surrogate pair from the current char and the next. Then char.ConvertToUtf32(high, low) gives you the unicode value and you again get the sprite index from it, like above.

    - Lastly, in Tmp_Text, changed the text setter to call my ParseFunction on the given text.

    The result is showing all emojis in the TextMeshPro text and Inputfield, regardless of the chosen font (since it's tied to a sprite sheet) and a fully function backspace key as well.

    If anyone needs more information or access to our sprite sheet, I'll try to find a way to put up what I can online somewhere.
    (Sorry, I don't read the forums that often, so it might take be a little bit to respond back ^^)
     
    ypatelzynga likes this.
  4. crispybeans

    crispybeans

    Joined:
    Apr 13, 2015
    Posts:
    210
    I have created a plugin for getting emoji's up and running on mobile devices , you can have it if you're interested , write me on tastybits8@gmail.com and you can have a link.

    Essentially you just need to plug in into the game and it will render emoji's to a UnityEngine.UI textfield when you type when with the keyboard or when you paste some text that has emoji's.

    Also, when you want to create an emoji in a text field what you do is to write :smiley: and it will create a smiley for you.
     
  5. programmrzinc

    programmrzinc

    Joined:
    May 29, 2011
    Posts:
    79
  6. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    8,996
    Novack likes this.
  7. ypatelzynga

    ypatelzynga

    Joined:
    Aug 30, 2018
    Posts:
    9
    I am trying to solve same problem, Can you please share source code and sprite sheet? It would be great help