加载进度条的实时
Slider slider = GetComponment<Slideer>();
fload process = 0 ;
while(process < 1){
}
加载进度条的实时
Slider slider = GetComponment<Slideer>();
fload process = 0 ;
while(process < 1){
}
当前值 = Mathf.SmoothStep(当前值,目标值,时间)
类似LERP,平滑赋值
waitUntil(函数体),当函数体执行完毕,跳出循环。
public class SliderTest : MonoBehaviour {
// Use this for initialization
void Start () {
StartCoroutine(ChangeValue());
}
private IEnumerator ChangeValue()
{
Slider slider = GetComponent<Slider>();
float process = 0;
while (process < 1) {
process += 0.1f;
yield return new WaitUntil(() =>
{
slider.value = Mathf.SmoothStep(slider.value, process, 0.5f);
return process - slider.value <= 0.01f;
});
}
}
}
使Slider实现进度条的功能。
因为进度条进行的不光滑,所以还需要改进。
public class SliderTest : MonoBehaviour {
// Use this for initialization
void Start () {
StartCoroutine(ChangeValue());
}
private IEnumerator ChangeValue()
{
Slider slider = GetComponent<Slider>();
float process = 0;
while (process < 1) {
process += 0.1f;
yield return new WaitUntil(() =>
{
slider.value = Mathf.SmoothStep(slider.value, process, 0.5f);
return process - slider.value <= 0.01f;
});
}
}
}
WaitUntil
SmoothStep