Переделывание загрузки сцены
This commit is contained in:
parent
88e182c7c8
commit
dcbc536143
Binary file not shown.
Binary file not shown.
@ -0,0 +1,8 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: eb2ac3cb50a78dc4cbf5389d3450dc06
|
||||||
|
NativeFormatImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
mainObjectFileID: 4890085278179872738
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
@ -1,3 +1,4 @@
|
|||||||
|
using System.Collections;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using UnityEngine.SceneManagement;
|
using UnityEngine.SceneManagement;
|
||||||
|
|
||||||
@ -5,6 +6,32 @@ public class StartGameScript : MonoBehaviour
|
|||||||
{
|
{
|
||||||
public void StartGame()
|
public void StartGame()
|
||||||
{
|
{
|
||||||
SceneManager.LoadSceneAsync(StaticDataMap.SelectedMap);
|
StartCoroutine(LoadSceneAsync(StaticDataMap.SelectedMap, SceneManager.GetActiveScene().name));
|
||||||
|
Debug.Log("Çàãðóçêà");
|
||||||
|
}
|
||||||
|
private IEnumerator LoadSceneAsync(string newScene, string oldScene)
|
||||||
|
{
|
||||||
|
// Çàãðóæàåì íîâóþ ñöåíó àñèíõðîííî
|
||||||
|
AsyncOperation asyncLoad = SceneManager.LoadSceneAsync(newScene, LoadSceneMode.Additive);
|
||||||
|
|
||||||
|
// Îæèäàåì, ïîêà íîâàÿ ñöåíà ïîëíîñòüþ çàãðóçèòñÿ
|
||||||
|
while (!asyncLoad.isDone)
|
||||||
|
{
|
||||||
|
yield return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Äåëàåì çàãðóæåííóþ ñöåíó àêòèâíîé
|
||||||
|
SceneManager.SetActiveScene(SceneManager.GetSceneByName(newScene));
|
||||||
|
|
||||||
|
// Âûãðóæàåì ñòàðóþ ñöåíó
|
||||||
|
AsyncOperation asyncUnload = SceneManager.UnloadSceneAsync(oldScene);
|
||||||
|
|
||||||
|
// Îæèäàåì, ïîêà ñòàðàÿ ñöåíà ïîëíîñòüþ âûãðóçèòñÿ
|
||||||
|
while (!asyncUnload.isDone)
|
||||||
|
{
|
||||||
|
yield return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
Debug.Log("Ñöåíà " + oldScene + " âûãðóæåíà, à ñöåíà " + newScene + " çàãðóæåíà è àêòèâíà.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user