Author Topic: Disabled UIAnchor updates when window is resized  (Read 6238 times)

Simie

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 25
    • View Profile
Disabled UIAnchor updates when window is resized
« on: November 24, 2013, 05:58:45 PM »
NGUI 3.0.6 rc3

A disabled UIAnchor will Update() when the window is resized. Bug?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Disabled UIAnchor updates when window is resized
« Reply #1 on: November 24, 2013, 06:26:15 PM »
It's intentional. Anchors now disable themselves when "run only once" option is turned on instead of getting destroyed. They also listen to screen size changes, even when disabled.

Simie

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 25
    • View Profile
Re: Disabled UIAnchor updates when window is resized
« Reply #2 on: November 24, 2013, 06:36:55 PM »
I didn't have the "one only once" option enabled on those UIAnchors, though.

I also can't see any logic in UIAnchor.cs which would cause the documented behaviour, either. Looks like it would update whenever the screen is resized, regardless of the runOnlyOnce flag.
« Last Edit: November 24, 2013, 06:47:45 PM by Simie »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Disabled UIAnchor updates when window is resized
« Reply #3 on: November 24, 2013, 06:59:11 PM »
It happens because of UICamera.onScreenResize += Update; subscription.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Disabled UIAnchor updates when window is resized
« Reply #4 on: November 24, 2013, 07:01:06 PM »
You can change it to the following:
  1.         void Awake ()
  2.         {
  3.                 mTrans = transform;
  4.                 mAnim = animation;
  5.                 UICamera.onScreenResize += ScreenSizeChanged;
  6.         }
  7.  
  8.         void OnDestroy () { UICamera.onScreenResize -= ScreenSizeChanged; }
  9.  
  10.         void ScreenSizeChanged () { if (runOnlyOnce) Update(); }
..and it should do the trick for you.

Simie

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 25
    • View Profile
Re: Disabled UIAnchor updates when window is resized
« Reply #5 on: November 24, 2013, 07:03:58 PM »
Oh right, I thought the intended behaviour was to only respond to screen size changes when runOnlyOnce was true, not that it would always respond to screen size changes no matter what. It makes sense now, thanks.