Improvement proposal to the Portrait Native Size checkbox for get correct size when sprite is packed by Sprite Atlas.
Posted: Tue Aug 09, 2022 3:07 am
Hi Tony,
From the Dialogue System 2.2.23, you've added a nicely option the Portrait Native Size checkbox to Standard UI Subtitle Panel.
That works very good, but the current source code has a little problem when the sprite is included Atlas.
In the SetPortraitImage function the resize procedue uses sprite.texture.width, but the texture size means souce texture of packed one, so if the sprite is included in 1024 x 1024 the portlait image set to 1024 x 1024 not the original sprite size.
So I proposal this way below: check the sprite is packed and use sprite.rect.width if it packed.
I've added this modification for my usage,but if you feel its good for entire of the asset, please consider to pick this to next version.
Thanks,
Ichijo
From the Dialogue System 2.2.23, you've added a nicely option the Portrait Native Size checkbox to Standard UI Subtitle Panel.
That works very good, but the current source code has a little problem when the sprite is included Atlas.
Code: Select all
protected virtual void SetPortraitImage(Sprite sprite)
{
if (portraitImage == null) return;
Tools.SetGameObjectActive(portraitImage, sprite != null);
portraitImage.sprite = sprite;
if (usePortraitNativeSize && sprite != null)
{
portraitImage.rectTransform.sizeDelta = new Vector2(sprite.texture.width, sprite.texture.height);
}
}
So I proposal this way below: check the sprite is packed and use sprite.rect.width if it packed.
Code: Select all
protected virtual void SetPortraitImage(Sprite sprite)
{
if (portraitImage == null) return;
Tools.SetGameObjectActive(portraitImage, sprite != null);
portraitImage.sprite = sprite;
if (usePortraitNativeSize && sprite != null)
{
portraitImage.rectTransform.sizeDelta = sprite.packed ?
new Vector2(sprite.rect.width, sprite.rect.height) :
new Vector2(sprite.texture.width, sprite.texture.height);
}
}
Thanks,
Ichijo