Author Topic: Center Scroll View On Child  (Read 2182 times)

erre

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 6
    • View Profile
Center Scroll View On Child
« on: August 31, 2017, 03:14:19 AM »
Hi all,

I'm working using NGUI 3.11.4. I have a problem with CenterOnChild component.
I've attached it to a grid (under a scroll view panel).

In Awake() I spawn my object list and call CenterOnChild.Recenter() that initialize the CenterOnChild component.
In OnEnable() I refresh data in that page. After refresh I call CenterOn(myObjTransform).

The first time I enter in this page it doesn't work. After first time, everything works.

Is it the expected behaviour?

How can I fix this?

Thank you.

Best regards,
Andrea.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Center Scroll View On Child
« Reply #1 on: August 31, 2017, 10:27:28 AM »
Awake() is a place to initialize only the local component. You should not be doing anything that relates to other components. Move it to Start(). I usually do this:
  1. bool mStarted = false;
  2. void DoStuff () { ... }
  3. void Start () { mStarted = true; DoStuff(); }
  4. void OnEnable () { if (mStarted) DoStuff(); }

erre

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 6
    • View Profile
Re: Center Scroll View On Child
« Reply #2 on: August 31, 2017, 11:40:03 AM »
Ok, it makes sense to me. I'll try!

Thank you.