Tasharen Entertainment Forum

Support => NGUI 3 Support => Topic started by: yuewah on July 20, 2012, 05:30:09 AM

Title: UIAnchor and UIStretch option to only run in Start()
Post 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.
Title: Re: UIAnchor and UIStretch option to only run in Start()
Post by: Xanatus on July 20, 2012, 11:17:10 AM
UIAnchor and UIStretch only update if positions/scales change.
And if you target a single resolution, why use stretch and anchor at all?
Title: Re: UIAnchor and UIStretch option to only run in Start()
Post by: yuewah on July 20, 2012, 12:41:44 PM
It supports iphone and iPad resolution, but it will not resize/change the resolution during the gameplay.
Title: Re: UIAnchor and UIStretch option to only run in Start()
Post by: vip_prizrak_3 on May 30, 2013, 06:59:07 AM
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.
Title: Re: UIAnchor and UIStretch option to only run in Start()
Post by: dlewis on May 30, 2013, 07:51:00 AM
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)
Title: Re: UIAnchor and UIStretch option to only run in Start()
Post by: ArenMook on May 30, 2013, 03:53:28 PM
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...
Title: Re: UIAnchor and UIStretch option to only run in Start()
Post by: ArenMook on May 30, 2013, 03:58:19 PM
I've added an option for it to the UIAnchor. You will see it in the next update.
Title: Re: UIAnchor and UIStretch option to only run in Start()
Post by: vip_prizrak_3 on May 31, 2013, 04:50:11 AM
Thanks)
Title: Re: UIAnchor and UIStretch option to only run in Start()
Post by: regeter on August 31, 2013, 03:52:39 PM
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.
Title: Re: UIAnchor and UIStretch option to only run in Start()
Post by: Nicki on August 31, 2013, 08:23:21 PM
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.
Title: Re: UIAnchor and UIStretch option to only run in Start()
Post by: regeter on September 04, 2013, 09:47:09 AM
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.
Title: Re: UIAnchor and UIStretch option to only run in Start()
Post by: regeter on September 04, 2013, 09:49:00 AM
In the scene view they look ok, but in the actual game they now are out of place.
Title: Re: UIAnchor and UIStretch option to only run in Start()
Post by: Nicki on September 04, 2013, 06:12:22 PM
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.
Title: Re: UIAnchor and UIStretch option to only run in Start()
Post by: regeter on September 04, 2013, 08:36:01 PM
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.
Title: Re: UIAnchor and UIStretch option to only run in Start()
Post by: ArenMook on September 05, 2013, 05:09:59 AM
Note that you still have nested anchors. You have the "Anchor" game object, and then your buttons have their own anchors.
Title: Re: UIAnchor and UIStretch option to only run in Start()
Post by: regeter on September 05, 2013, 09:49:57 AM
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.