Tasharen Entertainment Forum
Support => NGUI 3 Support => Topic started by: yuewah on July 20, 2012, 05:30:09 AM
-
I found that UIAnchor and UIStretch will update its position on every frame. But for mobile device, it is not necessary, can you add an option to only run on Start()? I know it is easy to change to code, but I wish it can be officially support it.
-
UIAnchor and UIStretch only update if positions/scales change.
And if you target a single resolution, why use stretch and anchor at all?
-
It supports iphone and iPad resolution, but it will not resize/change the resolution during the gameplay.
-
It's a good idea. In Profiler UIAnchor.Update use 3-7% of CPU Usage.
I disable update after 2 seconds after the start, and CPU usage dropped to 0, and all elements are in their place.
UIAnchor.cs
bool alreaduInPosition = false;
void Start ()
{
...
Invoke("StopUpdate", 2.0f);
}
void StopUpdate()
{
alreaduInPosition = true;
}
void Update ()
{
if (alreaduInPosition) return;
...
}
It would be very nice if had realized the possibility of disabling after the start.
-
I have also encountered an issue where UIAnchor would update every frame (lots of them), although it was always moving in the z axis which was weird. I moved off the project before I could do serious debugging of it (but I don't know how/why it would always move towards the camera in the z axis)
-
I can add an option to remove the UIAnchor after the Update has been called once, but this will prevent the elements from adjusting to screen resolution changes.
Ideally there should be some kind of an event within Unity that notifies of screen size changes...
-
I've added an option for it to the UIAnchor. You will see it in the next update.
-
Thanks)
-
I use 8 buttons that are using the anchors. Everything was great, but now I decided to check "Run only once" on each button. The end result that only some (5 out of the 8) of the buttons now gets correctly aligned. Should this not be per instance of the script?
I had to re-disable this, and everything is back to normal.
-
When you're nesting anchors, each anchor won't know who goes first, so you will get potentially weird movements if you let them turn off after only one frame.
Optimally, you'd run them downwards in the hierarchy once and then turn them off.
You can make your own script that runs each anchor's update() and sees if the position changed because of it, if it hasn't then destroy the anchor. Make sure you run this in the right order though.
-
Thank you for your help but I don't think they are in a hierarchy, they are siblings really.
(https://sites.google.com/site/regeter/home/UIAnchor.png)
You can see this pictures. Each corner has two circles. With this option enabled to just run once some of the circles are out of place.
-
In the scene view they look ok, but in the actual game they now are out of place.
-
Yeah, but I mean in the anchoring hierarchy. I assume one widget is anchored to the screen and then the others anchor to the other ones? Or how is that setup?
There's a chain of dependencies there that needs to be done in the correct order if you want to only run the anchor once.
-
no they are all anchored to the panel...
but you made me check the scene again and I found the issue.
The anchor script can assign a panel gameobject and I had this empty. Now I assigned the correct panel from the hierarchy and the "Run Only Once" option now works fine.
-
Note that you still have nested anchors. You have the "Anchor" game object, and then your buttons have their own anchors.
-
Correct, I also removed that anchor during my review. This anchor was auto created, but when I removed it noticed no ill effect.
Thanks for all the help.