Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement