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
12
Editor/Toolbar/Settings/IToolbarProjectSettings.cs
Normal file
12
Editor/Toolbar/Settings/IToolbarProjectSettings.cs
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
namespace Module.NavigationTool.Editor.Toolbar
|
||||
{
|
||||
public interface IToolbarProjectSettings
|
||||
{
|
||||
string Title { get; }
|
||||
bool IsSettingsDirty { get; }
|
||||
|
||||
void Initialize(ToolbarProjectSettings projectSettings);
|
||||
void Draw();
|
||||
void SetSettingsValue();
|
||||
}
|
||||
}
|
||||
3
Editor/Toolbar/Settings/IToolbarProjectSettings.cs.meta
Normal file
3
Editor/Toolbar/Settings/IToolbarProjectSettings.cs.meta
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: a45b77fff4244ae4a1271208dcb3bc9c
|
||||
timeCreated: 1693423025
|
||||
113
Editor/Toolbar/Settings/ToolbarProjectSettings.cs
Normal file
113
Editor/Toolbar/Settings/ToolbarProjectSettings.cs
Normal file
|
|
@ -0,0 +1,113 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Module.NavigationTool.Editor.Toolbar
|
||||
{
|
||||
[Serializable]
|
||||
public sealed class ToolbarProjectSettings
|
||||
{
|
||||
[SerializeField]
|
||||
private List<string> keys = new();
|
||||
[SerializeField]
|
||||
private List<string> values = new();
|
||||
|
||||
public const string RELATIVE_PATH = "ProjectSettings/ToolbarProjectSettings.asset";
|
||||
|
||||
public void Load()
|
||||
{
|
||||
try
|
||||
{
|
||||
string path = GetAbsolutePath();
|
||||
|
||||
if (File.Exists(path))
|
||||
{
|
||||
string json = File.ReadAllText(path);
|
||||
JsonUtility.FromJsonOverwrite(json, this);
|
||||
}
|
||||
else
|
||||
{
|
||||
keys.Clear();
|
||||
values.Clear();
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Debug.LogException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public void Save()
|
||||
{
|
||||
try
|
||||
{
|
||||
string path = GetAbsolutePath();
|
||||
string json = JsonUtility.ToJson(this, true);
|
||||
File.WriteAllText(path, json, Encoding.Unicode);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Debug.LogException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public T GetValueAs<T>() where T : new()
|
||||
{
|
||||
try
|
||||
{
|
||||
string key = typeof(T).FullName;
|
||||
int index = keys.IndexOf(key);
|
||||
|
||||
if (index == -1)
|
||||
{
|
||||
var t = new T();
|
||||
keys.Add(key);
|
||||
values.Add(JsonUtility.ToJson(t));
|
||||
return t;
|
||||
}
|
||||
|
||||
string json = values[index];
|
||||
return JsonUtility.FromJson<T>(json);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Debug.LogException(e);
|
||||
return new T();
|
||||
}
|
||||
}
|
||||
|
||||
public void SetValue<T>(T value) where T : new()
|
||||
{
|
||||
try
|
||||
{
|
||||
string key = typeof(T).FullName;
|
||||
string json = JsonUtility.ToJson(value);
|
||||
int index = keys.IndexOf(key);
|
||||
|
||||
if (index != -1)
|
||||
{
|
||||
values[index] = json;
|
||||
}
|
||||
else
|
||||
{
|
||||
keys.Add(key);
|
||||
values.Add(json);
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Debug.LogException(e);
|
||||
}
|
||||
}
|
||||
|
||||
private string GetAbsolutePath()
|
||||
{
|
||||
string path = Application.dataPath;
|
||||
path = path.Substring(0, Application.dataPath.Length - 6);
|
||||
path += RELATIVE_PATH;
|
||||
return path;
|
||||
}
|
||||
}
|
||||
}
|
||||
3
Editor/Toolbar/Settings/ToolbarProjectSettings.cs.meta
Normal file
3
Editor/Toolbar/Settings/ToolbarProjectSettings.cs.meta
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: a5fbb83f9c104775ae07b33244e133d2
|
||||
timeCreated: 1693466538
|
||||
110
Editor/Toolbar/Settings/ToolbarProjectSettingsProvider.cs
Normal file
110
Editor/Toolbar/Settings/ToolbarProjectSettingsProvider.cs
Normal file
|
|
@ -0,0 +1,110 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Module.NavigationTool.Editor.Toolbar
|
||||
{
|
||||
internal static class ToolbarProjectSettingsProvider
|
||||
{
|
||||
private static Styles STYLES;
|
||||
private static IToolbarProjectSettings[] SETTINGS;
|
||||
private static ToolbarProjectSettings PROJECT_SETTINGS;
|
||||
private const string PREF_FOLDOUT_STATE = "ToolbarFoldout_{0}";
|
||||
|
||||
[SettingsProvider]
|
||||
public static SettingsProvider GetProvider()
|
||||
{
|
||||
Initialize();
|
||||
var keywords = new List<string> { "Toolbar" };
|
||||
|
||||
for (var i = 0; i < SETTINGS.Length; i++)
|
||||
{
|
||||
keywords.Add(SETTINGS[i].Title);
|
||||
}
|
||||
|
||||
return new SettingsProvider("Module/Toolbar", SettingsScope.Project)
|
||||
{
|
||||
label = "Toolbar",
|
||||
keywords = keywords.ToArray(),
|
||||
guiHandler = OnGui
|
||||
};
|
||||
}
|
||||
|
||||
private static void Initialize()
|
||||
{
|
||||
if (STYLES == null)
|
||||
STYLES = new Styles();
|
||||
|
||||
if (PROJECT_SETTINGS == null)
|
||||
{
|
||||
PROJECT_SETTINGS = new ToolbarProjectSettings();
|
||||
PROJECT_SETTINGS.Load();
|
||||
}
|
||||
|
||||
if (SETTINGS == null)
|
||||
SETTINGS = ToolbarSettingsUtility.GetAllProjectSettings(PROJECT_SETTINGS);
|
||||
}
|
||||
|
||||
private static void OnGui(string searchContext)
|
||||
{
|
||||
Initialize();
|
||||
STYLES.Initialize(GUI.skin);
|
||||
var isSettingsDirty = false;
|
||||
|
||||
EditorGUILayout.BeginVertical(STYLES.settingsGroup);
|
||||
{
|
||||
for (var i = 0; i < SETTINGS.Length; i++)
|
||||
{
|
||||
IToolbarProjectSettings settings = SETTINGS[i];
|
||||
|
||||
try
|
||||
{
|
||||
bool foldoutState = GetFoldoutState(settings);
|
||||
bool newFoldoutState = EditorGUILayout.BeginFoldoutHeaderGroup(foldoutState, settings.Title, EditorStyles.foldoutHeader);
|
||||
|
||||
if (newFoldoutState)
|
||||
{
|
||||
EditorGUI.indentLevel++;
|
||||
settings.Draw();
|
||||
|
||||
if (settings.IsSettingsDirty)
|
||||
{
|
||||
isSettingsDirty = true;
|
||||
settings.SetSettingsValue();
|
||||
}
|
||||
|
||||
EditorGUI.indentLevel--;
|
||||
}
|
||||
|
||||
EditorGUILayout.EndFoldoutHeaderGroup();
|
||||
EditorGUILayout.Space();
|
||||
|
||||
if (newFoldoutState != foldoutState)
|
||||
SetFoldoutState(settings, newFoldoutState);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
EditorGUILayout.LabelField(e.Message);
|
||||
}
|
||||
}
|
||||
|
||||
if (isSettingsDirty)
|
||||
PROJECT_SETTINGS.Save();
|
||||
}
|
||||
EditorGUILayout.EndVertical();
|
||||
}
|
||||
|
||||
private static bool GetFoldoutState(IToolbarProjectSettings settings)
|
||||
{
|
||||
string key = string.Format(PREF_FOLDOUT_STATE, settings.GetType().FullName);
|
||||
return EditorPrefs.GetBool(key, true);
|
||||
}
|
||||
|
||||
private static void SetFoldoutState(IToolbarProjectSettings settings, bool foldout)
|
||||
{
|
||||
string key = string.Format(PREF_FOLDOUT_STATE, settings.GetType().FullName);
|
||||
EditorPrefs.SetBool(key, foldout);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 7e21927d181c41f1acdbecc9f5fc3e26
|
||||
timeCreated: 1693423048
|
||||
|
|
@ -36,7 +36,7 @@ namespace Module.NavigationTool.Editor.Toolbar
|
|||
if (STYLES == null)
|
||||
STYLES = new Styles();
|
||||
if (SETTINGS == null)
|
||||
SETTINGS = ToolbarSettingsUtility.GetAllSettings();
|
||||
SETTINGS = ToolbarSettingsUtility.GetAllUserSettings();
|
||||
}
|
||||
|
||||
private static void OnGui(string searchContext)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue