Advertisement
Guest User

Untitled

a guest
Mar 19th, 2019
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.02 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.SceneManagement;
  5.  
  6. public class AutoSceneAdditiveLoad
  7. : MonoBehaviour
  8. {
  9. public Object sceneObj;
  10.  
  11. public void Start()
  12. {
  13. DontDestroyOnLoad(this.gameObject);
  14. StartCoroutine(DoLoadScene());
  15. }
  16.  
  17. public void OnValidate()
  18. {
  19. #if UNITY_EDITOR
  20. if (sceneObj != null)
  21. {
  22. var sceneAsset = sceneObj as UnityEditor.SceneAsset;
  23. if (sceneAsset == null)
  24. sceneObj = null;
  25. }
  26. #endif
  27. }
  28.  
  29. private IEnumerator DoLoadScene()
  30. {
  31. Debug.LogFormat("AutoSceneTransition: loading scene {0}", sceneObj.name);
  32.  
  33. var time = System.DateTime.Now;
  34. var async = SceneManager.LoadSceneAsync(sceneObj.name, LoadSceneMode.Single);
  35.  
  36. while (!async.isDone)
  37. yield return null;
  38.  
  39. var delta = System.DateTime.Now - time;
  40.  
  41. Debug.LogFormat("AutoSceneTransition: > load complete ({0:F2}s)", (float)delta.Seconds);
  42. }
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement