1.7.0: Added option to sort scenes by asset labels
This commit is contained in:
parent
d9e62f6589
commit
cceef7bb7e
|
|
@ -11,7 +11,7 @@
|
||||||
"allowUnsafeCode": false,
|
"allowUnsafeCode": false,
|
||||||
"overrideReferences": false,
|
"overrideReferences": false,
|
||||||
"precompiledReferences": [],
|
"precompiledReferences": [],
|
||||||
"autoReferenced": false,
|
"autoReferenced": true,
|
||||||
"defineConstraints": [],
|
"defineConstraints": [],
|
||||||
"versionDefines": [],
|
"versionDefines": [],
|
||||||
"noEngineReferences": false
|
"noEngineReferences": false
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@
|
||||||
{
|
{
|
||||||
string Title { get; }
|
string Title { get; }
|
||||||
|
|
||||||
|
void Initialize();
|
||||||
void Draw();
|
void Draw();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -21,6 +21,10 @@ namespace Module.NavigationTool.Editor.Toolbar
|
||||||
set => EditorPrefs.SetBool(PREF_IS_BUILD_AND_RUN_ENABLED, value);
|
set => EditorPrefs.SetBool(PREF_IS_BUILD_AND_RUN_ENABLED, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void Initialize()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
public void Draw()
|
public void Draw()
|
||||||
{
|
{
|
||||||
IsBuildEnabled = EditorGUILayout.Toggle("Enable Build Target picker", IsBuildEnabled);
|
IsBuildEnabled = EditorGUILayout.Toggle("Enable Build Target picker", IsBuildEnabled);
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,9 @@
|
||||||
using UnityEditor;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using UnityEditor;
|
||||||
|
using UnityEditorInternal;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
namespace Module.NavigationTool.Editor.Toolbar
|
namespace Module.NavigationTool.Editor.Toolbar
|
||||||
{
|
{
|
||||||
|
|
@ -7,16 +12,80 @@ namespace Module.NavigationTool.Editor.Toolbar
|
||||||
public string Title => "Scene";
|
public string Title => "Scene";
|
||||||
|
|
||||||
private const string PREF_IS_SCENE_ENABLED = "ToolbarSettings_IsSceneEnabled";
|
private const string PREF_IS_SCENE_ENABLED = "ToolbarSettings_IsSceneEnabled";
|
||||||
|
private const string PREF_SCENE_ASSET_LABELS = "ToolbarSettings_SceneAssetLabels";
|
||||||
|
|
||||||
public static bool IsSceneEnabled
|
public static bool IsSceneEnabled
|
||||||
{
|
{
|
||||||
get => EditorPrefs.GetBool(PREF_IS_SCENE_ENABLED, true);
|
get => EditorPrefs.GetBool(PREF_IS_SCENE_ENABLED, true);
|
||||||
set => EditorPrefs.SetBool(PREF_IS_SCENE_ENABLED, value);
|
private set => EditorPrefs.SetBool(PREF_IS_SCENE_ENABLED, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static List<string> SceneAssetLabels
|
||||||
|
{
|
||||||
|
get => EditorPrefs.GetString(PREF_SCENE_ASSET_LABELS).Split(',').ToList();
|
||||||
|
private set => EditorPrefs.SetString(PREF_SCENE_ASSET_LABELS, string.Join(',', value));
|
||||||
|
}
|
||||||
|
|
||||||
|
private ReorderableList assetLabelList;
|
||||||
|
private List<string> assetLabels;
|
||||||
|
|
||||||
|
public void Initialize()
|
||||||
|
{
|
||||||
|
assetLabels = SceneAssetLabels.ToList();
|
||||||
|
assetLabelList = new ReorderableList(assetLabels, typeof(string), true, true, true, true);
|
||||||
|
assetLabelList.drawElementCallback += OnAssetLabelListDrawElement;
|
||||||
|
assetLabelList.drawHeaderCallback += OnAssetLabelListDrawHeader;
|
||||||
|
assetLabelList.onAddCallback += OnAssetLabelListAddedElement;
|
||||||
|
assetLabelList.onRemoveCallback += OnAssetLabelListRemovedElement;
|
||||||
|
assetLabelList.onReorderCallback += OnAssetLabelListReorder;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Draw()
|
public void Draw()
|
||||||
{
|
{
|
||||||
IsSceneEnabled = EditorGUILayout.Toggle("Enable Scene picker", IsSceneEnabled);
|
IsSceneEnabled = EditorGUILayout.Toggle("Enable Scene picker", IsSceneEnabled);
|
||||||
|
|
||||||
|
if (assetLabelList == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
assetLabelList.DoLayoutList();
|
||||||
|
SceneAssetLabels = assetLabels;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void OnAssetLabelListDrawHeader(Rect rect)
|
||||||
|
{
|
||||||
|
EditorGUI.LabelField(rect, "Scene sorting by Asset label");
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnAssetLabelListDrawElement(Rect rect, int index, bool isActive, bool isFocused)
|
||||||
|
{
|
||||||
|
rect.height -= 2;
|
||||||
|
rect.y += 1;
|
||||||
|
|
||||||
|
string text = assetLabels[index];
|
||||||
|
string temp = EditorGUI.TextField(rect, text);
|
||||||
|
|
||||||
|
if (string.Equals(text, temp, StringComparison.Ordinal))
|
||||||
|
return;
|
||||||
|
|
||||||
|
assetLabels[index] = temp;
|
||||||
|
ToolScenePicker.SetAsDirty();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnAssetLabelListAddedElement(ReorderableList list)
|
||||||
|
{
|
||||||
|
assetLabels.Add(string.Empty);
|
||||||
|
ToolScenePicker.SetAsDirty();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnAssetLabelListRemovedElement(ReorderableList list)
|
||||||
|
{
|
||||||
|
assetLabels.RemoveAt(list.index);
|
||||||
|
ToolScenePicker.SetAsDirty();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnAssetLabelListReorder(ReorderableList list)
|
||||||
|
{
|
||||||
|
ToolScenePicker.SetAsDirty();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -29,6 +29,10 @@ namespace Module.NavigationTool.Editor.Toolbar
|
||||||
set => EditorPrefs.SetFloat(PREF_TIME_SCALE_MAX, value);
|
set => EditorPrefs.SetFloat(PREF_TIME_SCALE_MAX, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void Initialize()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
public void Draw()
|
public void Draw()
|
||||||
{
|
{
|
||||||
IsTimeScaleEnabled = EditorGUILayout.Toggle("Enable Time Scale slider", IsTimeScaleEnabled);
|
IsTimeScaleEnabled = EditorGUILayout.Toggle("Enable Time Scale slider", IsTimeScaleEnabled);
|
||||||
|
|
|
||||||
|
|
@ -21,6 +21,10 @@ namespace Module.NavigationTool.Editor.Toolbar
|
||||||
set => EditorPrefs.SetBool(PREF_IS_UI_LAYER_ENABLED, value);
|
set => EditorPrefs.SetBool(PREF_IS_UI_LAYER_ENABLED, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void Initialize()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
public void Draw()
|
public void Draw()
|
||||||
{
|
{
|
||||||
IsUiEnabled = EditorGUILayout.Toggle("Enable Canvas picker", IsUiEnabled);
|
IsUiEnabled = EditorGUILayout.Toggle("Enable Canvas picker", IsUiEnabled);
|
||||||
|
|
|
||||||
|
|
@ -57,16 +57,15 @@ namespace Module.NavigationTool.Editor.Toolbar
|
||||||
|
|
||||||
private static void InitializeRemainingScenes(List<string> listNames, List<string> listPaths)
|
private static void InitializeRemainingScenes(List<string> listNames, List<string> listPaths)
|
||||||
{
|
{
|
||||||
|
List<string> sortByAssetLabels = ToolbarScenePickerSettings.SceneAssetLabels;
|
||||||
|
var assetLabelToScenes = new SceneSortElement[sortByAssetLabels.Count + 1];
|
||||||
string[] guids = AssetDatabase.FindAssets("t:scene");
|
string[] guids = AssetDatabase.FindAssets("t:scene");
|
||||||
int startIndex = listNames.Count;
|
|
||||||
|
|
||||||
for (var i = 0; i < guids.Length; i++)
|
for (var i = 0; i < guids.Length; i++)
|
||||||
{
|
{
|
||||||
string path = AssetDatabase.GUIDToAssetPath(guids[i]);
|
string path = AssetDatabase.GUIDToAssetPath(guids[i]);
|
||||||
|
|
||||||
if (listPaths.Contains(path))
|
if (listPaths.Contains(path) || !path.StartsWith("Assets"))
|
||||||
continue;
|
|
||||||
if (!path.StartsWith("Assets"))
|
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
var scene = AssetDatabase.LoadAssetAtPath<SceneAsset>(path);
|
var scene = AssetDatabase.LoadAssetAtPath<SceneAsset>(path);
|
||||||
|
|
@ -77,15 +76,39 @@ namespace Module.NavigationTool.Editor.Toolbar
|
||||||
string sceneName = path.Substring(7, path.Length - 13)
|
string sceneName = path.Substring(7, path.Length - 13)
|
||||||
.Replace('/', '\\');
|
.Replace('/', '\\');
|
||||||
|
|
||||||
listNames.Add(sceneName);
|
string[] assetLabels = AssetDatabase.GetLabels(scene);
|
||||||
listPaths.Add(path);
|
int index = -1;
|
||||||
|
|
||||||
|
for (var j = 0; j < assetLabels.Length; j++)
|
||||||
|
{
|
||||||
|
index = sortByAssetLabels.IndexOf(assetLabels[j]);
|
||||||
|
|
||||||
|
if (index != -1)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (index == -1)
|
||||||
|
index = sortByAssetLabels.Count;
|
||||||
|
if (assetLabelToScenes[index] == null)
|
||||||
|
assetLabelToScenes[index] = new SceneSortElement();
|
||||||
|
|
||||||
|
assetLabelToScenes[index].names.Add(sceneName);
|
||||||
|
assetLabelToScenes[index].paths.Add(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (startIndex >= listNames.Count)
|
for (var i = 0; i < assetLabelToScenes.Length; i++)
|
||||||
return;
|
{
|
||||||
|
SceneSortElement e = assetLabelToScenes[i];
|
||||||
|
|
||||||
listNames.Insert(startIndex, string.Empty);
|
if (e == null)
|
||||||
listPaths.Insert(startIndex, string.Empty);
|
continue;
|
||||||
|
|
||||||
|
listNames.Add(string.Empty);
|
||||||
|
listPaths.Add(string.Empty);
|
||||||
|
|
||||||
|
listNames.AddRange(e.names);
|
||||||
|
listPaths.AddRange(e.paths);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Update()
|
public override void Update()
|
||||||
|
|
@ -125,5 +148,11 @@ namespace Module.NavigationTool.Editor.Toolbar
|
||||||
{
|
{
|
||||||
IS_DIRTY = true;
|
IS_DIRTY = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private sealed class SceneSortElement
|
||||||
|
{
|
||||||
|
public readonly List<string> names = new List<string>();
|
||||||
|
public readonly List<string> paths = new List<string>();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -25,8 +25,12 @@ namespace Module.NavigationTool.Editor.Toolbar
|
||||||
{
|
{
|
||||||
Type type = types[j];
|
Type type = types[j];
|
||||||
|
|
||||||
if (!type.IsInterface && !type.IsAbstract && iType.IsAssignableFrom(type))
|
if (type.IsInterface || type.IsAbstract || !iType.IsAssignableFrom(type))
|
||||||
list.Add((IToolbarSettings)FormatterServices.GetUninitializedObject(type));
|
continue;
|
||||||
|
|
||||||
|
var toolbar = (IToolbarSettings)FormatterServices.GetUninitializedObject(type);
|
||||||
|
toolbar.Initialize();
|
||||||
|
list.Add(toolbar);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "com.module.navigationtool",
|
"name": "com.module.navigationtool",
|
||||||
"version": "1.6.0",
|
"version": "1.7.0",
|
||||||
"displayName": "Module.NavigationTool",
|
"displayName": "Module.NavigationTool",
|
||||||
"description": "Support for navigation tools, like favorites, history and toolbars",
|
"description": "Support for navigation tools, like favorites, history and toolbars",
|
||||||
"unity": "2019.2",
|
"unity": "2019.2",
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue