From 40d32e1919f8ea180c753820128727e751010199 Mon Sep 17 00:00:00 2001 From: Sinai Date: Fri, 16 Apr 2021 18:37:26 +1000 Subject: [PATCH] cleanup scene loader, redundant code --- src/ExplorerCore.cs | 2 +- src/UI/Panels/SceneExplorer.cs | 85 ++++++++++++++++------------------ 2 files changed, 41 insertions(+), 46 deletions(-) diff --git a/src/ExplorerCore.cs b/src/ExplorerCore.cs index 3df602a..faa13ac 100644 --- a/src/ExplorerCore.cs +++ b/src/ExplorerCore.cs @@ -13,7 +13,7 @@ namespace UnityExplorer public class ExplorerCore { public const string NAME = "UnityExplorer"; - public const string VERSION = "3.3.12"; + public const string VERSION = "3.4.0"; public const string AUTHOR = "Sinai"; public const string GUID = "com.sinai.unityexplorer"; diff --git a/src/UI/Panels/SceneExplorer.cs b/src/UI/Panels/SceneExplorer.cs index 5b7510e..2bf8f91 100644 --- a/src/UI/Panels/SceneExplorer.cs +++ b/src/UI/Panels/SceneExplorer.cs @@ -248,53 +248,48 @@ namespace UnityExplorer.UI.Panels // Scene Loader try { - Type sceneUtil = ReflectionUtility.GetTypeByName("UnityEngine.SceneManagement.SceneUtility"); - if (sceneUtil == null) - throw new Exception("This version of Unity does not ship with the 'SceneUtility' class, or it was not unstripped."); - var method = sceneUtil.GetMethod("GetScenePathByBuildIndex", ReflectionUtility.AllFlags); - - var title2 = UIFactory.CreateLabel(content, "SceneLoaderLabel", "Scene Loader", TextAnchor.MiddleLeft, Color.white, true, 14); - UIFactory.SetLayoutElement(title2.gameObject, minHeight: 25, flexibleHeight: 0); - - var allSceneDropObj = UIFactory.CreateDropdown(content, out Dropdown allSceneDrop, "", 14, null); - UIFactory.SetLayoutElement(allSceneDropObj, minHeight: 25, minWidth: 150, flexibleWidth: 0, flexibleHeight: 0); - - int sceneCount = SceneManager.sceneCountInBuildSettings; - for (int i = 0; i < sceneCount; i++) + if (SceneHandler.WasAbleToGetScenesInBuild) { - var scenePath = (string)method.Invoke(null, new object[] { i }); - allSceneDrop.options.Add(new Dropdown.OptionData(Path.GetFileNameWithoutExtension(scenePath))); + var loaderTitle = UIFactory.CreateLabel(content, "SceneLoaderLabel", "Scene Loader", TextAnchor.MiddleLeft, Color.white, true, 14); + UIFactory.SetLayoutElement(loaderTitle.gameObject, minHeight: 25, flexibleHeight: 0); + + var allSceneDropObj = UIFactory.CreateDropdown(content, out Dropdown allSceneDrop, "", 14, null); + UIFactory.SetLayoutElement(allSceneDropObj, minHeight: 25, minWidth: 150, flexibleWidth: 0, flexibleHeight: 0); + + foreach (var scene in SceneHandler.AllSceneNames) + allSceneDrop.options.Add(new Dropdown.OptionData(scene)); + + allSceneDrop.value = 1; + allSceneDrop.value = 0; + + var buttonRow = UIFactory.CreateHorizontalGroup(content, "LoadButtons", true, true, true, true, 4); + + var loadButton = UIFactory.CreateButton(buttonRow, "LoadSceneButton", "Load (Single)", () => + { + try + { + SceneManager.LoadScene(allSceneDrop.options[allSceneDrop.value].text); + } + catch (Exception ex) + { + ExplorerCore.LogWarning($"Unable to load the Scene! {ex.ReflectionExToString()}"); + } + }, new Color(0.1f, 0.3f, 0.3f)); + UIFactory.SetLayoutElement(loadButton.gameObject, minHeight: 25, minWidth: 150); + + var loadAdditiveButton = UIFactory.CreateButton(buttonRow, "LoadSceneButton", "Load (Additive)", () => + { + try + { + SceneManager.LoadScene(allSceneDrop.options[allSceneDrop.value].text, LoadSceneMode.Additive); + } + catch (Exception ex) + { + ExplorerCore.LogWarning($"Unable to load the Scene! {ex.ReflectionExToString()}"); + } + }, new Color(0.1f, 0.3f, 0.3f)); + UIFactory.SetLayoutElement(loadAdditiveButton.gameObject, minHeight: 25, minWidth: 150); } - allSceneDrop.value = 1; - allSceneDrop.value = 0; - - var buttonRow = UIFactory.CreateHorizontalGroup(content, "LoadButtons", true, true, true, true, 4); - - var loadButton = UIFactory.CreateButton(buttonRow, "LoadSceneButton", "Load (Single)", () => - { - try - { - SceneManager.LoadScene(allSceneDrop.options[allSceneDrop.value].text); - } - catch (Exception ex) - { - ExplorerCore.LogWarning($"Unable to load the Scene! {ex.ReflectionExToString()}"); - } - }, new Color(0.1f, 0.3f, 0.3f)); - UIFactory.SetLayoutElement(loadButton.gameObject, minHeight: 25, minWidth: 150); - - var loadAdditiveButton = UIFactory.CreateButton(buttonRow, "LoadSceneButton", "Load (Additive)", () => - { - try - { - SceneManager.LoadScene(allSceneDrop.options[allSceneDrop.value].text, LoadSceneMode.Additive); - } - catch (Exception ex) - { - ExplorerCore.LogWarning($"Unable to load the Scene! {ex.ReflectionExToString()}"); - } - }, new Color(0.1f, 0.3f, 0.3f)); - UIFactory.SetLayoutElement(loadAdditiveButton.gameObject, minHeight: 25, minWidth: 150); } catch (Exception ex) {