当前位置:网站首页>Unity development - scene asynchronous loading
Unity development - scene asynchronous loading
2022-06-22 06:02:00 【Xiao Zhang has to work hard every day】
Set up
scene A-> scene C, But the scene C Resources are too big , Jump scene will appear when loading jump directly C There was a Caton when I was , So when the scene is loaded , Make a scene B( Black screen effect ) The transition of , Not too embarrassing for Caton , So you need to implement the scenario A-> scene B-> scene C.
1、 Select the scene interface

among ButtonState Script ButtonState.cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
public class ButtonState : MonoBehaviour
{
[SerializeField]
private float localScale;
[SerializeField]
private float PointScale;
public void OnPointerEnter(PointerEventData eventData)// When the mouse enters UI Events executed after execution
{
transform.localScale = new Vector3(PointScale, PointScale, PointScale);
}
public void OnPointerExit(PointerEventData eventData)// When the mouse goes away UI Events executed after execution
{
transform.localScale = new Vector3(localScale, localScale, localScale);
}
public void OnDisable()
{
transform.localScale = new Vector3(localScale, localScale, localScale);
}
}
Two 、GameObject The script hanging above :GameController.cs

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class GameController : MonoBehaviour
{
public static List<LanguageScence> dic;
//public AudioSource AudioEffect;
public GameObject AudioBg;
public static int M;
private static bool Isplay = false;
private GameObject go;
private void Awake()
{
if (!Isplay)
{
go = Instantiate(AudioBg);// Play background music
}
}
// After choosing the language , Set variable value , Change the scene
public void SelectLanguage(string name)
{
switch (name)
{
case "Chinese":
M = 1;
SceneLoad();
break;
case "English":
M = 2;
SceneLoad();
break;
case "Finnish":
M = 3;
SceneLoad();
break;
}
}
// Scene conversion
void SceneLoad()
{
if (!Isplay)
{
DontDestroyOnLoad(go);
Isplay = true;
}
Debug.Log(" Go to the black ball scene first ");
SceneManager.LoadScene("loadScene");
}
}
3、 ... and 、 Scripts that need to be supported
①LanguageScence.cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class LanguageScence : MonoBehaviour
{
public List<string> ELanguageText = new List<string>();
}
②LanguageState.cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
//public class LanguageState : MonoBehaviour
//{
//}
public enum LanguageState//2 change class by enum Enumerated values
{
Chinese,
English,
Finnish
}
Four 、 Three jump scenes

5、 ... and 、 Dark scenes :loadScene

Dark scene script :
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class AsnyScene : MonoBehaviour
{
AsyncOperation async = null;
void Awake()
{
StartCoroutine(asynEvent(GameController.M));// Loading scenarios asynchronously
}
void Update()
{
}
IEnumerator asynEvent(int level)
{
Debug.Log(" The black curtain of the transition appears ");
yield return null;
AsyncOperation asyncOperation = SceneManager.LoadSceneAsync(level);// The scene is not superimposed
asyncOperation.allowSceneActivation = true;// Whether to allow jump after loading
}
}6、 ... and 、 summary
scene A-> scene B-> scene C when , Because the scene B( Dark scenes ) For scenes with small resources , So you can jump directly , It can be loaded directly , But the scene B-> scene C when , scene C There are many resource files , Cause slow loading , Therefore, asynchronous loading is adopted in the dark scene , therefore , scene A-> scene B( Dark scenes ) Use in :
SceneManager.LoadScene(" Black scene name or index ");Can , And in the scene B-> scene C when , Convert black scenes to scenes C when , Using asynchronous loading :
AsyncOperation asyncOperation = SceneManager.LoadSceneAsync(“ Scene name or scene index ”);// The scene is not superimposed
asyncOperation.allowSceneActivation = true;// Whether to allow jump after loading That is, when the scene is not loaded C when , Stay in the scene B in , In a dark scene , Solve the embarrassment of loading .
边栏推荐
- MFC tabctrl control to modify label size
- 北峰助力南昌市应急管理局打造公专融合应急通信保障网
- Network, IO flow, reflection, multithreading, exception
- Improve your game‘s performance
- Le contrôle MFC tabctrl modifie la taille de l'étiquette
- Improve your game‘s performance
- 常用CMOS模拟开关功能和原理
- Conversion between gray code and binary
- RGB, sRGB and XYZ coordinate conversion
- 爬虫初始及项目
猜你喜欢

Go language uses zap log Library

D3D10 screenshot function saves texture to local

vscode极简安装教程

基于CRU中的tmp数据进行年平均气温分析

从转载阿里开源项目 Egg.js 技术文档引发的“版权纠纷”,看宽松的 MIT 许可该如何用?

Le contrôle MFC tabctrl modifie la taille de l'étiquette

Machine learning note 7: powerful neural network representation

I2C interface

电热水壶坏了别扔,它很容易修好的!

Grabcut analysis
随机推荐
Using SystemVerilog to describe a state machine
Read and understand the four deep learning methods of supervised learning, unsupervised learning, semi supervised learning and intensive learning
爬虫初始及项目
Frame profiling
C指针的理解
Go语言使用zap日志库
P1061 [noip2006 popularization group] counting method of jam
Test platform composed of time sequence
MySQL basic interview questions
Remove then add string from variable of Makefile
基于CRU中的tmp数据进行年平均气温分析
MFC tabctrl control to modify label size
401-字符串(344. 反转字符串、541. 反转字符串II、题目:剑指Offer 05.替换空格、151. 颠倒字符串中的单词)
使用Systemverilog描述状态机
u盘作为启动盘重装win10系统(无需其他软件)
Vscode minimalist installation tutorial
为Cortex-M4编写优化的DSP代码
Xshell download and installation (solve the problem of expired evaluation)
System identification of automatic control principle
Beifeng helps Nanchang Emergency Management Bureau to build a public-private integrated emergency communication guarantee network