98 lines
3.4 KiB
C#
98 lines
3.4 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using UnityEditor;
|
|
using UnityEditorInternal;
|
|
using UnityEngine;
|
|
|
|
namespace Module.NavigationTool.Editor.Toolbar
|
|
{
|
|
internal sealed class ToolbarScenePickerSettings : IToolbarSettings
|
|
{
|
|
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
|
|
{
|
|
get => EditorPrefs.GetBool(PREF_IS_SCENE_ENABLED, true);
|
|
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();
|
|
}
|
|
}
|
|
} |