Author Topic: Scrollview, dynamic content and scale problem  (Read 4623 times)

Gaxil

  • Newbie
  • *
  • Thank You
  • -Given: 2
  • -Receive: 0
  • Posts: 7
    • View Profile
Scrollview, dynamic content and scale problem
« on: May 21, 2014, 10:48:48 AM »
Hi,

I'm trying to create a dynamic interface by instanciating prefabs I've made (sliders, checkboxes ...) and attaching them to a widget. It was working really well when no scrollview were involved, the anchors were resizing everything correctly.
But since I've parented my widget to a scrollview, I have a completely out of scale UI, like 300x bigger. Changing the transform scale in the inspector is working fine, but not by script.
If I'm doing the same thing manually in the editor, I can get everything to work fine, but it's quite screwed doing so by code, the problem is there as soon as I have to modify the parent of an instanciated prefab by code ...

Any idea how to solve this?

Thanks in advance ...

Gaxil

  • Newbie
  • *
  • Thank You
  • -Given: 2
  • -Receive: 0
  • Posts: 7
    • View Profile
Re: Scrollview, dynamic content and scale problem
« Reply #1 on: May 21, 2014, 11:28:34 AM »
By the way, I forget to mention that I've also tried to use NGUITools.MarkParentAsChanged() without any success (well, I got the exact same result).

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Scrollview, dynamic content and scale problem
« Reply #2 on: May 21, 2014, 12:25:26 PM »
You need to use NGUITools.AddChild to add children, not Instantiate. NGUI's UIRoot is scaled by 2 / Screen.height by default, which is a very small value. So your 300x300 widget becomes 300 / 2 * Screen.height, which is *huge*. NGUITools.AddChild resets the scale properly.

Gaxil

  • Newbie
  • *
  • Thank You
  • -Given: 2
  • -Receive: 0
  • Posts: 7
    • View Profile
Re: Scrollview, dynamic content and scale problem
« Reply #3 on: May 21, 2014, 02:02:59 PM »
Thank you very much, it works like a charm!