Support => NGUI 3 Support => Topic started by: Carbonite on June 18, 2014, 04:19:07 PM
Title: Advanced Anchors at runtime
Post by: Carbonite on June 18, 2014, 04:19:07 PM
I haven't been able to find anything on setting advanced anchors at runtime. SetAnchor seems to only setup a unified anchor. I added an overload to fix this. If it is the correct way, could we get it added to the next update?
/// <summary> /// Anchor this rectangle to the specified transform using an advanced anchor system. /// </summary>
Title: Re: Advanced Anchors at runtime
Post by: Carbonite on June 18, 2014, 04:33:32 PM
Well I just realized, if it's advanced, I will need to set the relatives as well. sorry for the confusion. Is this the correct way?
/// <summary> /// Anchor this rectangle to the specified transform using the advanced system. Relative values are a scale from 0 to 1, 0 being left/bottom, 1 being right/top. /// </summary>
Title: Re: Advanced Anchors at runtime
Post by: ArenMook on June 18, 2014, 05:57:09 PM
When function has that many parameters, it's generally better to reconsider writing it. You can set both relative and absolute on an anchor like so:
leftAnchor.target= target;
leftAnchor.Set(relative, absolute);
Title: Re: Advanced Anchors at runtime
Post by: Carbonite on June 18, 2014, 06:10:45 PM
copy. So use 8 lines of code for all four sides, plus the resetAnchor and UpdateAnchor calls instead of a beast of a function call. Was that anywhere in your tutorials? Sorry if it was, I looked for hours. Thanks for the reply.
Title: Re: Advanced Anchors at runtime
Post by: ArenMook on June 19, 2014, 05:51:06 PM
For now yeah. I actually added a single function for that that takes all 3 -- the target, relative and absolute that you will find in the next update. And yes, you still need to call ResetAnchors() and UpdateAnchors() afterwards.
Title: Re: Advanced Anchors at runtime
Post by: Carbonite on June 21, 2014, 04:00:01 AM
Thank you. I love your work btw. Making my life so much easier.