Skip to content

Instantly share code, notes, and snippets.

@kalineh
Created March 14, 2019 22:34
Show Gist options
  • Save kalineh/35e3401a6690996ef792409c8a418353 to your computer and use it in GitHub Desktop.
Save kalineh/35e3401a6690996ef792409c8a418353 to your computer and use it in GitHub Desktop.
AutoSceneAdditiveLoad.cs
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