Author Topic: UIAnchor question  (Read 2596 times)

PapaWhiskey

  • Guest
UIAnchor question
« on: January 13, 2013, 01:34:33 PM »
maybe I'm missing something...

i'd have thought that if i made an empty game object, added a UIAnchor script to it, set that anchor to something other than center, that the gameobject would adjust it's transform, or maybe even do it "under the hood", but thats not the case it seems...if you do as i just described you still have to position the anchor yourself...so whats the point of the different types of anchors if you have to do the positioning manually anyways?

Nicki

  • Global Moderator
  • Hero Member
  • *****
  • Thank You
  • -Given: 33
  • -Receive: 141
  • Posts: 1,768
    • View Profile
Re: UIAnchor question
« Reply #1 on: January 13, 2013, 03:34:14 PM »
It should do just that.

PapaWhiskey

  • Guest
Re: UIAnchor question
« Reply #2 on: January 14, 2013, 11:06:08 AM »
It should do just that.

and as it doesnt...the solution is?

or what are the steps to creating an anchor if they're not as straightforward as what i did (in the UIAnchor sample scene)

Majicpanda

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 83
    • View Profile
Re: UIAnchor question
« Reply #3 on: January 14, 2013, 02:20:21 PM »
What's your hierarchy look like?
-Anchor_Middle
-- Panel
--- GameObject
---- Widgets

-Anchor_Top
-- Panel
--- GameObject
---- Widgets

PapaWhiskey

  • Guest
Re: UIAnchor question
« Reply #4 on: January 14, 2013, 02:23:54 PM »
Anchor - Center
   Panel
      anchors
      sprites
      labels
   Panel
     etc

from futzing around with some other windows we need done today...the anchor game object changing it's transform is hit and miss...i've been able to do it more than once where after picking one of the nine locations, the transform updates, but more often than not, the transform is not changing and is incorrect

Majicpanda

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 83
    • View Profile
Re: UIAnchor question
« Reply #5 on: January 14, 2013, 02:32:50 PM »
Paying close attention to making sure you are resetting the position of the anchors so they're zero'd out and also the GameObject that nests all the widgets? You cannot nest widgets themselves, so sometimes I overlook ensuring size and position of empty GameObject "containers" are zero'd out and size 1/1/1.. etc.

Your hierarchy appears fine.

Nicki

  • Global Moderator
  • Hero Member
  • *****
  • Thank You
  • -Given: 33
  • -Receive: 141
  • Posts: 1,768
    • View Profile
Re: UIAnchor question
« Reply #6 on: January 14, 2013, 04:35:35 PM »
The solution is doing it right instead of wrong.

If everything is set up correctly, your hierarchy:

Anchor - Center
   Panel
      anchors
      sprites
      labels
   Panel
     etc

Should put both panels in the center and the "anchors" object should be set to whichever corner/center you set it to in the inspector on first Update. Sprites and labels will be in the center as well, as they are not under a non-center anchor.

Make sure the anchor is in the same layer as your UICamera. Make sure you haven't set the anchor to use a widget or panel container.

Take screenshots of the anchor's transform values, if it changes weirdly and post here, maybe we can help you track this funky issue down. :)

robbb

  • Guest
Re: UIAnchor question
« Reply #7 on: January 14, 2013, 05:09:47 PM »
It could be that your anchors are picking up the wrong layer.

If you're just creating a new empty game object, dragging it in to the hierarchy and adding a UIAnchor, then your anchor object will end up on the default layer, and automatically pick up the 'Main Camera' object as its reference. In most people's cases this'll be wrong as they'll have their UI on a layer like 'GUI' or '2D'.

Check your UIAnchor objects layer and, if it's wrong, update it, then drag the UICamera for that UI over the anchor's 'UICamera' property.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UIAnchor question
« Reply #8 on: January 15, 2013, 07:04:29 AM »
NGUITools.AddChild should be used to add children as it sets up the layers for you. Or Alt+Shift+N shortcut with NGUI.