using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
public enum Scenetype
{
Login,//开始场景
Main//战斗场景
}
public class UILoadingView : MonoBehaviour
{
public static Scenetype scentype;
public Slider slider;
public Text text;
private AsyncOperation async;
void Start ()
{
if (scentype == Scenetype.Main)
{
async = SceneManager.LoadSceneAsync("Main");
}
else if (scentype == Scenetype.Login)
{
async = SceneManager.LoadSceneAsync("Login");
}
//异步跳转
// async = SceneManager.LoadSceneAsync(JianJie.Instance.Path_ );
async.allowSceneActivation = false;
}
private int progpress;
private int currprogpress;
void Update ()
{
OnTime();
}
public void OnTime()
{
if (async != null)
{
if (async.progress < 0.9)//跳转加载进度
{
//使加载不生硬
progpress = Mathf.Clamp((int)async.progress * 100, 1, 100);
}
else
{
progpress = 100;
}
if (currprogpress < progpress)
{
currprogpress++;
slider.value = currprogpress / 100.0f;
text.text = string.Format("{0}%", currprogpress );
}
else
{
slider.value = 1;
currprogpress = 100;
text.text = string.Format("{0}%", currprogpress);
async.allowSceneActivation = true;
}
}
}
}
异步跳转(跳转间接)------枚举在要跳转的Button中设置并跳转到缓冲场景
最新推荐文章于 2024-01-03 16:56:28 发布
这篇博客详细介绍了在Unity中如何使用UnityEngine.SceneManagement进行场景的异步加载,并通过UI Slider和Text组件实时显示加载进度。代码示例展示了如何在Login和Main两个场景间平滑切换,并通过限制场景激活来防止加载过程中的不必要操作。
5412

被折叠的 条评论
为什么被折叠?



