Hello Guest

Author Topic: Adding objects to a Scrollable Area through code  (Read 3341 times)

GorillaOne

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 5
    • View Profile
Adding objects to a Scrollable Area through code
« on: February 11, 2014, 06:28:39 am »
 I am currently using a ScrollableArea_Vertical prefab with an attached Scrollbar. My desired functionality is to start the program with no objects added to the ScrollableArea_Vertical content object, but to add them through script later. The challenge is that when Unity starts and the ScrollableArea_Vertical has no objects in it's content area, it disables the Scrollbar.

What is the best way to add objects to the ScrollableArea_Vertical in script during runtime and activate the Scrollbar for normal use? I have attempted to call

(pseudo code)
tk2dUIScrollableAreaObject.MeasureContentLenghth();
Scrollbar.SetActive(true);

No apparent results.

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Adding objects to a Scrollable Area through code
« Reply #1 on: February 11, 2014, 09:35:43 am »
as the docs say - measure content length just measures the length of the content and returns it. Its up to you to set it, after adding whatever amount of padding you need.
eg.
scrollableArea.ContentLength = MeasureContentLength() + padding;
You don't need to set the scrolbar manually

GorillaOne

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: Adding objects to a Scrollable Area through code
« Reply #2 on: February 11, 2014, 11:22:40 pm »
Thanks for the info.