0.7.2: Added asset bundle and addressable scenes to scene picker

This commit is contained in:
Anders Ejlersen 2021-09-17 23:49:29 +02:00
parent 9ba22f779d
commit ca34993eb3
3 changed files with 115 additions and 37 deletions

View file

@ -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

View file

@ -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<string>(scenes.Length);
var listPaths = new List<string>(scenes.Length);
var listNames = new List<string>();
var listPaths = new List<string>();
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<SceneAsset>(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();
@ -66,6 +43,104 @@ namespace Module.NavigationTool.Editor.Tools
IS_DIRTY = false;
}
private static void InitializeBuildSettingsScenes(List<string> listNames, List<string> 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<string> listNames, List<string> 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<SceneAsset>(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<string> listNames, List<string> listPaths)
{
var assets = new List<AddressableAssetEntry>();
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<string> listNames, List<string> 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<SceneAsset>(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()
{
Initialize();

View file

@ -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",