Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ibicha/emojitexture
A Unity plugin to render Emojis ☺ ❤ 🍆 🍑 to a texture
https://github.com/ibicha/emojitexture
android ios texture unity-plugin unity3d
Last synced: about 2 months ago
JSON representation
A Unity plugin to render Emojis ☺ ❤ 🍆 🍑 to a texture
- Host: GitHub
- URL: https://github.com/ibicha/emojitexture
- Owner: iBicha
- License: other
- Archived: true
- Created: 2017-12-31T23:14:09.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2023-02-07T19:26:28.000Z (almost 2 years ago)
- Last Synced: 2024-09-26T23:04:53.240Z (about 2 months ago)
- Topics: android, ios, texture, unity-plugin, unity3d
- Language: C#
- Homepage:
- Size: 810 KB
- Stars: 62
- Watchers: 9
- Forks: 9
- Open Issues: 17
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# EmojiTexture
##### :warning: Unity now supports [Emojis using TextMesh Pro](https://docs.unity3d.com/Packages/[email protected]/manual/ColorEmojis.html). Please use that package instead, since this project hasn't been updated for a while.A Unity plugin to render Emojis ☺ ❤ 🍆 🍑 to a texture. Currently for iOS and Android only.
Please note that the editor is not supported. It will only render on device (should work on simulator as well)
## Preview
## Usage
As simple as:
```csharp
material.mainTexture = new EmojiTexture("❤");
```
You can also do these things:
```csharp
//Create an EmojiTexture with a specific size (best if power of 2)
var emojiTexture = new EmojiTexture(128);//Change an existing EmojiTexture
emojiTexture.Text = "❤";//Get the texture as an array of bytes, in case you want to do something with it
var bytes = emojiTexture.ByteBuffer;//Know the code of the emoji? Set it directly as an integer!
//E.g. https://emojipedia.org/smiling-face-with-smiling-eyes/
emojiTexture.Unicode = 0x1F60A; //😊 Smiling Face With Smiling Eyes```
## Github emoji API (Experimental)
When not running Android or iOS, EmojiTexture can use [Github emoji API](https://developer.github.com/v3/emojis/).
This require network connection. While the list of emojis is cached, individual images are not.Setting emojis from Github needs to run in a `Coroutine`, because it is an async operation.
It is possible to set the emoji text (same as above)
```
yield return emojiTexture.SetGithubEmoji("❤");
```
Or using keywords
```
yield return emojiTexture.SetGithubEmoji(":heart:");
```Please check out example scene for usage (it includes a native emoji, a github emoji and TextMesh Pro examples, that shuffle emojis from script or read user imput with touch screen).
## TextMesh Pro support (Experimental)
[TextMesh Pro](https://assetstore.unity.com/packages/essentials/beta-projects/textmesh-pro-84126) already supports emojis as sprites, but they need to be prepared beforehand, which makes it troublesome in terms of build size (and also a lot of manual work), if you want to support as many emojis as possible. This is where EmojiTexture comes in. It generates these sprites on the fly as they are needed.## Setup
~~- Import TextMesh Pro from the [Asset Store](https://assetstore.unity.com/packages/essentials/beta-projects/textmesh-pro-84126)~~ Use the new **Package Manager** to install TextMesh Pro (this should happen automatically since it is a project dependency)
- In the Player Settings, add `TMPRO_EMOJIS` to the [Scripting Define Symbols](https://docs.unity3d.com/Manual/PlatformDependentCompilation.html)![Scripting Define Symbols](https://docs.unity3d.com/uploads/Main/ScriptDefines.png)
- Add the component `TMP_EmojiSupport` on the same game object as your `TextMeshPro` or `TextMeshProUGUI` component.
That's about it. You should have emoji support out of the box.
- On the `TMP_EmojiSupport` component, if `Github fallback` is checked, the emojis will be downloaded from github if you are not running on Android or iOS (and if you have network)## Optimizations
Few pointers to consider:
- Emojis are stored in sprite sheets of the size 4 by 4 (16 emojis) with an emoji texture of `128x128` pixels (which makes a `512x512` per sprite sheet.) These are constants defined in `TMProEmojiAsset.EMOJI_SIZE` and `TMProEmojiAsset.SHEET_TILES`. Optimize these values according to your use case. **BE AWARE** currently, github returns enoji images as `128x128`, and they share the same sprite sheet. Changing these constants will probably break emojis from github. (A resizing method needs to be implemented for that purpose, but that would be at the cost of performance)- When a sprite sheet is full, a new one is created.
- Currently cleaning up unused emojis is not yet supported. This will be added in the future.## Known issues.
- While the native emoji renderer (Android/iOS) tries to estimate the correct rendering, Github emojis and TMP both have trouble with complex emojis (such as flags, emojis with skintones, etc). These will be addressed in the future, as there is room for improvement.
- Some rendering issues are due to how TMP works, because it scans for unicode characters, and we get to feed it sprites. This needs to be fixed on TMP's side.