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
3
Editor/Toolbar/Tools/Settings.meta
Normal file
3
Editor/Toolbar/Tools/Settings.meta
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: a630457a27194c8b8e93a7d8b2a8ae27
|
||||
timeCreated: 1644864264
|
||||
29
Editor/Toolbar/Tools/Settings/ToolbarBuildSettings.cs
Normal file
29
Editor/Toolbar/Tools/Settings/ToolbarBuildSettings.cs
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
using UnityEditor;
|
||||
|
||||
namespace Module.NavigationTool.Editor.Toolbar
|
||||
{
|
||||
internal sealed class ToolbarBuildSettings : IToolbarSettings
|
||||
{
|
||||
public string Title => "Build";
|
||||
|
||||
private const string PREF_IS_BUILD_ENABLED = "ToolbarSettings.IsBuildEnabled";
|
||||
private const string PREF_IS_BUILD_AND_RUN_ENABLED = "ToolbarSettings.IsBuildAndRunEnabled";
|
||||
|
||||
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 void Draw()
|
||||
{
|
||||
IsBuildEnabled = EditorGUILayout.Toggle("Enable Build Target picker", IsBuildEnabled);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 05811b28871541ec868123c6176c987f
|
||||
timeCreated: 1644864282
|
||||
22
Editor/Toolbar/Tools/Settings/ToolbarScenePickerSettings.cs
Normal file
22
Editor/Toolbar/Tools/Settings/ToolbarScenePickerSettings.cs
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
using UnityEditor;
|
||||
|
||||
namespace Module.NavigationTool.Editor.Toolbar
|
||||
{
|
||||
internal sealed class ToolbarScenePickerSettings : IToolbarSettings
|
||||
{
|
||||
public string Title => "Scene";
|
||||
|
||||
private const string PREF_IS_SCENE_ENABLED = "ToolbarSettings_IsSceneEnabled";
|
||||
|
||||
public static bool IsSceneEnabled
|
||||
{
|
||||
get => EditorPrefs.GetBool(PREF_IS_SCENE_ENABLED, true);
|
||||
set => EditorPrefs.SetBool(PREF_IS_SCENE_ENABLED, value);
|
||||
}
|
||||
|
||||
public void Draw()
|
||||
{
|
||||
IsSceneEnabled = EditorGUILayout.Toggle("Enable Scene picker", IsSceneEnabled);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 40d094d8314a485988bb647a72b78fb4
|
||||
timeCreated: 1644864987
|
||||
62
Editor/Toolbar/Tools/Settings/ToolbarTimeSettings.cs
Normal file
62
Editor/Toolbar/Tools/Settings/ToolbarTimeSettings.cs
Normal file
|
|
@ -0,0 +1,62 @@
|
|||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Module.NavigationTool.Editor.Toolbar
|
||||
{
|
||||
internal sealed class ToolbarTimeSettings : IToolbarSettings
|
||||
{
|
||||
public string Title => "Time";
|
||||
|
||||
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 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);
|
||||
}
|
||||
|
||||
public void Draw()
|
||||
{
|
||||
IsTimeScaleEnabled = EditorGUILayout.Toggle("Enable Time Scale slider", IsTimeScaleEnabled);
|
||||
|
||||
GUI.enabled = IsTimeScaleEnabled;
|
||||
float timeScaleMinValue = EditorGUILayout.FloatField("Min Value", TimeScaleMinValue);
|
||||
float timeScaleMaxValue = EditorGUILayout.FloatField("Max Value", TimeScaleMaxValue);
|
||||
|
||||
if (!Mathf.Approximately(timeScaleMinValue, TimeScaleMinValue))
|
||||
{
|
||||
if (timeScaleMinValue < 0.0f)
|
||||
timeScaleMinValue = 0.0f;
|
||||
|
||||
if (timeScaleMinValue > timeScaleMaxValue)
|
||||
timeScaleMaxValue = timeScaleMinValue;
|
||||
}
|
||||
else if (!Mathf.Approximately(timeScaleMaxValue, TimeScaleMaxValue))
|
||||
{
|
||||
if (timeScaleMaxValue < 0.0f)
|
||||
timeScaleMaxValue = 0.0f;
|
||||
|
||||
if (timeScaleMaxValue < timeScaleMinValue)
|
||||
timeScaleMinValue = timeScaleMaxValue;
|
||||
}
|
||||
|
||||
TimeScaleMinValue = timeScaleMinValue;
|
||||
TimeScaleMaxValue = timeScaleMaxValue;
|
||||
GUI.enabled = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 4ff04b8c4eb645eba58747d2399f8825
|
||||
timeCreated: 1644865203
|
||||
30
Editor/Toolbar/Tools/Settings/ToolbarUiSettings.cs
Normal file
30
Editor/Toolbar/Tools/Settings/ToolbarUiSettings.cs
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
using UnityEditor;
|
||||
|
||||
namespace Module.NavigationTool.Editor.Toolbar
|
||||
{
|
||||
internal sealed class ToolbarUiSettings : IToolbarSettings
|
||||
{
|
||||
public string Title => "UI";
|
||||
|
||||
private const string PREF_IS_UI_ENABLED = "ToolbarSettings_IsUiEnabled";
|
||||
private const string PREF_IS_UI_LAYER_ENABLED = "ToolbarSettings_IsUiLayerEnabled";
|
||||
|
||||
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 void Draw()
|
||||
{
|
||||
IsUiEnabled = EditorGUILayout.Toggle("Enable Canvas picker", IsUiEnabled);
|
||||
IsUiLayerEnabled = EditorGUILayout.Toggle("Enable Layer toggle", IsUiLayerEnabled);
|
||||
}
|
||||
}
|
||||
}
|
||||
3
Editor/Toolbar/Tools/Settings/ToolbarUiSettings.cs.meta
Normal file
3
Editor/Toolbar/Tools/Settings/ToolbarUiSettings.cs.meta
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: ce06d92a6c084745bb04f8468a3b2802
|
||||
timeCreated: 1644865309
|
||||
|
|
@ -8,7 +8,7 @@ namespace Module.NavigationTool.Editor.Toolbar
|
|||
[UsedImplicitly]
|
||||
internal sealed class ToolBuild : AbstractToolbarDrawer
|
||||
{
|
||||
public override bool Visible => ToolbarSettings.IsBuildEnabled;
|
||||
public override bool Visible => ToolbarBuildSettings.IsBuildEnabled;
|
||||
public override bool Enabled => !Application.isPlaying;
|
||||
public override EToolbarPlacement Placement => EToolbarPlacement.Left;
|
||||
public override int Priority => (int)EToolbarPriority.Low;
|
||||
|
|
@ -50,7 +50,7 @@ namespace Module.NavigationTool.Editor.Toolbar
|
|||
var rect0 = new Rect(rect.x, rect.y, rect.width - 16.0f, rect.height);
|
||||
var rect1 = new Rect(rect0.xMax, rect.y, 16.0f, rect.height);
|
||||
|
||||
int currentSelected = ToolbarSettings.IsBuildAndRunEnabled ? 1 : 0;
|
||||
int currentSelected = ToolbarBuildSettings.IsBuildAndRunEnabled ? 1 : 0;
|
||||
|
||||
if (GUI.Button(rect0, BUTTON_LIST[currentSelected], styles.buttonNoPadding))
|
||||
{
|
||||
|
|
@ -65,7 +65,7 @@ namespace Module.NavigationTool.Editor.Toolbar
|
|||
EditorUtility.DisplayCustomMenu(rect, CONTENT_LIST, currentSelected, (userData, options, selected) =>
|
||||
{
|
||||
if (selected != -1)
|
||||
ToolbarSettings.IsBuildAndRunEnabled = selected == 1;
|
||||
ToolbarBuildSettings.IsBuildAndRunEnabled = selected == 1;
|
||||
}, null);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ namespace Module.NavigationTool.Editor.Toolbar
|
|||
[UsedImplicitly]
|
||||
internal sealed class ToolBuildTargetPicker : AbstractToolbarDrawer
|
||||
{
|
||||
public override bool Visible => ToolbarSettings.IsBuildEnabled;
|
||||
public override bool Visible => ToolbarBuildSettings.IsBuildEnabled;
|
||||
public override bool Enabled => !Application.isPlaying;
|
||||
public override EToolbarPlacement Placement => EToolbarPlacement.Left;
|
||||
public override int Priority => (int)EToolbarPriority.Low;
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ namespace Module.NavigationTool.Editor.Toolbar
|
|||
[UsedImplicitly]
|
||||
internal sealed class ToolScenePicker : AbstractToolbarDrawer
|
||||
{
|
||||
public override bool Visible => ToolbarSettings.IsSceneEnabled;
|
||||
public override bool Visible => ToolbarScenePickerSettings.IsSceneEnabled;
|
||||
public override bool Enabled => !EditorApplication.isPlaying && !EditorApplication.isPlayingOrWillChangePlaymode;
|
||||
public override EToolbarPlacement Placement => EToolbarPlacement.Right;
|
||||
public override int Priority => (int)EToolbarPriority.Medium;
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ namespace Module.NavigationTool.Editor.Toolbar
|
|||
[UsedImplicitly]
|
||||
internal sealed class ToolTimeScale : AbstractToolbarDrawer
|
||||
{
|
||||
public override bool Visible => ToolbarSettings.IsTimeScaleEnabled;
|
||||
public override bool Visible => ToolbarTimeSettings.IsTimeScaleEnabled;
|
||||
public override bool Enabled => true;
|
||||
public override EToolbarPlacement Placement => EToolbarPlacement.Left;
|
||||
public override int Priority => (int)EToolbarPriority.Low;
|
||||
|
|
@ -23,8 +23,8 @@ namespace Module.NavigationTool.Editor.Toolbar
|
|||
|
||||
EditorGUI.LabelField(r0, "Time scale", EditorStyles.centeredGreyMiniLabel);
|
||||
EditorGUI.LabelField(r2, value.ToString("0.00"), EditorStyles.centeredGreyMiniLabel);
|
||||
float temp = GUI.HorizontalSlider(r1, value, ToolbarSettings.TimeScaleMinValue, ToolbarSettings.TimeScaleMaxValue);
|
||||
temp = Mathf.Clamp(temp, ToolbarSettings.TimeScaleMinValue, ToolbarSettings.TimeScaleMaxValue);
|
||||
float temp = GUI.HorizontalSlider(r1, value, ToolbarTimeSettings.TimeScaleMinValue, ToolbarTimeSettings.TimeScaleMaxValue);
|
||||
temp = Mathf.Clamp(temp, ToolbarTimeSettings.TimeScaleMinValue, ToolbarTimeSettings.TimeScaleMaxValue);
|
||||
|
||||
if (Mathf.Abs(temp - 1.0f) < 0.02f)
|
||||
temp = 1.0f;
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ namespace Module.NavigationTool.Editor.Toolbar
|
|||
[UsedImplicitly]
|
||||
internal sealed class ToolUICanvasPicker : AbstractToolbarDrawer
|
||||
{
|
||||
public override bool Visible => ToolbarSettings.IsUiEnabled;
|
||||
public override bool Visible => ToolbarUiSettings.IsUiEnabled;
|
||||
public override bool Enabled => (UTools.visibleLayers & (1 << LayerMask.NameToLayer("UI"))) != 0;
|
||||
public override EToolbarPlacement Placement => EToolbarPlacement.Left;
|
||||
public override int Priority => (int)EToolbarPriority.Medium;
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ namespace Module.NavigationTool.Editor.Toolbar
|
|||
[UsedImplicitly]
|
||||
internal sealed class ToolUILayerToggle : AbstractToolbarDrawer
|
||||
{
|
||||
public override bool Visible => ToolbarSettings.IsUiLayerEnabled;
|
||||
public override bool Visible => ToolbarUiSettings.IsUiLayerEnabled;
|
||||
public override bool Enabled => true;
|
||||
public override EToolbarPlacement Placement => EToolbarPlacement.Left;
|
||||
public override int Priority => (int)EToolbarPriority.Medium - 1;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue