异步加载场景loading界面

本文介绍了一个使用Unity实现的加载界面示例,通过`Loading`和`LoadingScene`两个类来异步加载场景。在`Loading`类中,利用`SceneManager.LoadSceneAsync`进行异步加载,并更新加载进度。同时,`LoadingScene`类提供了单例模式来设置加载场景的名称和提示信息。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
public class Loading : MonoBehaviour
{
	public Text tipsText;
	public GameObject circle;
	private float fps = 10.0f;
	private float time;
	private int nowFram;
	AsyncOperation async;
	int progress = 0;

	void Start()
	{
		//tipsText.text = LoadingScene.Instance.Tips;
		StartCoroutine(LoadScene());
	}
	IEnumerator LoadScene()
	{
		yield return new WaitForSeconds(3f);
		async = SceneManager.LoadSceneAsync(LoadingScene.Instance.LoadName);
		yield return async;
	}

	void OnGUI()
	{
		//DrawAnimation();
	}

	void Update()
	{
		//circle.transform.Rotate(Vector3.back);
		//progress = (int)(async.progress * 100);
	}
	void DrawAnimation()
	{

		time += Time.deltaTime;

		if (time >= 1.0 / fps)
		{

			nowFram++;

			time = 0;

		}
		GUI.Label(new Rect(100, 180, 300, 60), "lOADING" + progress);

	}

}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class LoadingScene
{
	private static LoadingScene instance;

	public static LoadingScene Instance
	{
		get 
		{
			if(instance == null)
			{
				instance = new LoadingScene();
			}
			return instance; 
		}
	}
	private string loadName;

	public string LoadName
	{
		get { return loadName; }
		set { loadName = value; }
	}

	public string Tips
	{
		get { return tips; }
	}

	private string tips;
	public void LoadAsyncScene(string nextScene)
	{
		
		//tips = tip;
		loadName = nextScene;
		SceneManager.LoadScene("LoadingScene");
	}
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值