Author Topic: [NGUI 3.5.5] UIAnchor OnScreenSizeChanged  (Read 3532 times)

timsk

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 2
    • View Profile
[NGUI 3.5.5] UIAnchor OnScreenSizeChanged
« on: April 18, 2014, 01:58:51 PM »
Hi,

We are making good use of the new anchoring system but are running into performance issues.

90% of our anchored widgets only need to update their anchors when the screen size changes. I'm going to be adding an option to UIAnchor to only update when it receives OnScreenSizeChanged from Unity. Before I start doing this, are there any reasons why this is not an option already? Are there any pitfalls I might run into?

I just want to be careful, as I'm going to be making a big change to how anchors behave at the root class (UIRect), so any issues will affect everything in the UI.

Thanks.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: [NGUI 3.5.5] UIAnchor OnScreenSizeChanged
« Reply #1 on: April 18, 2014, 05:16:22 PM »
No need to modify anything. Use this helper script -- it's far easier.
  1. using UnityEngine;
  2.  
  3. public class ResolutionWatcher : MonoBehaviour
  4. {
  5.     void OnEnable () { UICamera.onScreenResize += OnResize; }
  6.     void OnDisable() { UICamera.onScreenResize -= OnResize; }
  7.     void OnResize () { UIRoot.Broadcast("UpdateAnchors"); }
  8. }
Leave the anchor update to be "OnEnable".

timsk

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 2
    • View Profile
Re: [NGUI 3.5.5] UIAnchor OnScreenSizeChanged
« Reply #2 on: April 18, 2014, 06:25:37 PM »
Glad i asked before doing it. Thanks a lot dude!