Image

April 25, 2020 ยท View on GitHub

Images designed and developed in Unity's current UI workflow are generally supported. Currently the only image type supported are Image components that have a fill type of Simple. More will be supported on an on need basis.

Conversion Pipeline

Images are converted through the ImageConversionSystem where the following components are attached to the entity generated by the conversion system:

ComponentDescription
LinkedMaterialEntityThe entity which has a Material component object attached and linked to the image entity
LinkedTextureEntityThe entity which has a Texture2D component object attached and linked to the image entity
AppliedColorThe current color of the Image
DimensionsThe size of the image on the canvas - i.e. the rect
DefaultSpriteResolutionThe original resolution of the sprite (see below for more details)
SpriteDataInformation of the sprite containing UVs and padding
MeshVertexDataVertex information required by a mesh
TriangleIndexElementIndices needed to generate the mesh
MeshDataSpanStores the slice of vertex and index spans of the submesh that the image belongs to
BuildUIElementTagOptionally added if you want to update the root mesh's data
UpdateVertexColorTagOptionally added if the color of the mesh needs to change, but the structure remains persistent.
MaterialPropertyIndexThe material property that the image will access when rendering.

Limitations

Currently only ImageTypes that are Simple work. Support for Sliced sprites are coming.

DefaultSpriteResolution

This stores the original resolution of the sprite. Meaning that if you had a 100x100 sprite, but your Image component is 200x200, we want to store the default resolution so we can reason about the scale of the displayed texture (in our case 2x). The scale computed is required to adjust the resultant calculation for any kind of padding our sprite needs from the SpriteData. This ensures that there is no stretching and the representation in Editor time is equivalent to runtime.

Storing Mesh Data

The LocalVertexDataElement and LocalTriangleIndexElement buffers contain the core data needed to build a mesh. Images are effectively quads and the BuildImageVertexDataSystem takes care of that for you, calculating the padding and using the canvas scale to dynamically , to compute the mesh vertices needed to display.

Associating Textures to "Texture" Entities

Textures are stored on their own entities as a ComponentObject. These entities are linked to associated Image entities via the VisualAssetConversionSystem and declared in the VisualAssetDeclarationSystem.

An image without a Texture uses the default Texture2D.whiteTexture, which is a single pixel that is white.