2D Toolkit Forum

2D Toolkit => Support => Topic started by: GorillaOne on February 11, 2014, 06:28:39 am

Title: Adding objects to a Scrollable Area through code
Post by: GorillaOne 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.
Title: Re: Adding objects to a Scrollable Area through code
Post by: unikronsoftware 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
Title: Re: Adding objects to a Scrollable Area through code
Post by: GorillaOne on February 11, 2014, 11:22:40 pm
Thanks for the info.