Author Topic: Simple anchor setup question  (Read 2355 times)

bac9

  • Full Member
  • ***
  • Thank You
  • -Given: 2
  • -Receive: 4
  • Posts: 113
    • View Profile
Simple anchor setup question
« on: October 09, 2014, 05:39:02 AM »
I was not able to figure it out from the documentation so I apologize if it is obvious. The question is: how can I (through code) set the reference points of Unified anchoring of a widget to Top/Bottom/Left/Right enum values that NGUI inspector UI always offers you to use? I have not found any argument like that in the SetAnchor method or among the properties of individual anchors, which leaves me reliant on rather ugly hack where I match the pixel dimensions and position of an anchored widget to those of it's parent and hope that NGUI auto-selects the appropriate reference mode on each of the four anchor points. It usually does, because mode I want has the closest relative offset (zero), but I'd rather avoid doing that.

I understand that those handy enums and Unified anchoring mode on the whole are probably just editor-side wrapping of underlying auto-generated Transforms and underlying Advanced anchoring mode, and I see the methods allowing you to set reference Transforms for anchors, but I'm not seeing any way to fetch those points in the first place. I can calculate the 4 corner points and 4 side midpoints myself, of course, and create my own transforms there, but that would be very dirty and I'd rather prefer to find a way to get a reference to existing ones.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Simple anchor setup question
« Reply #1 on: October 10, 2014, 02:18:02 AM »
widget.SetAnchor, or if you want individually -- widget.leftAnchor.Set, widget.rightAnchor.Set, etc.

P.S. If setting them individually, don't forget to call widget.ResetAndUpdateAnchors(); after you're done.

bac9

  • Full Member
  • ***
  • Thank You
  • -Given: 2
  • -Receive: 4
  • Posts: 113
    • View Profile
Re: Simple anchor setup question
« Reply #2 on: October 11, 2014, 03:57:20 AM »
Yes, I know about widget.*anchor.Set - but there is no overload that allows you to set up snapping to the left/right/top/bottom edge, only relative offset, absolute offset and optional transform you have to come up with yourself, supposedly. How can I get the Transform reference to the center of the left edge of a widget I'm anchoring to, for example? Without calculating that position from scratch, that is - it's possible to do so, but I suspect NGUI already calculates those points to present them in the custom inspector of the anchors.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Simple anchor setup question
« Reply #3 on: October 11, 2014, 04:52:02 AM »
Eh? The relative value is it. 0 means left, 0.5 means center, 1 means right. Check the documentation for the UIRect.

bac9

  • Full Member
  • ***
  • Thank You
  • -Given: 2
  • -Receive: 4
  • Posts: 113
    • View Profile
Re: Simple anchor setup question
« Reply #4 on: October 11, 2014, 04:58:28 AM »
Eh? The relative value is it. 0 means left, 0.5 means center, 1 means right. Check the documentation for the UIRect.
Oh, thanks, that's a relief, I assumed both were pixel offsets than had nothing to do with setting the point of origin. :)