Here are two screenshots from Stellaris, where images are seamlessly integrated into the text. How can I achieve this in Unity?
The regular Text component unfortunately can't do that, at least not on a UI canvas and without some nasty hacks. But TextMeshPro can. I really recommend using TextMeshPro over the classic Text component anyway, because it is superior in basically every way. The only thing which still justifies the existence of the classic Text component is backwards compatibility.
- Create an image asset with all the icons you need (aka "sprite atlas")
- Import the image as a "Texture Type: Sprite" with "Sprite Type: Multiple".
- Slice the image into sprites using the sprite editor (requires importing the 2D Sprite package from the package manager). Set the "Pivot" of every sprite to "Bottom Left" (otherwise the sprites will not align properly with the text).
- Right-click on the image asset in your project window and select Create > TextMeshPro > Sprite Asset
- Create a "Text - TextMeshPro" gameObject on your canvas. When you already have one, make sure that you still have "Rich Text" enabled (it's hidden under "Extra Settings").
- Assign that sprite asset to your TextMeshPro component. The setting is hidden under "Extra Settings". Or alternatively, if you want to use the same set of icons for all texts in the game, Go to Edit > Project Settings > Text Mesh Pro > Settings and set the default sprite asset to the asset you just created.
- You can now refer to sprites in your sprite asset by writing
<sprite=number>into the text of your text object, where "number" is the sprite number from your sprite atlas. You can also explicitly name sprites in your TextMeshPro Sprite Asset and then refer to them as
For example, if the second tooltip from the screenshot in the question were a TextMeshPro text, then its text would read something like this in the editor:
Pop Amenities Usage (<sprite name="populaton"> <color="yellow">52</color>): <color="red">52</color>