Home › Page › UghSpritePrototype


Ugh Scripting Reference > UghSpritePrototype

Inherits from ScriptableObject.

UghSpritePrototype defines an individual sprite held inside a sprite atlas.  Variables that define the location and size of the sprite are automatically filled with values when a sprite atlas is generated.  Additional variables define the appearance and behavior of the sprite, and must be adjusted by the user.

UghSprite uses UghSpritePrototype to compose a sprite.

UghSpriteDefinition holds a list of UghSpritePrototypes (inside of the UghSpriteResolutionDefinition helper class) and chooses an appropriate UghSpritePrototype based on screen resolution at runtime.

name type description
edgeInsets EdgePixels Calculated at runtime.  The bounding rectangle of the sprite in the atlas, in Unity units.
edgePixelCrops EdgePixels The number of pixels to shave off of each side.  Useful to get rid of edge artifacts after PVRTC compression.
edgePixelInsets EdgePixels The bounding rectangle of the sprite in the atlas, in pixels.
insetScaling InsetScaling A hint to UghSprite on how to stretch UVs when the sprite is scaled.
material Material The atlas material that holds the sprite.
nativePixelSize Vector3 The width and height of the sprite, in pixels.
nativeUVRect Rect The UV coordinates of the sprite in the atlas.
pixelHeight int Calculated at runtime.  The actual height of the sprite (including scaling and crops) in pixels.
pixelSize Vector3 Calculated at runtime.  The actual size of the sprite (including scaling and crops) in pixels.
pixelWidth int Calculated at runtime.  The actual width of the sprite (including scaling and crops) in pixels.
size Vector3 Calculated at runtime.  The size of the sprite, in Unity units.
sourceUVRect Rect Calculated at runtime.  The actual UV coordinates of the sprite in the atlas (including scaling and crops.)
name type description
CreateSprite GameObject Generates an UghSprite (or derivative) that uses this UghSpritePrototype.
UpdatePrototype void Calculates the value of all variables that are filled at runtime.


Using UghSpritePrototype in Script

public GameObject CreateSprite(Type type)

Given an UghSprite Type (or derivative,) this function will return a game object with the appropriate components, with the Prototype variable filled in with this UghSpritePrototype.  For example:  Calling CreateSprite(typeof(UghButton)) will return a GameObject that has an UghButton component.

public void UpdatePrototype()

This function will calculate values for all variables that are determined at runtime.  This function is automatically called once during OnEnable.  Call this function if you change any variables at runtime and need to immediately update the calculated variables.