Ngui should be considered the most common component in unity. Uisprite is a good comrade, hard to help the game engine to improve rendering efficiency. But I do not understand that the localsize of the transform component for Mao Uisprite is to be set to the original size of the picture in order to display it properly, why not let localsize = new Vector3 (1,1,1) just fine?
This also brings a problem, the game in a gameobject with a sprite when switching to other sprites, but also keep the original Sprite transform properties, so that some pictures may be in the process of switching to become disproportionate. For example, look at the following two pictures, the protagonist of our game after a change of action, because the size of the picture is inconsistent and has been stretched.
The localsize of the sprite is then reset every time you switch. Where can you know the size of the sprite, in fact, there is no relevant property in the Sprite component, this property is hidden in the sprite corresponding to the Altas. So, I wrote the following code. Specifically for resizing when switching sprites. The code is quite simple and should be easy to understand.
Using Unityengine;
Using System.Collections;
public class Spritehelper:monobehaviour
{
//adjust uisprite public
static void Adjustscale (Uisprite uisprite)
{
//based on Spritename find Sprite
uiatlas.sprite sprite = UiSprite.atlas.GetSprite in Uiatlas ( Uisprite.spritename);
UiSprite.transform.localScale = new Vector3 (sprite.outer.width, sprite.outer.height, 0);
}
Adjust uitexture public
static void Adjustscale (Uitexture uitexture)
{
Texture Texture = Uitexture.maintexture;
UiTexture.transform.localScale = new Vector3 (texture.width, texture.height, 0);
}
}
Okay, now it's a perfect solution.