Created
March 14, 2019 22:34
-
-
Save kalineh/35e3401a6690996ef792409c8a418353 to your computer and use it in GitHub Desktop.
AutoSceneAdditiveLoad.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections; | |
using System.Collections.Generic; | |
using UnityEngine; | |
using UnityEngine.SceneManagement; | |
public class AutoSceneAdditiveLoad | |
: MonoBehaviour | |
{ | |
public Object sceneObj; | |
public void Start() | |
{ | |
DontDestroyOnLoad(this.gameObject); | |
StartCoroutine(DoLoadScene()); | |
} | |
public void OnValidate() | |
{ | |
#if UNITY_EDITOR | |
if (sceneObj != null) | |
{ | |
var sceneAsset = sceneObj as UnityEditor.SceneAsset; | |
if (sceneAsset == null) | |
sceneObj = null; | |
} | |
#endif | |
} | |
private IEnumerator DoLoadScene() | |
{ | |
Debug.LogFormat("AutoSceneTransition: loading scene {0}", sceneObj.name); | |
var time = System.DateTime.Now; | |
var async = SceneManager.LoadSceneAsync(sceneObj.name, LoadSceneMode.Single); | |
while (!async.isDone) | |
yield return null; | |
var delta = System.DateTime.Now - time; | |
Debug.LogFormat("AutoSceneTransition: > load complete ({0:F2}s)", (float)delta.Seconds); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment