From ca34993eb3199d1d4cf98d7dd0f7d0a587df71ef Mon Sep 17 00:00:00 2001 From: Ejlersen Date: Fri, 17 Sep 2021 23:49:29 +0200 Subject: [PATCH] 0.7.2: Added asset bundle and addressable scenes to scene picker --- Editor/Module.NavigationTool.Editor.asmdef | 8 +- Editor/Toolbar/Tools/ToolScenePicker.cs | 137 ++++++++++++++++----- package.json | 7 +- 3 files changed, 115 insertions(+), 37 deletions(-) diff --git a/Editor/Module.NavigationTool.Editor.asmdef b/Editor/Module.NavigationTool.Editor.asmdef index 6d3509a..3e55a38 100644 --- a/Editor/Module.NavigationTool.Editor.asmdef +++ b/Editor/Module.NavigationTool.Editor.asmdef @@ -1,7 +1,9 @@ { "name": "Module.NavigationTool.Editor", - "rootNamespace": "", - "references": [], + "rootNamespace": "Module.NavigationTool.Editor", + "references": [ + "GUID:69448af7b92c7f342b298e06a37122aa" + ], "includePlatforms": [ "Editor" ], @@ -9,7 +11,7 @@ "allowUnsafeCode": false, "overrideReferences": false, "precompiledReferences": [], - "autoReferenced": true, + "autoReferenced": false, "defineConstraints": [], "versionDefines": [], "noEngineReferences": false diff --git a/Editor/Toolbar/Tools/ToolScenePicker.cs b/Editor/Toolbar/Tools/ToolScenePicker.cs index 932014f..6fbfbe8 100644 --- a/Editor/Toolbar/Tools/ToolScenePicker.cs +++ b/Editor/Toolbar/Tools/ToolScenePicker.cs @@ -2,6 +2,8 @@ using System.IO; using JetBrains.Annotations; using UnityEditor; +using UnityEditor.AddressableAssets; +using UnityEditor.AddressableAssets.Settings; using UnityEditor.SceneManagement; using UnityEngine; using UnityEngine.SceneManagement; @@ -25,38 +27,13 @@ namespace Module.NavigationTool.Editor.Tools return; EditorBuildSettingsScene[] scenes = EditorBuildSettings.scenes; - var listNames = new List(scenes.Length); - var listPaths = new List(scenes.Length); + var listNames = new List(); + var listPaths = new List(); - for (var i = 0; i < scenes.Length; i++) - { - if (string.IsNullOrEmpty(scenes[i].path)) - continue; - - listNames.Add($"{Path.GetFileNameWithoutExtension(scenes[i].path)} (Build Settings)"); - listPaths.Add(scenes[i].path); - } - - string[] guids = AssetDatabase.FindAssets("t:scene"); - int startIndex = listNames.Count; - - for (var i = 0; i < guids.Length; i++) - { - string path = AssetDatabase.GUIDToAssetPath(guids[i]); - var scene = AssetDatabase.LoadAssetAtPath(path); - - if (scene == null || listPaths.Contains(path)) - continue; - - listNames.Add(path.Substring(7, path.Length - 13).Replace('/', '\\')); - listPaths.Add(path); - } - - if (startIndex < listNames.Count) - { - listNames.Insert(startIndex, string.Empty); - listPaths.Insert(startIndex, string.Empty); - } + InitializeBuildSettingsScenes(listNames, listPaths); + InitializeAssetBundleScenes(listNames, listPaths); + InitializeAddressableScenes(listNames, listPaths); + InitializeRemainingScenes(listNames, listPaths); OPTIONS = listNames.ToArray(); PATHS = listPaths.ToArray(); @@ -65,6 +42,104 @@ namespace Module.NavigationTool.Editor.Tools SELECTED_INDEX = listPaths.IndexOf(activeScene.path); IS_DIRTY = false; } + + private static void InitializeBuildSettingsScenes(List listNames, List listPaths) + { + EditorBuildSettingsScene[] scenes = EditorBuildSettings.scenes; + + for (var i = 0; i < scenes.Length; i++) + { + if (string.IsNullOrEmpty(scenes[i].path)) + continue; + + listNames.Add($"{Path.GetFileNameWithoutExtension(scenes[i].path)} \tBuild settings"); + listPaths.Add(scenes[i].path); + } + } + + private static void InitializeAssetBundleScenes(List listNames, List listPaths) + { + string[] bundleNames = AssetDatabase.GetAllAssetBundleNames(); + int startIndex = listNames.Count; + + for (var i = 0; i < bundleNames.Length; i++) + { + string[] assetPaths = AssetDatabase.GetAssetPathsFromAssetBundle(bundleNames[i]); + + for (var j = 0; j < assetPaths.Length; j++) + { + string path = assetPaths[j]; + + if (listPaths.Contains(path)) + continue; + + var scene = AssetDatabase.LoadAssetAtPath(path); + + if (scene == null) + continue; + + listNames.Add($"{Path.GetFileNameWithoutExtension(path)} \tAsset bundle"); + listPaths.Add(path); + } + } + + if (startIndex >= listNames.Count) + return; + + listNames.Insert(startIndex, string.Empty); + listPaths.Insert(startIndex, string.Empty); + } + + private static void InitializeAddressableScenes(List listNames, List listPaths) + { + var assets = new List(); + AddressableAssetSettingsDefaultObject.Settings.GetAllAssets(assets, false); + int startIndex = listNames.Count; + + for (var i = 0; i < assets.Count; i++) + { + if (!(assets[i].MainAsset is SceneAsset)) + continue; + + string path = assets[i].AssetPath; + listNames.Add($"{Path.GetFileNameWithoutExtension(path)} \tAddressable"); + listPaths.Add(path); + } + + if (startIndex >= listNames.Count) + return; + + listNames.Insert(startIndex, string.Empty); + listPaths.Insert(startIndex, string.Empty); + } + + private static void InitializeRemainingScenes(List listNames, List listPaths) + { + string[] guids = AssetDatabase.FindAssets("t:scene"); + int startIndex = listNames.Count; + + for (var i = 0; i < guids.Length; i++) + { + string path = AssetDatabase.GUIDToAssetPath(guids[i]); + + if (listPaths.Contains(path)) + continue; + + var scene = AssetDatabase.LoadAssetAtPath(path); + + if (scene == null) + continue; + + listNames.Add(path.Substring(7, path.Length - 13).Replace('/', '\\')); + listPaths.Add(path); + } + + if (startIndex >= listNames.Count) + return; + + listNames.Insert(startIndex, string.Empty); + listPaths.Insert(startIndex, string.Empty); + } public override void Update() { diff --git a/package.json b/package.json index a625490..0c0f069 100644 --- a/package.json +++ b/package.json @@ -1,13 +1,14 @@ { "name": "com.module.navigationtool", - "version": "0.7.1", + "version": "0.7.2", "displayName": "Module.NavigationTool", "description": "Support for navigation tools, like favorites, history and toolbars", "unity": "2019.2", "unityRelease": "17f1", "dependencies": { - }, - "keywords": [ + "com.unity.addressables": "1.10.0" + }, + "keywords": [ "navigation", "favorites", "history",