The editor extension is only for learning and testing, remove it from your object, it’s slow and you don’t need it. To keep the pivot on the lower left corner when the screen changes size you need to call SetPivotPosition again after the screen changed size. You can call it inside the Update and that should also work fine.
It is way too slow to use for a game.
I have a simple problem.
One canvas.
A window(just a panel) with an icon (image) inside of it.
A tooltip(just a panel) that I need to move to the position of the icon.
The tooltip is a child of the canvas, the icon is a child of the window panel.
I added “Rect Transform Extended” to both tooltip panel and icon.
I set both to Rect control-As Child Of Canvas.
Now it the editor I copy the position of the icon and paste it into the position of the panel.
Then nothing happens, well at least not for 15 to 30 seconds.
Don’t use Rect Transform Extended, is just for learning, it’s very slow, this is a tool to use from code.
But I don’t understand your problem, it hangs for 30 seconds? that is not normal. Are you sure the cause of that is Rect Transform Extended? because I don’t see how is that possible, first time I hear something like that.
Hey man, just bought your asset so real quick question about getting a target position.
I have a ui element that I need to move off screen, so cool “transform.SetAnchorsPositionX(0f, AnchorsCoordinateSystem.OutsideCanvas);” gets my element off screen.
But I need to animate this position so I need to get the position without moving the element first, then tween it.
I can create a extension to do this no problem, but before I do that I was wondering if there was already a way to do it that I just haven’t noticed?
Cheers.
No, there is nothing made for that. If you are using something like doTween to animate you don’t need to create a component, but if you are using something like the Unity animator timeline, then yes, that is the way to go.
yeah i’m using a tweening engine to animate things, not the timeline. So I need to get the position before I can tween it. that’s where my issue is, transform.SetAnchorsPositionX doesn’t return anything, just sets its position. I need to get the position and set it myself.
i’ve hacked together a quick solution by just creating a dummy transform, applying the offscreen positioning logic and using that position to animate my target transform. It’d just be nice if I could get the position from a API.
Hi, is this some kind of bug or is there something I’m doing wrong:
-
Create Canvas
-
Create Panel (inside Canvas)
-
Create Button (inside panel)
-
Add “RectTransformExtended” component to both Panel and Button
-
Change Panels rect control coordinates to “As Child Of Canvas Normalized”
-
Change Panels “Size > Width” to 0.5
…Now the button is gone, and there is error message “Look rotation viewing vector is zero”???
transform.GetAnchorsPosition().x is what you need.
That is a Unity internal bug, reload the scene (you can save) do it again and it should work. It happens without using this tool.
Hello. I would like to have a sliced image to look consistently across different screen resolutions. I’m not using the Canvas Scaler component. Currently I’m using your SetWidth() and SetHeight(), but as you can see, image borders look different depending on screen resolution (see attached images from resolutions 640x480 and 400x2500). What did I miss?
public RectTransform image1RT;
public RectTransform image2RT;
public Vector2 screenSize;
void Start ()
{
unitsPerUiPixel = UnitsPerUiPixel(Camera.main);
Vector2 screenSize = Layout.GetOrthographicCameraSize(Camera.main) / unitsPerUiPixel;
image1RT.SetWidth(screenSize.x / 2f);
image1RT.SetHeight(screenSize.y / 5f);
image2RT.SetWidth(screenSize.x / 4f);
image2RT.SetHeight(screenSize.y / 5f);
}
The result in the screenshots looks fine to me according to the code you posted. If you set the size of the object to be proportional to the size if the screen like in the code you posted, it will look different on each screen (proportional), if you want the elements to be the same size in all the screens you need a totally different thing. You need the Canvas Scaler and you need to configure it in “Constant Physical Size”, then you have to move and resize stuff using units and never pixels.
If your target is a mobile device remember that the Unity IDE does not let you to realy preview the different screen sizes inside the Unity IDE because it does not have a DPI size emulation. (this feature was still on the roadmap the last time I checked). A workaround for this is to use this asset:
https://assetstore.unity.com/packages/tools/utilities/xarm-aspect-and-resolution-master-10563
Thank you for the quick reply! I’m not using Canvas Scaler in my project because it doesn’t coexist well with the rest of my UI code. Long story short, I’ll have to make it work without Canvas Scaler.
Just to clarify, I’m not looking for a constant physical size.
What I’m trying to accomplish should be pretty straightforward. For example: display a button that would take 1/10th of screen width and 1/5th of screen height. The button would have a border with thickness of 1/10 of the button height. This happens automatically if I use simple scaling for the button image, but doesn’t happen with sliced images. So, one solution would be to have separate button images for each aspect ratio of the button, but that can get out of hand really quick. Any suggestions?
Thanks for the asset, very cool. Been struggling with UI for some time now
Hello publisher,
I bought your asset. It’s very helpful. but I noticed that scripts in the asset have no namespace. I would be happy if you could add namespace for this asset.
Sorry for my English.
Thanks.