Page 1 of 1

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
by ichijo
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.

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);
            }
        }
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.

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);
            }
        }
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

Re: Improvement proposal to the Portrait Native Size checkbox for get correct size when sprite is packed by Sprite Atlas

Posted: Tue Aug 09, 2022 8:26 am
by Tony Li
Thank you for the suggestion and for providing the code! I will definitely add this to version 2.2.31.

Re: Improvement proposal to the Portrait Native Size checkbox for get correct size when sprite is packed by Sprite Atlas

Posted: Wed Aug 10, 2022 10:58 am
by ichijo
Sounds great, thank you!