Author Topic: change UIAnchor in script  (Read 6945 times)

harrisonpink

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 29
    • View Profile
change UIAnchor in script
« on: August 02, 2014, 08:25:53 PM »
Hey guys, I've searched everywhere for an answer, but have had no luck.

I've got an object with the following Anchor properties:

Target: UI Root
Left: Target's Left + 26
Right: Target's Left + 46
Bottom: Target's Top - 139
Bottom: Target's Top - 119

What I'd like to do is change this in script to:

Target: UI Root
Left: Target's Right - 46
Right: Target's Right - 26
Bottom: Target's Top - 139
Bottom: Target's Top - 119

However, I'm trying to understand the Side and pixelOffset settings with no luck.  Can anyone help?
« Last Edit: August 03, 2014, 03:24:03 AM by harrisonpink »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: change UIAnchor in script
« Reply #1 on: August 03, 2014, 09:36:10 AM »
What side and pixel offset settings? I'm not sure what you're referring to or how they relate to what you're trying to do.
  1. widget.leftAnchor.relative = 1; // 0 = left, 1 = right
  2. widget.leftAnchor.absolute = -46;
  3.  
  4. widget.rightAnchor.relative = 1;
  5. widget.rightAnchor.absolute = -26;
  6.  
  7. widget.ResetAndUpdateAnchors();

harrisonpink

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 29
    • View Profile
Re: change UIAnchor in script
« Reply #2 on: August 03, 2014, 09:17:13 PM »
I'm sorry, I don't quite understand what you're asking me. The sides are described above I thought? I've attached some images to help explain what I want to do.

I've tried coding something like this in c# as described here http://tasharen.com/ngui/docs/class_u_i_anchor.html but it hasn't worked.

  1. spriteAnchor = imageSprite.GetComponent<UIAnchor>();
  2.  
  3. spriteAnchor.pixelOffset = Vector2(-26, 0);
  4.  

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: change UIAnchor in script
« Reply #3 on: August 04, 2014, 10:03:57 AM »
UIAnchor is a legacy component from NGUI 2 days. It has nothing to do with NGUI 3's layout system that you see on widgets.

The code I posted is all you need. "widget" is your widget. Replace it with "imageSprite" in your case.

This is the documentation page you should be looking at: http://www.tasharen.com/forum/index.php?topic=7013.0

harrisonpink

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 29
    • View Profile
Re: change UIAnchor in script
« Reply #4 on: August 04, 2014, 01:59:39 PM »
Aha! That makes sense. Thank you for your help, I will play around with this and figure it out!