All Classes Functions Variables Enumerations Properties Events
Public Types | Public Member Functions | Static Public Member Functions | Public Attributes | Properties
tk2dSlicedSprite Class Reference

Sprite implementation that implements 9-slice scaling. Doesn't support diced sprites. The interface takes care of sprite unit conversions for border[Top|Bottom|Left|Right]. More...

Inherits tk2dBaseSprite.

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

override void Build ()
 Rebuilds the mesh data for this sprite. Not usually necessary to call this, unless some internal states are modified.
void FlipX ()
 Flips the sprite horizontally.
void FlipY ()
 Flips the sprite vertically.
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 spriteId)
 Sets sprite by identifier from the new collection.
bool SetSprite (tk2dSpriteCollectionData newCollection, string spriteName)
 Sets sprite by name from the new collection.
void SwitchCollectionAndSprite (tk2dSpriteCollectionData newCollection, int newSpriteId)
 Switches the sprite collection and sprite. Simply set the spriteId property when you don't need to switch the sprite collection. This will be deprecated in a future release, use SetSprite instead.
bool SwitchCollectionAndSprite (tk2dSpriteCollectionData newCollection, string spriteName)
 Switches the sprite collection and sprite. Simply set the spriteId property when you don't need to switch the sprite collection. This will be deprecated in a future release, use SetSprite instead.
void MakePixelPerfect ()
 Makes the sprite pixel perfect to the active camera. Automatically detects tk2dCamera if present Otherwise uses Camera.main.
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.

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, tk2dRuntime.SpriteCollectionSize 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

bool legacyMode = true
 Legacy mode (uses scale to adjust overall size). Newly created sprites should have this set to false.
float borderTop = 0.2f
 Top border in sprite fraction (0 - Top, 1 - Bottom)
float borderBottom = 0.2f
 Bottom border in sprite fraction (0 - Bottom, 1 - Top)
float borderLeft = 0.2f
 Left border in sprite fraction (0 - Left, 1 - Right)
float borderRight = 0.2f
 Right border in sprite fraction (1 - Right, 0 - Left)
bool pixelPerfect = false
 Specifies if this sprite is kept pixel perfect.
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

bool BorderOnly [get, set]
 Gets or sets border only. When true, the quad in the middle of the sliced sprite is omitted, thus only drawing a border and saving fillrate.
Vector2 dimensions [get, set]
 Gets or sets the dimensions.
Anchor anchor [get, set]
 The anchor position for this sliced sprite.
bool CreateBoxCollider [get, set]
 Create a trimmed box collider for this sprite.
tk2dSpriteCollectionData Collection [get, set]
 Deprecation warning: the set accessor will be removed in a future version. Use SwitchCollectionAndSprite 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 spriteId [get, set]
 Gets or sets the sprite identifier.
tk2dSpriteDefinition CurrentSprite [get]
 Gets the current sprite definition.

Detailed Description

Sprite implementation that implements 9-slice scaling. Doesn't support diced sprites. The interface takes care of sprite unit conversions for border[Top|Bottom|Left|Right].


Member Enumeration Documentation

enum tk2dBaseSprite.Anchor [inherited]

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, inherited]

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, inherited]

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 
override void tk2dSlicedSprite.Build ( ) [virtual]

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

Implements tk2dBaseSprite.

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

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 
void tk2dBaseSprite.FlipX ( ) [inherited]

Flips the sprite horizontally.

void tk2dBaseSprite.FlipY ( ) [inherited]

Flips the sprite vertically.

Bounds tk2dBaseSprite.GetBounds ( ) [inherited]

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) [inherited]

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
Bounds tk2dBaseSprite.GetUntrimmedBounds ( ) [inherited]

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
void tk2dBaseSprite.MakePixelPerfect ( ) [inherited]

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

void tk2dBaseSprite.SetSprite ( int  newSpriteId) [inherited]

Sets the sprite by identifier.

bool tk2dBaseSprite.SetSprite ( string  spriteName) [inherited]

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

void tk2dBaseSprite.SetSprite ( tk2dSpriteCollectionData  newCollection,
int  spriteId 
) [inherited]

Sets sprite by identifier from the new collection.

bool tk2dBaseSprite.SetSprite ( tk2dSpriteCollectionData  newCollection,
string  spriteName 
) [inherited]

Sets sprite by name from the new collection.

void tk2dBaseSprite.SwitchCollectionAndSprite ( tk2dSpriteCollectionData  newCollection,
int  newSpriteId 
) [inherited]

Switches the sprite collection and sprite. Simply set the spriteId property when you don't need to switch the sprite collection. This will be deprecated in a future release, use SetSprite instead.

Parameters:
newCollectionA reference to the sprite collection to switch to.
newSpriteIdNew sprite identifier.
bool tk2dBaseSprite.SwitchCollectionAndSprite ( tk2dSpriteCollectionData  newCollection,
string  spriteName 
) [inherited]

Switches the sprite collection and sprite. Simply set the spriteId property when you don't need to switch the sprite collection. This will be deprecated in a future release, use SetSprite instead.

Parameters:
newCollectionA reference to the sprite collection to switch to.
spriteNameSprite name.

Member Data Documentation

Bottom border in sprite fraction (0 - Bottom, 1 - Top)

Left border in sprite fraction (0 - Left, 1 - Right)

Right border in sprite fraction (1 - Right, 0 - Left)

Top border in sprite fraction (0 - Top, 1 - Bottom)

BoxCollider tk2dBaseSprite.boxCollider = null [inherited]

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

Legacy mode (uses scale to adjust overall size). Newly created sprites should have this set to false.

MeshCollider tk2dBaseSprite.meshCollider = null [inherited]

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

bool tk2dBaseSprite.pixelPerfect = false [inherited]

Specifies if this sprite is kept pixel perfect.


Property Documentation

The anchor position for this sliced sprite.

bool tk2dSlicedSprite.BorderOnly [get, set]

Gets or sets border only. When true, the quad in the middle of the sliced sprite is omitted, thus only drawing a border and saving fillrate.

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

Color tk2dBaseSprite.color [get, set, inherited]

Gets or sets the color.

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

Create a trimmed box collider for this sprite.

Gets the current sprite definition.

Returns:
tk2dSpriteDefinition for the currently active sprite.
Vector2 tk2dSlicedSprite.dimensions [get, set]

Gets or sets the dimensions.

Use this to change the dimensions of the sliced sprite in pixel units

Vector3 tk2dBaseSprite.scale [get, set, inherited]

Gets or sets the scale.

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

int tk2dBaseSprite.spriteId [get, set, inherited]

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.