unity ngui怎么做视频播放进度条怎么赋值
发布网友
发布时间:2022-05-16 21:05
我来回答
共1个回答
热心网友
时间:2024-03-17 09:02
脚本
public GameObject BtnGaoLu;
public UISlider MyUISlider;
private bool isLoad=false;
private AsyncOperation async;
float progress = 0;
void Awake()
{
UIEventListener.Get(BtnGaoLu).onClick = fnChangeSence;
MyUISlider.alpha = 0;
}
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
//绘制进度条,但是由于时间太短,效果不好
if (isLoad)
{
MyUISlider.alpha = 1;
progress = Convert.ToSingle((async.progress.ToString("f2")));
if (progress > 0)
{
MyUISlider.GetComponent<UISlider>().value = progress+0.8f;
//此处添加0.8f是因为我只加载到85%就跳转了,为了达到进度条到达100*的效果,所以添加了0.8,是实际情况而定。
print(progress);
}
}
}
void fnChangeSence(GameObject obj)
{
StartCoroutine(fnLoadSence("Final_Scene"));
}
IEnumerator fnLoadSence(string strSenceName)
{
isLoad = true;
async = Application.LoadLevelAsync(strSenceName);
yield return async;
}