The root class of all sprites. Does not assume any animation capabilities or atlas packing. More...
Public Types | |
enum | SPRITE_PLANE |
enum | ANCHOR_METHOD |
enum | WINDING_ORDER |
Public Member Functions | |
delegate void | SpriteResizedDelegate (float newWidth, float newHeight, SpriteRoot sprite) |
virtual void | Clear () |
Resets important sprite values to defaults for reuse. | |
virtual void | Copy (SpriteRoot s) |
Copies all the vital attributes of another sprite. | |
virtual void | Delete () |
If non-managed, call Delete() before destroying this component or the GameObject to which it is attached. Memory leaks can ensue otherwise. | |
void | CalcSize () |
Recalculates the width and height of the sprite based upon the change in its UV dimensions (autoResize) or on the current camera's disposition (pixelPerfect). | |
virtual void | SetSize (float w, float h) |
Sets the physical dimensions of the sprite in the plane selected. | |
virtual void | TruncateRight (float pct) |
Truncates the right edge of the sprite to the specified percentage. 1 == no truncation 0 == complete truncation. | |
virtual void | TruncateLeft (float pct) |
Truncates the left edge of the sprite to the specified percentage. 1 == no truncation 0 == complete truncation. | |
virtual void | TruncateTop (float pct) |
Truncates the top edge of the sprite to the specified percentage. 1 == no truncation 0 == complete truncation. | |
virtual void | TruncateBottom (float pct) |
Truncates the bottom edge of the sprite to the specified percentage. 1 == no truncation 0 == complete truncation. | |
virtual void | Untruncate () |
Removes any truncation. | |
virtual void | Unclip () |
Removes any clipping that is being applied to the sprite. | |
virtual void | UpdateUVs () |
Applies any changes to the UVs to the actual sprite mesh. | |
virtual void | SetColor (Color c) |
Sets the sprite's color to the specified color. | |
void | CalcPixelToUV () |
Recalculates the pixel-to-UV ratio based on the current texture. | |
void | SetTexture (Texture2D tex) |
Changes the texture to be used by the sprite's material. NOTE: This will cause the sprite not to batch with other sprites and can only be used with non-managed sprites. | |
void | SetMaterial (Material mat) |
Changes the material to be used by the sprite. NOTE: This can only be used with non-managed sprites. | |
void | UpdateCamera () |
Updates any camera-dependent settings, such as the calculated pixel-perfect size. Use this with BroadcastMessage() to do bulk re-calculation of object sizes whenever your screensize/resolution changes at runtime. | |
void | SetCamera () |
A no-argument version of SetCamera() that simply re-assigns the same camera to the object, forcing it to recalculate all camera-dependent calculations. | |
virtual void | SetCamera (Camera c) |
Sets the camera to use when calculating a pixel-perfect sprite size. | |
virtual void | Hide (bool tf) |
Hides or displays the sprite by disabling/enabling the sprite's mesh renderer component, or if managed, sets the mesh size to 0. | |
bool | IsHidden () |
Returns whether the sprite is currently set to be hideAtStart (whether its mesh renderer component is enabled). | |
void | SetBleedCompensation (float x, float y) |
Sets the bleed compensation to use (see bleedCompensation). | |
void | SetBleedCompensation (Vector2 xy) |
Sets the bleed compensation to use (see bleedCompensation). | |
void | SetPlane (SPRITE_PLANE p) |
Sets the plane in which the sprite is to be drawn. See: SPRITE_PLANE. | |
void | SetWindingOrder (WINDING_ORDER order) |
Sets the winding order to use. See WINDING_ORDER. | |
void | SetDrawLayer (int layer) |
Sets the draw layer of the sprite (only applies to managed sprites). | |
void | SetFrameInfo (SPRITE_FRAME fInfo) |
Sets the sprite's frame info, which includes UVs, offsets, etc. | |
void | SetUVs (Rect uv) |
Sets the sprite's UVs to the specified values. | |
void | SetUVsFromPixelCoords (Rect pxCoords) |
Sets the sprite's UVs from pixel coordinates. | |
Rect | GetUVs () |
Returns the current UV coordinates of the sprite (before bleed compensation). | |
Vector3[] | GetVertices () |
Returns a reference to the sprite's vertices. NOTE: You can only directly modify the sprite's vertices if it is a non-managed sprite. | |
Vector3 | GetCenterPoint () |
Gets the center point of the sprite, taking into account the actual positions of vertices. | |
void | SetAnchor (ANCHOR_METHOD a) |
Sets the anchor method to use. See ANCHOR_METHOD. | |
void | SetOffset (Vector3 o) |
Sets the offset of the sprite from its GameObject. See offset. | |
Vector2 | PixelSpaceToUVSpace (Vector2 xy) |
Converts pixel-space values to UV-space scalar values according to the currently assigned material. NOTE: This is for converting widths and heights-not coordinates (which have reversed Y-coordinates). For coordinates, use PixelCoordToUVCoord()! | |
Vector2 | PixelSpaceToUVSpace (int x, int y) |
Converts pixel-space values to UV-space scalar values according to the currently assigned material. NOTE: This is for converting widths and heights-not coordinates (which have reversed Y-coordinates). For coordinates, use PixelCoordToUVCoord()! | |
Vector2 | PixelCoordToUVCoord (Vector2 xy) |
Converts pixel coordinates to UV coordinates according to the currently assigned material. NOTE: This is for converting coordinates and will reverse the Y component accordingly. For converting widths and heights, use PixelSpaceToUVSpace()! | |
Vector2 | PixelCoordToUVCoord (int x, int y) |
Converts pixel coordinates to UV coordinates according to the currently assigned material. NOTE: This is for converting coordinates and will reverse the Y component accordingly. For converting widths and heights, use PixelSpaceToUVSpace()! | |
abstract int | GetStateIndex (string stateName) |
Returns the index of the state with the specified name. -1 if no state matching the specified name is found. | |
abstract void | SetState (int index) |
Sets the sprite to the specified state/animation. | |
Public Attributes | |
bool | managed = false |
When true, the sprite will be managed by the selected sprite manager script. When false, the sprite has its own mesh and will be batched automatically with other sprites (when available - Unity iPhone). | |
SpriteManager | manager |
Reference to the manager which will manage this sprite, provided managed is set to true. | |
int | drawLayer |
The layer in which the sprite will be drawn if managed. | |
bool | persistent = false |
This must be set to true at design time for the sprite to survive loading a new level. | |
SPRITE_PLANE | plane = SPRITE_PLANE.XY |
The plane in which the sprite will be drawn. | |
WINDING_ORDER | winding = WINDING_ORDER.CW |
The winding order of the sprite's polygons - determines the direction the sprite will "face". | |
float | width |
Width of the sprite in world space. | |
float | height |
Height of the sprite in world space. | |
Vector2 | bleedCompensation |
Will contract the UV edges of the sprite by the specified amount to prevent "bleeding" from neighboring pixels, especially when mipmapping. | |
ANCHOR_METHOD | anchor = ANCHOR_METHOD.TEXTURE_OFFSET |
Anchor method to use.
| |
bool | pixelPerfect = false |
Automatically sizes the sprite so that it will display pixel-perfect on-screen. NOTE: If you change the orthographic size of the camera or the distance between the sprite and a perspective camera, call SetCamera() to make the text pixel-perfect again. However, if you want automatic resizing functionality without being pixel-perfect and therefore allowing zooming in and out, use autoResize instead. | |
bool | autoResize = false |
Automatically resizes the sprite based on its new UV dimensions compared to its previous dimensions. Setting this to true allows you to use non-uniform sized sprites for animation without causing the sprite to appear "squashed" while animating. | |
Vector3 | offset = new Vector3() |
Offsets the sprite, in world space, from the center of its GameObject. | |
Color | color = Color.white |
The color to be used by all four of the sprite's vertices. This can be used to color, highlight, or fade the sprite. Be sure to use a vertex-colored shader for this to have an effect. | |
bool | hideAtStart = false |
Whether the sprite will be hideAtStart when it starts. | |
bool | ignoreClipping = false |
When true, the sprite will not be clipped. | |
Properties | |
Color | Color [get, set] |
Accessor for the object's current overall color tint. | |
virtual Camera | RenderCamera [get, set] |
Accessor for the camera that will be used to render this object. Use this to ensure the object is properly configured for the specific camera that will render it. | |
Vector2 | PixelSize [get, set] |
Gets/Sets the width and height of the sprite in pixels as it appears on-screen. | |
Vector2 | ImageSize [get] |
Gets the width and height of the image the sprite is displaying. NOTE: This is not the number of screen pixels occupied by the sprite, but rather the original number of texels which compose the sprite's image. | |
bool | Managed [get, set] |
Sets the sprite to a managed or batched state. | |
virtual Rect3D | ClippingRect [get, set] |
The rect against which the sprite should be clipped. The sprite will be immediately clipped by this rect when set. When setting, the rect should be in world space. | |
virtual bool | Clipped [get, set] |
Accessor for whether the sprite is to be clipped by any already-specified clipping rect. | |
ANCHOR_METHOD | Anchor [get, set] |
Accessor for the object's anchor method. | |
Vector3 | UnclippedTopLeft [get] |
The top-left corner of the sprite when no clipping or trimming is applied. | |
Vector3 | UnclippedBottomRight [get] |
The bottom-right corner of the sprite when no clipping or trimming is applied. | |
Vector3 | TopLeft [get] |
Returns the position of the top-left vertex of the sprite after any clipping or trimming. | |
Vector3 | BottomRight [get] |
Returns the position of the bottom-right vertex of the sprite after any clipping or trimming. |
The root class of all sprites. Does not assume any animation capabilities or atlas packing.
The anchoring scheme of a sprite. The anchor point is the point on the sprite that will remain stationary when the sprite's size changes. For a health bar that "grows" to the right while its left edge remains stationary, you would use UPPER_LEFT, MIDDLE_LEFT, or BOTTOM_LEFT.
For a health bar that "grows" upward while the bottom edge remains stationary, you would use BOTTOM_LEFT, BOTTOM_CENTER, or BOTTOM_RIGHT.
The plane in which a sprite should be drawn.
Defines which way the polygons of a sprite should be wound. The two options are clock-wise (CW) and counter clock-wise (CCW). These determine the direction the sprite will "face".
void SpriteRoot.CalcPixelToUV | ( | ) |
Recalculates the pixel-to-UV ratio based on the current texture.
void SpriteRoot.CalcSize | ( | ) |
Recalculates the width and height of the sprite based upon the change in its UV dimensions (autoResize) or on the current camera's disposition (pixelPerfect).
virtual void SpriteRoot.Clear | ( | ) | [virtual] |
Resets important sprite values to defaults for reuse.
Reimplemented in SimpleSprite, Sprite, AutoSpriteBase, and SpriteBase.
virtual void SpriteRoot.Copy | ( | SpriteRoot | s | ) | [virtual] |
Copies all the vital attributes of another sprite.
s | Source sprite to be copied. |
virtual void SpriteRoot.Delete | ( | ) | [virtual] |
If non-managed, call Delete() before destroying this component or the GameObject to which it is attached. Memory leaks can ensue otherwise.
Reimplemented in SpriteBase.
Vector3 SpriteRoot.GetCenterPoint | ( | ) |
Gets the center point of the sprite, taking into account the actual positions of vertices.
abstract int SpriteRoot.GetStateIndex | ( | string | stateName | ) | [pure virtual] |
Returns the index of the state with the specified name. -1 if no state matching the specified name is found.
stateName | The name of the state sought. |
Implemented in SimpleSprite, Sprite, and AutoSpriteBase.
Rect SpriteRoot.GetUVs | ( | ) |
Returns the current UV coordinates of the sprite (before bleed compensation).
Vector3 [] SpriteRoot.GetVertices | ( | ) |
Returns a reference to the sprite's vertices. NOTE: You can only directly modify the sprite's vertices if it is a non-managed sprite.
virtual void SpriteRoot.Hide | ( | bool | tf | ) | [virtual] |
Hides or displays the sprite by disabling/enabling the sprite's mesh renderer component, or if managed, sets the mesh size to 0.
tf | When true, the sprite is hideAtStart, when false, the sprite will be displayed. |
Reimplemented in UIListItem, UIProgressBar, UISlider, UITextField, AutoSpriteControlBase, and SpriteBase.
bool SpriteRoot.IsHidden | ( | ) |
Returns whether the sprite is currently set to be hideAtStart (whether its mesh renderer component is enabled).
Vector2 SpriteRoot.PixelCoordToUVCoord | ( | int | x, | |
int | y | |||
) |
Converts pixel coordinates to UV coordinates according to the currently assigned material. NOTE: This is for converting coordinates and will reverse the Y component accordingly. For converting widths and heights, use PixelSpaceToUVSpace()!
x | The x-coordinate to convert. | |
y | The y-coordinate to convert. |
Vector2 SpriteRoot.PixelCoordToUVCoord | ( | Vector2 | xy | ) |
Converts pixel coordinates to UV coordinates according to the currently assigned material. NOTE: This is for converting coordinates and will reverse the Y component accordingly. For converting widths and heights, use PixelSpaceToUVSpace()!
xy | The coordinates to convert. |
Vector2 SpriteRoot.PixelSpaceToUVSpace | ( | int | x, | |
int | y | |||
) |
Converts pixel-space values to UV-space scalar values according to the currently assigned material. NOTE: This is for converting widths and heights-not coordinates (which have reversed Y-coordinates). For coordinates, use PixelCoordToUVCoord()!
x | The X-value to convert. | |
y | The Y-value to convert. |
Vector2 SpriteRoot.PixelSpaceToUVSpace | ( | Vector2 | xy | ) |
Converts pixel-space values to UV-space scalar values according to the currently assigned material. NOTE: This is for converting widths and heights-not coordinates (which have reversed Y-coordinates). For coordinates, use PixelCoordToUVCoord()!
xy | The values to convert. |
void SpriteRoot.SetAnchor | ( | ANCHOR_METHOD | a | ) |
Sets the anchor method to use. See ANCHOR_METHOD.
a | The anchor method to use. |
void SpriteRoot.SetBleedCompensation | ( | Vector2 | xy | ) |
Sets the bleed compensation to use (see bleedCompensation).
void SpriteRoot.SetBleedCompensation | ( | float | x, | |
float | y | |||
) |
Sets the bleed compensation to use (see bleedCompensation).
virtual void SpriteRoot.SetCamera | ( | Camera | c | ) | [virtual] |
Sets the camera to use when calculating a pixel-perfect sprite size.
c |
Reimplemented in AutoSpriteControlBase.
void SpriteRoot.SetCamera | ( | ) |
A no-argument version of SetCamera() that simply re-assigns the same camera to the object, forcing it to recalculate all camera-dependent calculations.
virtual void SpriteRoot.SetColor | ( | Color | c | ) | [virtual] |
Sets the sprite's color to the specified color.
c | Color to shade the sprite. |
Reimplemented in UIProgressBar, and UISlider.
void SpriteRoot.SetDrawLayer | ( | int | layer | ) |
Sets the draw layer of the sprite (only applies to managed sprites).
layer | The draw layer of the sprite. Lower values cause an earlier draw order, higher values, a later draw order. |
void SpriteRoot.SetFrameInfo | ( | SPRITE_FRAME | fInfo | ) |
Sets the sprite's frame info, which includes UVs, offsets, etc.
fInfo | A SPRITE_FRAME structure containing the frame info. |
void SpriteRoot.SetMaterial | ( | Material | mat | ) |
Changes the material to be used by the sprite. NOTE: This can only be used with non-managed sprites.
mat | The new material. |
void SpriteRoot.SetOffset | ( | Vector3 | o | ) |
Sets the offset of the sprite from its GameObject. See offset.
o | The offset to use. |
void SpriteRoot.SetPlane | ( | SPRITE_PLANE | p | ) |
Sets the plane in which the sprite is to be drawn. See: SPRITE_PLANE.
p | The plane in which the sprite should be drawn. |
virtual void SpriteRoot.SetSize | ( | float | w, | |
float | h | |||
) | [virtual] |
Sets the physical dimensions of the sprite in the plane selected.
width | Width of the sprite in world space. | |
height | Height of the sprite in world space. |
Reimplemented in UIProgressBar, and UISlider.
abstract void SpriteRoot.SetState | ( | int | index | ) | [pure virtual] |
Sets the sprite to the specified state/animation.
index | The zero-based index of the desired state/animation. |
Implemented in SimpleSprite, Sprite, and AutoSpriteBase.
void SpriteRoot.SetTexture | ( | Texture2D | tex | ) |
Changes the texture to be used by the sprite's material. NOTE: This will cause the sprite not to batch with other sprites and can only be used with non-managed sprites.
tex | The new texture. |
void SpriteRoot.SetUVs | ( | Rect | uv | ) |
Sets the sprite's UVs to the specified values.
nextFrame | A Rect containing the new UV coordinates. |
void SpriteRoot.SetUVsFromPixelCoords | ( | Rect | pxCoords | ) |
Sets the sprite's UVs from pixel coordinates.
pxCoords | A rect containing the pixel coordinates. When populating the Rect, use the following syntax: Rect.MinMaxRect(leftCoord, bottomCoord, rightCoord, topCoord) Where the coordinates are in pixel space. Like in any image editor, the coordinate space runs from 0 on the left to width-1 on the right, and 0 at the top, to height-1 at the bottom. |
void SpriteRoot.SetWindingOrder | ( | WINDING_ORDER | order | ) |
Sets the winding order to use. See WINDING_ORDER.
order | The winding order to use. |
delegate void SpriteRoot.SpriteResizedDelegate | ( | float | newWidth, | |
float | newHeight, | |||
SpriteRoot | sprite | |||
) |
Defines a delegate that can be called upon resizing of the sprite. Use this if you want to adjust colliders, etc, when the sprites dimensions are resized.
virtual void SpriteRoot.TruncateBottom | ( | float | pct | ) | [virtual] |
Truncates the bottom edge of the sprite to the specified percentage. 1 == no truncation 0 == complete truncation.
pct | The percentage of the sprite to truncate (0-1) |
Reimplemented in UIListItem, and AutoSpriteControlBase.
virtual void SpriteRoot.TruncateLeft | ( | float | pct | ) | [virtual] |
Truncates the left edge of the sprite to the specified percentage. 1 == no truncation 0 == complete truncation.
pct | The percentage of the sprite to truncate (0-1) |
Reimplemented in UIListItem, and AutoSpriteControlBase.
virtual void SpriteRoot.TruncateRight | ( | float | pct | ) | [virtual] |
Truncates the right edge of the sprite to the specified percentage. 1 == no truncation 0 == complete truncation.
pct | The percentage of the sprite to truncate (0-1) |
Reimplemented in UIListItem, and AutoSpriteControlBase.
virtual void SpriteRoot.TruncateTop | ( | float | pct | ) | [virtual] |
Truncates the top edge of the sprite to the specified percentage. 1 == no truncation 0 == complete truncation.
pct | The percentage of the sprite to truncate (0-1) |
Reimplemented in UIListItem, and AutoSpriteControlBase.
virtual void SpriteRoot.Unclip | ( | ) | [virtual] |
Removes any clipping that is being applied to the sprite.
Reimplemented in UIProgressBar, UISlider, UITextField, and AutoSpriteControlBase.
virtual void SpriteRoot.Untruncate | ( | ) | [virtual] |
Removes any truncation.
Reimplemented in UIListItem, and AutoSpriteControlBase.
void SpriteRoot.UpdateCamera | ( | ) |
Updates any camera-dependent settings, such as the calculated pixel-perfect size. Use this with BroadcastMessage() to do bulk re-calculation of object sizes whenever your screensize/resolution changes at runtime.
virtual void SpriteRoot.UpdateUVs | ( | ) | [virtual] |
Applies any changes to the UVs to the actual sprite mesh.
ANCHOR_METHOD SpriteRoot.anchor = ANCHOR_METHOD.TEXTURE_OFFSET |
bool SpriteRoot.autoResize = false |
Automatically resizes the sprite based on its new UV dimensions compared to its previous dimensions. Setting this to true allows you to use non-uniform sized sprites for animation without causing the sprite to appear "squashed" while animating.
Vector2 SpriteRoot.bleedCompensation |
Will contract the UV edges of the sprite by the specified amount to prevent "bleeding" from neighboring pixels, especially when mipmapping.
Color SpriteRoot.color = Color.white |
The color to be used by all four of the sprite's vertices. This can be used to color, highlight, or fade the sprite. Be sure to use a vertex-colored shader for this to have an effect.
The layer in which the sprite will be drawn if managed.
float SpriteRoot.height |
Height of the sprite in world space.
bool SpriteRoot.hideAtStart = false |
Whether the sprite will be hideAtStart when it starts.
bool SpriteRoot.ignoreClipping = false |
When true, the sprite will not be clipped.
bool SpriteRoot.managed = false |
When true, the sprite will be managed by the selected sprite manager script. When false, the sprite has its own mesh and will be batched automatically with other sprites (when available - Unity iPhone).
Reference to the manager which will manage this sprite, provided managed is set to true.
Vector3 SpriteRoot.offset = new Vector3() |
Offsets the sprite, in world space, from the center of its GameObject.
bool SpriteRoot.persistent = false |
This must be set to true at design time for the sprite to survive loading a new level.
bool SpriteRoot.pixelPerfect = false |
Automatically sizes the sprite so that it will display pixel-perfect on-screen. NOTE: If you change the orthographic size of the camera or the distance between the sprite and a perspective camera, call SetCamera() to make the text pixel-perfect again. However, if you want automatic resizing functionality without being pixel-perfect and therefore allowing zooming in and out, use autoResize instead.
SPRITE_PLANE SpriteRoot.plane = SPRITE_PLANE.XY |
The plane in which the sprite will be drawn.
float SpriteRoot.width |
Width of the sprite in world space.
WINDING_ORDER SpriteRoot.winding = WINDING_ORDER.CW |
The winding order of the sprite's polygons - determines the direction the sprite will "face".
ANCHOR_METHOD SpriteRoot.Anchor [get, set] |
Accessor for the object's anchor method.
Vector3 SpriteRoot.BottomRight [get] |
Returns the position of the bottom-right vertex of the sprite after any clipping or trimming.
virtual bool SpriteRoot.Clipped [get, set] |
Accessor for whether the sprite is to be clipped by any already-specified clipping rect.
Reimplemented in UIProgressBar, UISlider, UITextField, and AutoSpriteControlBase.
virtual Rect3D SpriteRoot.ClippingRect [get, set] |
The rect against which the sprite should be clipped. The sprite will be immediately clipped by this rect when set. When setting, the rect should be in world space.
Reimplemented in UIProgressBar, UISlider, UITextField, and AutoSpriteControlBase.
Color SpriteRoot.Color [get, set] |
Accessor for the object's current overall color tint.
Vector2 SpriteRoot.ImageSize [get] |
Gets the width and height of the image the sprite is displaying. NOTE: This is not the number of screen pixels occupied by the sprite, but rather the original number of texels which compose the sprite's image.
bool SpriteRoot.Managed [get, set] |
Sets the sprite to a managed or batched state.
Vector2 SpriteRoot.PixelSize [get, set] |
Gets/Sets the width and height of the sprite in pixels as it appears on-screen.
virtual Camera SpriteRoot.RenderCamera [get, set] |
Accessor for the camera that will be used to render this object. Use this to ensure the object is properly configured for the specific camera that will render it.
Reimplemented in AutoSpriteControlBase.
Vector3 SpriteRoot.TopLeft [get] |
Returns the position of the top-left vertex of the sprite after any clipping or trimming.
Vector3 SpriteRoot.UnclippedBottomRight [get] |
The bottom-right corner of the sprite when no clipping or trimming is applied.
Vector3 SpriteRoot.UnclippedTopLeft [get] |
The top-left corner of the sprite when no clipping or trimming is applied.