Scene picker: Added option to add groups of scenes to open
This commit is contained in:
parent
41604b98e7
commit
a86f76904e
28 changed files with 1052 additions and 225 deletions
|
|
@ -0,0 +1,48 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Module.NavigationTool.Editor.Toolbar
|
||||
{
|
||||
internal sealed class ToolbarScenePickerProjectSettings : IToolbarProjectSettings
|
||||
{
|
||||
public string Title => "Scene";
|
||||
public bool IsSettingsDirty { get; private set; }
|
||||
|
||||
private StringReordableListDrawer assetLabelList;
|
||||
private SceneGroupReordableListDrawer sceneGroupList;
|
||||
|
||||
private ToolbarProjectSettings projectSettings;
|
||||
private Settings settings;
|
||||
|
||||
public void Initialize(ToolbarProjectSettings projectSettings)
|
||||
{
|
||||
this.projectSettings = projectSettings;
|
||||
settings = projectSettings.GetValueAs<Settings>();
|
||||
|
||||
assetLabelList = new StringReordableListDrawer(settings.labels, "Scene sorting by Asset label");
|
||||
assetLabelList.onChanged += ToolScenePicker.SetAsDirty;
|
||||
|
||||
sceneGroupList = new SceneGroupReordableListDrawer(settings.sceneGroups.groups, "Scene groups");
|
||||
sceneGroupList.onChanged += ToolScenePicker.SetAsDirty;
|
||||
}
|
||||
|
||||
public void Draw()
|
||||
{
|
||||
assetLabelList.DoLayoutList();
|
||||
sceneGroupList.DoLayoutList();
|
||||
IsSettingsDirty = assetLabelList.IsDirty || sceneGroupList.IsDirty;
|
||||
}
|
||||
|
||||
public void SetSettingsValue()
|
||||
{
|
||||
projectSettings.SetValue(settings);
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
public sealed class Settings
|
||||
{
|
||||
public List<string> labels = new();
|
||||
public SceneGroupArray sceneGroups = new();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 3dd46bde8e5b4cca9c95d051862f5817
|
||||
timeCreated: 1693466453
|
||||
|
|
@ -1,9 +1,4 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using UnityEditor;
|
||||
using UnityEditorInternal;
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
|
||||
namespace Module.NavigationTool.Editor.Toolbar
|
||||
{
|
||||
|
|
@ -12,7 +7,6 @@ namespace Module.NavigationTool.Editor.Toolbar
|
|||
public string Title => "Scene";
|
||||
|
||||
private const string PREF_IS_SCENE_ENABLED = "ToolbarSettings_IsSceneEnabled";
|
||||
private const string PREF_SCENE_ASSET_LABELS = "ToolbarSettings_SceneAssetLabels";
|
||||
private const string PREF_SCENE_PICKER_LOAD_SET_AS_ADDITIVE_KEY = "ToolbarSettings_ScenePickerLoadSetAsAdditive";
|
||||
|
||||
public static bool IsSceneEnabled
|
||||
|
|
@ -21,78 +15,19 @@ namespace Module.NavigationTool.Editor.Toolbar
|
|||
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));
|
||||
}
|
||||
|
||||
public static bool IsScenePickerSetAsAdditive
|
||||
{
|
||||
get => EditorPrefs.GetBool(PREF_SCENE_PICKER_LOAD_SET_AS_ADDITIVE_KEY, false);
|
||||
set => EditorPrefs.SetBool(PREF_SCENE_PICKER_LOAD_SET_AS_ADDITIVE_KEY, 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()
|
||||
{
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue