1.5.0: Added interface and utility class for adding settings to toolbar settings provider
This commit is contained in:
parent
12de62dabb
commit
91c9504910
25 changed files with 272 additions and 133 deletions
9
Editor/Toolbar/Settings/IToolbarSettings.cs
Normal file
9
Editor/Toolbar/Settings/IToolbarSettings.cs
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
namespace Module.NavigationTool.Editor.Toolbar
|
||||
{
|
||||
public interface IToolbarSettings
|
||||
{
|
||||
string Title { get; }
|
||||
|
||||
void Draw();
|
||||
}
|
||||
}
|
||||
3
Editor/Toolbar/Settings/IToolbarSettings.cs.meta
Normal file
3
Editor/Toolbar/Settings/IToolbarSettings.cs.meta
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 66bccfd6abba42ba9d07f0d746d6179d
|
||||
timeCreated: 1644864241
|
||||
|
|
@ -1,64 +0,0 @@
|
|||
using UnityEditor;
|
||||
|
||||
namespace Module.NavigationTool.Editor.Toolbar
|
||||
{
|
||||
internal static class ToolbarSettings
|
||||
{
|
||||
private const string PREF_IS_UI_ENABLED = "ToolbarSettings_IsUiEnabled";
|
||||
private const string PREF_IS_UI_LAYER_ENABLED = "ToolbarSettings_IsUiLayerEnabled";
|
||||
private const string PREF_IS_SCENE_ENABLED = "ToolbarSettings_IsSceneEnabled";
|
||||
private const string PREF_IS_BUILD_ENABLED = "ToolbarSettings.IsBuildEnabled";
|
||||
private const string PREF_IS_BUILD_AND_RUN_ENABLED = "ToolbarSettings.IsBuildAndRunEnabled";
|
||||
private const string PREF_IS_TIME_SCALE_ENABLED = "ToolbarSettings.IsTimeScaleEnabled";
|
||||
private const string PREF_TIME_SCALE_MIN = "ToolbarSettings.TimeScaleMin";
|
||||
private const string PREF_TIME_SCALE_MAX = "ToolbarSettings.TimeScaleMax";
|
||||
|
||||
public static bool IsUiEnabled
|
||||
{
|
||||
get => EditorPrefs.GetBool(PREF_IS_UI_ENABLED, false);
|
||||
set => EditorPrefs.SetBool(PREF_IS_UI_ENABLED, value);
|
||||
}
|
||||
|
||||
public static bool IsUiLayerEnabled
|
||||
{
|
||||
get => EditorPrefs.GetBool(PREF_IS_UI_LAYER_ENABLED, false);
|
||||
set => EditorPrefs.SetBool(PREF_IS_UI_LAYER_ENABLED, value);
|
||||
}
|
||||
|
||||
public static bool IsSceneEnabled
|
||||
{
|
||||
get => EditorPrefs.GetBool(PREF_IS_SCENE_ENABLED, true);
|
||||
set => EditorPrefs.SetBool(PREF_IS_SCENE_ENABLED, value);
|
||||
}
|
||||
|
||||
public static bool IsBuildEnabled
|
||||
{
|
||||
get => EditorPrefs.GetBool(PREF_IS_BUILD_ENABLED, false);
|
||||
set => EditorPrefs.SetBool(PREF_IS_BUILD_ENABLED, value);
|
||||
}
|
||||
|
||||
public static bool IsBuildAndRunEnabled
|
||||
{
|
||||
get => EditorPrefs.GetBool(PREF_IS_BUILD_AND_RUN_ENABLED, true);
|
||||
set => EditorPrefs.SetBool(PREF_IS_BUILD_AND_RUN_ENABLED, value);
|
||||
}
|
||||
|
||||
public static bool IsTimeScaleEnabled
|
||||
{
|
||||
get => EditorPrefs.GetBool(PREF_IS_TIME_SCALE_ENABLED, false);
|
||||
set => EditorPrefs.SetBool(PREF_IS_TIME_SCALE_ENABLED, value);
|
||||
}
|
||||
|
||||
public static float TimeScaleMinValue
|
||||
{
|
||||
get => EditorPrefs.GetFloat(PREF_TIME_SCALE_MIN, 0.0f);
|
||||
set => EditorPrefs.SetFloat(PREF_TIME_SCALE_MIN, value);
|
||||
}
|
||||
|
||||
public static float TimeScaleMaxValue
|
||||
{
|
||||
get => EditorPrefs.GetFloat(PREF_TIME_SCALE_MAX, 1.0f);
|
||||
set => EditorPrefs.SetFloat(PREF_TIME_SCALE_MAX, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,3 +0,0 @@
|
|||
fileFormatVersion: 2
|
||||
guid: ee57c1a04c9448e585e7e524886bdeda
|
||||
timeCreated: 1639924440
|
||||
|
|
@ -1,3 +1,4 @@
|
|||
using System.Collections.Generic;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
|
|
@ -6,67 +7,50 @@ namespace Module.NavigationTool.Editor.Toolbar
|
|||
internal static class ToolbarSettingsProvider
|
||||
{
|
||||
private static Styles STYLES;
|
||||
private static IToolbarSettings[] SETTINGS;
|
||||
|
||||
[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.User)
|
||||
{
|
||||
label = "Toolbar",
|
||||
keywords = new[] { "Scene", "UI", "Toolbar" },
|
||||
keywords = keywords.ToArray(),
|
||||
guiHandler = OnGui
|
||||
};
|
||||
}
|
||||
|
||||
private static void OnGui(string searchContext)
|
||||
private static void Initialize()
|
||||
{
|
||||
if (STYLES == null)
|
||||
STYLES = new Styles();
|
||||
|
||||
STYLES.Initialize((GUI.skin));
|
||||
|
||||
if (SETTINGS == null)
|
||||
SETTINGS = ToolbarSettingsUtility.GetAllSettings();
|
||||
}
|
||||
|
||||
private static void OnGui(string searchContext)
|
||||
{
|
||||
Initialize();
|
||||
STYLES.Initialize(GUI.skin);
|
||||
|
||||
EditorGUILayout.BeginVertical(STYLES.settingsGroup);
|
||||
{
|
||||
EditorGUILayout.LabelField("UI", EditorStyles.boldLabel);
|
||||
ToolbarSettings.IsUiEnabled = EditorGUILayout.Toggle("Enable Canvas picker", ToolbarSettings.IsUiEnabled);
|
||||
ToolbarSettings.IsUiLayerEnabled = EditorGUILayout.Toggle("Enable Layer toggle", ToolbarSettings.IsUiLayerEnabled);
|
||||
|
||||
EditorGUILayout.Space();
|
||||
EditorGUILayout.LabelField("Scene", EditorStyles.boldLabel);
|
||||
ToolbarSettings.IsSceneEnabled = EditorGUILayout.Toggle("Enable Scene picker", ToolbarSettings.IsSceneEnabled);
|
||||
|
||||
EditorGUILayout.Space();
|
||||
EditorGUILayout.LabelField("Build Target", EditorStyles.boldLabel);
|
||||
ToolbarSettings.IsBuildEnabled = EditorGUILayout.Toggle("Enable Build Target picker", ToolbarSettings.IsBuildEnabled);
|
||||
|
||||
EditorGUILayout.Space();
|
||||
EditorGUILayout.LabelField("Time", EditorStyles.boldLabel);
|
||||
ToolbarSettings.IsTimeScaleEnabled = EditorGUILayout.Toggle("Enable Time Scale slider", ToolbarSettings.IsTimeScaleEnabled);
|
||||
|
||||
GUI.enabled = ToolbarSettings.IsTimeScaleEnabled;
|
||||
float timeScaleMinValue = EditorGUILayout.FloatField("Min Value", ToolbarSettings.TimeScaleMinValue);
|
||||
float timeScaleMaxValue = EditorGUILayout.FloatField("Max Value", ToolbarSettings.TimeScaleMaxValue);
|
||||
|
||||
if (!Mathf.Approximately(timeScaleMinValue, ToolbarSettings.TimeScaleMinValue))
|
||||
for (var i = 0; i < SETTINGS.Length; i++)
|
||||
{
|
||||
if (timeScaleMinValue < 0.0f)
|
||||
timeScaleMinValue = 0.0f;
|
||||
|
||||
if (timeScaleMinValue > timeScaleMaxValue)
|
||||
timeScaleMaxValue = timeScaleMinValue;
|
||||
IToolbarSettings settings = SETTINGS[i];
|
||||
|
||||
EditorGUILayout.LabelField(settings.Title, EditorStyles.boldLabel);
|
||||
settings.Draw();
|
||||
EditorGUILayout.Space();
|
||||
}
|
||||
else if (!Mathf.Approximately(timeScaleMaxValue, ToolbarSettings.TimeScaleMaxValue))
|
||||
{
|
||||
if (timeScaleMaxValue < 0.0f)
|
||||
timeScaleMaxValue = 0.0f;
|
||||
|
||||
if (timeScaleMaxValue < timeScaleMinValue)
|
||||
timeScaleMinValue = timeScaleMaxValue;
|
||||
}
|
||||
|
||||
ToolbarSettings.TimeScaleMinValue = timeScaleMinValue;
|
||||
ToolbarSettings.TimeScaleMaxValue = timeScaleMaxValue;
|
||||
GUI.enabled = true;
|
||||
}
|
||||
EditorGUILayout.EndVertical();
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue