Sprite base class. Performs target agnostic functionality and manages state parameters. More...

Inherits tk2dRuntime.ISpriteCollectionForceBuild.

Inherited by tk2dClippedSprite, tk2dSlicedSprite, tk2dSprite, and tk2dTiledSprite.

List of all members.

Public Types

enum  Anchor
 Anchor. NOTE: The order in this enum is deliberate, to initialize at LowerLeft for backwards compatibility. This is also the reason it is local here. Other Anchor enums are NOT compatbile. Do not cast. More...

Public Member Functions

void SetSprite (int newSpriteId)
 Sets the sprite by identifier.
bool SetSprite (string spriteName)
 Sets the sprite by name. The sprite will be selected from the current collection.
void SetSprite (tk2dSpriteCollectionData newCollection, int newSpriteId)
 Sets sprite by identifier from the new collection.
bool SetSprite (tk2dSpriteCollectionData newCollection, string spriteName)
 Sets sprite by name from the new collection.
void MakePixelPerfect ()
 Makes the sprite pixel perfect to the active camera. Automatically detects tk2dCamera if present Otherwise uses Camera.main.
abstract void Build ()
 Rebuilds the mesh data for this sprite. Not usually necessary to call this, unless some internal states are modified.
int GetSpriteIdByName (string name)
 Resolves a sprite name and returns a unique id for the sprite. Convenience alias of tk2dSpriteCollectionData.GetSpriteIdByName
Bounds GetBounds ()
 Gets the local space bounds of the sprite.
Bounds GetUntrimmedBounds ()
 Gets untrimmed local space bounds of the sprite. This is the size of the sprite before 2D Toolkit trims away empty space in the sprite. Use this when you need to position sprites in a grid, etc, when the trimmed bounds is not sufficient.
tk2dSpriteDefinition GetCurrentSpriteDef ()
 Gets the current sprite definition.
virtual void ReshapeBounds (Vector3 dMin, Vector3 dMax)
 Used for sprite resizing in Editor, and UILayout.

Static Public Member Functions

static T AddComponent< T > (GameObject go, tk2dSpriteCollectionData spriteCollection, int spriteId)
 Adds a tk2dBaseSprite derived class as a component to the gameObject passed in, setting up necessary parameters and building geometry.
static T AddComponent< T > (GameObject go, tk2dSpriteCollectionData spriteCollection, string spriteName)
 Adds a tk2dBaseSprite derived class as a component to the gameObject passed in, setting up necessary parameters and building geometry. Shorthand using sprite name.
static GameObject CreateFromTexture< T > (Texture texture, tk2dSpriteCollectionSize size, Rect region, Vector2 anchor)
 Create a sprite (and gameObject) displaying the region of the texture specified. Use tk2dSpriteCollectionData.CreateFromTexture if you need to create a sprite collection with multiple sprites.

Public Attributes

BoxCollider boxCollider = null
 Internal cached version of the box collider created for this sprite, if present.
MeshCollider meshCollider = null
 Internal cached version of the mesh collider created for this sprite, if present.

Properties

tk2dSpriteCollectionData Collection [get, set]
 Deprecation warning: the set accessor will be removed in a future version. Use SetSprite when you need to switch sprite collection.
Color color [get, set]
 Gets or sets the color.
Vector3 scale [get, set]
 Gets or sets the scale.
int SortingOrder [get, set]
 Gets or sets the sorting order The sorting order lets you override draw order for sprites which are at the same z position It is similar to offsetting in z - the sprite stays at the original position This corresponds to the renderer.sortingOrder property in Unity 4.3.
bool FlipX [get, set]
 Flips the sprite horizontally. Set FlipX to true to flip it horizontally. Note: The sprite itself may be flipped by the hierarchy above it or localScale These functions do not consider those cases.
bool FlipY [get, set]
 Flips the sprite vertically. Set FlipY to true to flip it vertically. Note: The sprite itself may be flipped by the hierarchy above it or localScale These functions do not consider those cases.
int spriteId [get, set]
 Gets or sets the sprite identifier.
tk2dSpriteDefinition CurrentSprite [get]
 Gets the current sprite definition.

Events

System.Action< tk2dBaseSpriteSpriteChanged
 This event is called whenever a sprite is changed. A sprite is considered to be changed when the sprite itself is changed, or the scale applied to the sprite is changed.

Detailed Description

Sprite base class. Performs target agnostic functionality and manages state parameters.


Member Enumeration Documentation

Anchor. NOTE: The order in this enum is deliberate, to initialize at LowerLeft for backwards compatibility. This is also the reason it is local here. Other Anchor enums are NOT compatbile. Do not cast.


Member Function Documentation

static T tk2dBaseSprite.AddComponent< T > ( GameObject  go,
tk2dSpriteCollectionData  spriteCollection,
int  spriteId 
) [static]

Adds a tk2dBaseSprite derived class as a component to the gameObject passed in, setting up necessary parameters and building geometry.

Type Constraints
T :tk2dBaseSprite 
static T tk2dBaseSprite.AddComponent< T > ( GameObject  go,
tk2dSpriteCollectionData  spriteCollection,
string  spriteName 
) [static]

Adds a tk2dBaseSprite derived class as a component to the gameObject passed in, setting up necessary parameters and building geometry. Shorthand using sprite name.

Type Constraints
T :tk2dBaseSprite 
abstract void tk2dBaseSprite.Build ( ) [pure virtual]

Rebuilds the mesh data for this sprite. Not usually necessary to call this, unless some internal states are modified.

Implemented in tk2dSlicedSprite, tk2dClippedSprite, tk2dTiledSprite, and tk2dSprite.

static GameObject tk2dBaseSprite.CreateFromTexture< T > ( Texture  texture,
tk2dSpriteCollectionSize  size,
Rect  region,
Vector2  anchor 
) [static]

Create a sprite (and gameObject) displaying the region of the texture specified. Use tk2dSpriteCollectionData.CreateFromTexture if you need to create a sprite collection with multiple sprites.

Type Constraints
T :tk2dBaseSprite 

Gets the local space bounds of the sprite.

Returns:
Local space bounds

Gets the current sprite definition.

Returns:
tk2dSpriteDefinition for the currently active sprite.
int tk2dBaseSprite.GetSpriteIdByName ( string  name)

Resolves a sprite name and returns a unique id for the sprite. Convenience alias of tk2dSpriteCollectionData.GetSpriteIdByName

Returns:
Unique Sprite Id.
Parameters:
nameCase sensitive sprite name, as defined in the sprite collection. This is usually the source filename excluding the extension

Gets untrimmed local space bounds of the sprite. This is the size of the sprite before 2D Toolkit trims away empty space in the sprite. Use this when you need to position sprites in a grid, etc, when the trimmed bounds is not sufficient.

Returns:
Local space untrimmed bounds

Makes the sprite pixel perfect to the active camera. Automatically detects tk2dCamera if present Otherwise uses Camera.main.

virtual void tk2dBaseSprite.ReshapeBounds ( Vector3  dMin,
Vector3  dMax 
) [virtual]

Used for sprite resizing in Editor, and UILayout.

Reimplemented in tk2dSlicedSprite, tk2dClippedSprite, tk2dTiledSprite, and tk2dSprite.

void tk2dBaseSprite.SetSprite ( int  newSpriteId)

Sets the sprite by identifier.

bool tk2dBaseSprite.SetSprite ( string  spriteName)

Sets the sprite by name. The sprite will be selected from the current collection.

void tk2dBaseSprite.SetSprite ( tk2dSpriteCollectionData  newCollection,
int  newSpriteId 
)

Sets sprite by identifier from the new collection.

bool tk2dBaseSprite.SetSprite ( tk2dSpriteCollectionData  newCollection,
string  spriteName 
)

Sets sprite by name from the new collection.


Member Data Documentation

BoxCollider tk2dBaseSprite.boxCollider = null

Internal cached version of the box collider created for this sprite, if present.

MeshCollider tk2dBaseSprite.meshCollider = null

Internal cached version of the mesh collider created for this sprite, if present.


Property Documentation

Deprecation warning: the set accessor will be removed in a future version. Use SetSprite when you need to switch sprite collection.

Color tk2dBaseSprite.color [get, set]

Gets or sets the color.

Please note the range for a Unity Color is 0..1 and not 0..255.

Gets the current sprite definition.

Returns:
tk2dSpriteDefinition for the currently active sprite.
bool tk2dBaseSprite.FlipX [get, set]

Flips the sprite horizontally. Set FlipX to true to flip it horizontally. Note: The sprite itself may be flipped by the hierarchy above it or localScale These functions do not consider those cases.

bool tk2dBaseSprite.FlipY [get, set]

Flips the sprite vertically. Set FlipY to true to flip it vertically. Note: The sprite itself may be flipped by the hierarchy above it or localScale These functions do not consider those cases.

Vector3 tk2dBaseSprite.scale [get, set]

Gets or sets the scale.

Use the sprite scale method as opposed to transform.localScale to avoid breaking dynamic batching.

Gets or sets the sorting order The sorting order lets you override draw order for sprites which are at the same z position It is similar to offsetting in z - the sprite stays at the original position This corresponds to the renderer.sortingOrder property in Unity 4.3.

int tk2dBaseSprite.spriteId [get, set]

Gets or sets the sprite identifier.

The spriteId is a unique number identifying each sprite. Use GetSpriteIdByName to resolve an identifier from the current sprite collection.


Event Documentation

This event is called whenever a sprite is changed. A sprite is considered to be changed when the sprite itself is changed, or the scale applied to the sprite is changed.