using System.Collections; using System.Collections.Generic; using PixelCrushers.Wrappers; using RootMotion; using UnityEngine; using UnityEngine.SceneManagement; public static class ProxySceneLoader// : MonoBehaviour { //private static ProxySceneLoader s_instance = null; private static string m_sceneToLoad; private const string EMPTY_SCENE_NAME = "Portal"; private static bool AUTO_LOAD = false; private static bool USE_PROXY_LOADER = true; /* public static ProxySceneLoader Instance { get { if (s_instance == null) { GameObject go = new GameObject("_ProxySceneLoader"); DontDestroyOnLoad(go); s_instance = go.AddComponent(); } return s_instance; } } */ public static void LoadScene(string name, bool directLoad = false) { if (USE_PROXY_LOADER && !directLoad) { m_sceneToLoad = name; SceneManager.sceneLoaded += OnSceneLoaded; SaveSystem.LoadScene(EMPTY_SCENE_NAME, false); } else { SaveSystem.LoadScene(name); } } public static void LoadSelectedScene() { SaveSystem.LoadScene(m_sceneToLoad); m_sceneToLoad = ""; } private static void OnSceneLoaded(Scene scene, LoadSceneMode arg1) { Resources.UnloadUnusedAssets(); if (scene.name.Equals(EMPTY_SCENE_NAME)) { if (AUTO_LOAD) { LoadSelectedScene(); } } SceneManager.sceneLoaded -= OnSceneLoaded; } }