Skip to content

This is a script that reproduces the sprite's position and scale at any aspect ratio in Unity.

License

Notifications You must be signed in to change notification settings

Kilimanjaro-a2/SpritePositionAdjuster

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

24 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SpritePositionAdjuster

日本語版README

Description

This script preserves the sprite's position and scale and can reproduce the same look even if the aspect ratio or height of the screen changes.

GifAnimation

Demo

This is a demo built with WebGL.

By changing the browser window height,

sprites will change position and size from the original.

However, the sprite with this script applied (Adjusted Sprite) does not change position and scales.

https://kilimanjaro-a2.github.io/SpritePositionAdjuster/

Usage

Initial Setting

On the UnityEditor, place a sprite in the scene with an arbitrary aspect ratio, and set the position and scale.

Then attach SpritePositionAdjuster.cs to the GameObject which has the SpriteRenderer component.

When you start the scene, the current GameView height is displayed on the console.

Current screen height is: 726. If you want to preserve current scale and position of this sprites, set originalHeight property 726 and restart the scene to check whether it works correctly.

ScreenShot

Set the height value displayed in the console for the OriginalScreenHeight of the SpritePositionAdjuster from the Inspector (726 in this case).

ScreenShot

That's it. The initial setting has been completed.

After that, even if you change the aspect and height of the GameView,

the position and scale of the sprite set first are reproduced.

KeepsPositionUpdated

If KeepsPositionUpdate is set to true, Update will always monitor the screen size for changes,

if it has changed, adjust the sprite position and scale immediately.

If false, the screen size will only be checked when the scene is first started,

performance is improved compared to true.

The default value is true.

About

This is a script that reproduces the sprite's position and scale at any aspect ratio in Unity.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages