Adding sliders at runtime

0 votes
asked Apr 9, 2016 in Issue by vadya_rus (210 points)

Hello,

I'm having trouble getting my sliders to look right when creating them from a prefab at runtime. In my script I have the minValue, maxValue and current value variables set to the values that I need for that particular slider upon instantiating. The issue is that the slider fill area and handle positions aren't displaying properly as shown in the image below.

So my question is if there is any way to fix this issue. Or maybe I'm assigning the variables improperly.

I am using plugin version 1.1.3

Thank you!

1 Answer

+1 vote
answered Apr 20, 2016 by vadya_rus (210 points)
selected Apr 21, 2016 by admin
 
Best answer

I figured it out! It turns out that I was setting the values on the Unity slider component directly which wasn't affecting the MaterialUI Slider component's current value. I managed to fix this by calling OnSliderValueChanged () in the Start function of the script. Below is a small snippet of the solution in the context of code.

 

public MaterialSlider materialSlider;

public float minValue;
public float maxValue;
public float currentValue;

void Start () {
// This bit was all that was needed to make sure that 
// the sliders looked proper when the options menu first opens up.
    materialSlider.OnSliderValueChanged (materialSlider.slider.value);
}

// Called when fields are first instantiated from the menu manager script 
// and whenever settings values are loaded from the disk.
public void ResetValues () {
    materialSlider.slider.minValue = minValue;
	materialSlider.slider.maxValue = maxValue;
	materialSlider.slider.value = currentValue;
}

 

commented Apr 21, 2016 by admin (31,720 points)
Glad you worked the issue out! Documentation (when it's complete and released) will certainly help make things like this a tad more clear. Also, apologies for not answering sooner.

I am planning on (one day) creating a helper class that will make instantiating MaterialUI elements far easier :)

~ Declan.
Welcome to MaterialUI support! Ask us anything :)
...