Thank you, this works!
So basically this is the same as the pivot for Sprite, right. At least, values are the same.
When setting y value I am subtracting from screenHeight because I am using top left coordinate system. (maybe it will be useful to someone)
If you use normal coordinate system, just remove "screenHeight -" part.
public float x {
get{
Vector3 topLeft = new Vector3(baseSprite.GetUntrimmedBounds().min.x, baseSprite.GetUntrimmedBounds().max.y,0);
return (new Vector3(transform.position.x, transform.position.y, transform.position.z) + topLeft).x;
}
set {
Vector3 topLeft = new Vector3(baseSprite.GetUntrimmedBounds().min.x, baseSprite.GetUntrimmedBounds().max.y,0);
transform.position = new Vector3(value, y, transform.position.z) - topLeft;
}
}
public float y {
get {
Vector3 topLeft = new Vector3(baseSprite.GetUntrimmedBounds().min.x, baseSprite.GetUntrimmedBounds().max.y,0);
return screenHeight - (new Vector3(transform.position.x, transform.position.y, transform.position.z) + topLeft).y;
}
set {
Vector3 topLeft = new Vector3(baseSprite.GetUntrimmedBounds().min.x, baseSprite.GetUntrimmedBounds().max.y,0);
transform.position = new Vector3(x, screenHeight - value, transform.position.z) - topLeft;
//transform.position = new Vector3 (transform.position.x, screenHeight-(value-offsetY+origin.y), transform.position.z);
}
}