using UnityEngine; using UnityEditor; using System.Collections.Generic; namespace Lovatto.SceneLoader.Editor { [InitializeOnLoad] class bl_LoadingScreenStartUp { private const string ONE_TIME_KEY = "lovatto.loadingscreen.startup"; static bl_LoadingScreenStartUp() { if (PlayerPrefs.GetInt(ONE_TIME_KEY, 0) == 0) { EditorApplication.update += Update; } } [MenuItem("Window/Loading Screen/Add Levels")] public static void SetupLevelsOption() { Setup(); } //[MenuItem("Window/Lovatto/Loading Screen/Documentation")] public static void OpenDocumentation() { //deprecated Application.OpenURL("http://lovattostudio.com/documentations/loading-screen/"); } /// /// /// static void Update() { PlayerPrefs.SetInt(ONE_TIME_KEY, 1); EditorApplication.update -= Update; Setup(); } /// /// /// static void Setup() { bl_SceneLoaderManager sm = Resources.Load("SceneLoaderManager", typeof(bl_SceneLoaderManager)) as bl_SceneLoaderManager; if (sm == null) { Debug.Log("Can't load scenes"); return; } SceneData[] allscenes = SceneNames(); List scenes = new List(); scenes.AddRange(sm.List.ToArray()); for (int i = 0; i < allscenes.Length; i++) { if (scenes.Exists(x => x.SceneName == allscenes[i].Name)) { continue; } bl_SceneLoaderInfo info = new bl_SceneLoaderInfo(); info.SceneName = allscenes[i].Name; info.DisplayName = allscenes[i].Name; info.SceneAsset = AssetDatabase.LoadAssetAtPath(allscenes[i].Path, typeof(Object)) as Object; sm.List.Add(info); } Debug.Log("Scenes setup with success!"); Selection.objects = new UnityEngine.Object[] { sm }; EditorUtility.SetDirty(sm); EditorGUIUtility.PingObject(sm); } /// /// /// /// public static SceneData[] SceneNames() { List temp = new List(); foreach (EditorBuildSettingsScene S in EditorBuildSettings.scenes) { if (S.enabled) { SceneData sd = new SceneData(); string name = S.path.Substring(S.path.LastIndexOf('/') + 1); name = name.Substring(0, name.Length - 6); sd.Name = name; sd.Path = S.path; temp.Add(sd); } } return temp.ToArray(); } public class SceneData { public string Name; public string Path; } } }