Home › Page › UghSpriteDefinition

UghSpriteDefinition

Ugh Scripting Reference > UghSpriteDefinition

Inherits from ScriptableObject

UghSpriteDefinitions are created in the editor via the sprite atlas process.  An UghSpriteDefinition is a collection of UghSpritePrototypes, where each prototype corresponds to a screen resolution.  At runtime, an UghSpriteDefinition will choose the best UghSpritePrototype to use based on the resolution of the screen.

UghSprites use UghSpriteDefinitions to define the texture they will display.

UghSpriteDefinition makes use of the ReferenceLink class.  Please read the documentation on ReferenceLink to understand how this impacts memory usage.

Variables
name type description
CurrentPrototype UghSpritePrototype The prototype that most closely matches the current screen resolution.
DefaultPrototype UghSpritePrototype The prototype that is used if a screen resolution cannot be determined.
resolutions UghSpriteResolutionDefinition[] A list of UghSpriteResolutionDefinitions that UghSpriteDefinition may choose from at runtime.
Events
name type description
OnCurrentPrototypeChanged  event Called when the value of CurrentPrototype changes (usually when a prototype is initially chosen at runtime.)
Class Functions
name type description
DefinitionFromPrototype UghSpriteDefinition Given an UghSpritePrototype, creates and returns an UghSpriteDefinition with the prototype as the DefaultPrototype.

_

Using UghSpriteDefinition in Script

UghSpriteDefinition is a solution for projects with target platforms that have different resolutions.  For example, a project may be built for both iPhone and iPad and require larger textures to maintain an attractive display on the iPad’s larger screen.

UghSpriteDefinition’s CurrentPrototype is chosen and loaded at runtime.  This is a slightly deferred load (it happens during the OnEnable ScriptableObject event.)  As such, if you need the CurrentPrototype as soon as it is loaded, you should register for the OnCurrentPrototypeChanged event.

UghSpriteDefinition’s DefaultPrototype is used both as a fallback if the CurrentPrototype fails to load at runtime, and as the prototype used in Unity’s scene editor window.  (DefaultPrototype is not deferred like CurrentPrototype, and thus is always safe to reference in script.)