I can add a function to doing this to a normal "Sprite", but it isn't in the core as it can cause serious confusion when used with custom anchors, etc. The anchor and/or custom anchor is positioned in the sprite, so any dimension scaling is performed around that. Its fine when its one of the edges of the sprite, but when its custom you're gonna get weird rescaling.
And then add the fact that you can have a hierarchy with transform.localScale affecting it...
But thats not to say you can't have some code to do it
Here is a class extension to the base sprite class. Save it and drop it somewhere in your project to use it.
using UnityEngine;
using System.Collections;
public static class tk2dBaseSpriteExtension {
public static void SetSize(this tk2dBaseSprite sprite, Vector2 pixelSize) {
tk2dSpriteDefinition def = sprite.CurrentSprite;
Vector2 requestedSize = new Vector2( def.texelSize.x * pixelSize.x, def.texelSize.y * pixelSize.y );
Vector3 dimensions = def.untrimmedBoundsData[1];
Vector3 scale = new Vector3( requestedSize.x / dimensions.x, requestedSize.y / dimensions.y, 1 );
sprite.scale = scale;
}
public static Vector2 GetSourcePixelSize( this tk2dBaseSprite sprite ) {
tk2dSpriteDefinition def = sprite.CurrentSprite;
Vector3 dims = def.untrimmedBoundsData[1];
return new Vector2( dims.x / def.texelSize.x, dims.y / def.texelSize.y );
}
}