1.8.0: Added target frame rate and PlayerPrefs.Delete to toolbar

- Added: Tooltips on all buttons and labels in toolbar tools
- Added: Target frame rate with `[min;max]` slider in toolbar
- Added: `PlayerPrefs` delete button added to toolbar
- Added: Option to select Single/Additive scene load/unload to scene picker
- Added: All `IToolbarSettings` will be grouped with a foldout-toggle in Preferences
This commit is contained in:
Anders Ejlersen 2022-12-07 22:10:09 +01:00
parent 10d07b986f
commit fe82c5c9fa
22 changed files with 669 additions and 48 deletions

View file

@ -1,3 +1,4 @@
using System;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
@ -8,6 +9,8 @@ namespace Module.NavigationTool.Editor.Toolbar
{
private static Styles STYLES;
private static IToolbarSettings[] SETTINGS;
private const string PREF_FOLDOUT_STATE = "ToolbarFoldout_{0}";
[SettingsProvider]
public static SettingsProvider GetProvider()
@ -46,13 +49,44 @@ namespace Module.NavigationTool.Editor.Toolbar
for (var i = 0; i < SETTINGS.Length; i++)
{
IToolbarSettings settings = SETTINGS[i];
EditorGUILayout.LabelField(settings.Title, EditorStyles.boldLabel);
settings.Draw();
EditorGUILayout.Space();
try
{
bool foldoutState = GetFoldoutState(settings);
bool newFoldoutState = EditorGUILayout.BeginFoldoutHeaderGroup(foldoutState, settings.Title, EditorStyles.foldoutHeader);
if (newFoldoutState)
{
EditorGUI.indentLevel++;
settings.Draw();
EditorGUI.indentLevel--;
}
EditorGUILayout.EndFoldoutHeaderGroup();
EditorGUILayout.Space();
if (newFoldoutState != foldoutState)
SetFoldoutState(settings, newFoldoutState);
}
catch (Exception e)
{
EditorGUILayout.LabelField(e.Message);
}
}
}
EditorGUILayout.EndVertical();
}
private static bool GetFoldoutState(IToolbarSettings settings)
{
string key = string.Format(PREF_FOLDOUT_STATE, settings.GetType().FullName);
return EditorPrefs.GetBool(key, true);
}
private static void SetFoldoutState(IToolbarSettings settings, bool foldout)
{
string key = string.Format(PREF_FOLDOUT_STATE, settings.GetType().FullName);
EditorPrefs.SetBool(key, foldout);
}
}
}

View file

@ -27,7 +27,7 @@ namespace Module.NavigationTool.Editor.Toolbar
public void Draw()
{
IsBuildEnabled = EditorGUILayout.Toggle("Enable Build Target picker", IsBuildEnabled);
IsBuildEnabled = EditorGUILayout.Toggle("Enable Build Target", IsBuildEnabled);
}
}
}

View file

@ -0,0 +1,26 @@
using UnityEditor;
namespace Module.NavigationTool.Editor.Toolbar
{
internal sealed class ToolbarPlayerPrefsSettings : IToolbarSettings
{
public string Title => "Player Prefs";
private const string PREF_PLAYER_PREFS_ENABLED = "ToolbarSettings.IsPlayerPrefsEnabled";
public static bool IsPlayerPrefsEnabled
{
get => EditorPrefs.GetBool(PREF_PLAYER_PREFS_ENABLED, false);
set => EditorPrefs.SetBool(PREF_PLAYER_PREFS_ENABLED, value);
}
public void Initialize()
{
}
public void Draw()
{
IsPlayerPrefsEnabled = EditorGUILayout.Toggle("Enable Player Prefs", IsPlayerPrefsEnabled);
}
}
}

View file

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: ed84516c9799495c829d09ad6076124d
timeCreated: 1670362850

View file

@ -13,6 +13,7 @@ namespace Module.NavigationTool.Editor.Toolbar
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
{
@ -25,6 +26,12 @@ namespace Module.NavigationTool.Editor.Toolbar
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;

View file

@ -0,0 +1,66 @@
using UnityEditor;
using UnityEngine;
namespace Module.NavigationTool.Editor.Toolbar
{
internal sealed class ToolbarTargetFrameRateSettings : IToolbarSettings
{
public string Title => "Target Frame Rate";
private const string PREF_IS_TARGET_FRAME_RATE_ENABLED = "ToolbarSettings.IsTargetFrameRateEnabled";
private const string PREF_TARGET_FRAME_RATE_MIN = "ToolbarSettings.TargetFrameRateMin";
private const string PREF_TARGET_FRAME_RATE_MAX = "ToolbarSettings.TargetFrameRateMax";
public static bool IsTargetFrameRateEnabled
{
get => EditorPrefs.GetBool(PREF_IS_TARGET_FRAME_RATE_ENABLED, false);
set => EditorPrefs.SetBool(PREF_IS_TARGET_FRAME_RATE_ENABLED, value);
}
public static int TargetFrameRateMinValue
{
get => EditorPrefs.GetInt(PREF_TARGET_FRAME_RATE_MIN, 10);
set => EditorPrefs.SetInt(PREF_TARGET_FRAME_RATE_MIN, value);
}
public static int TargetFrameRateMaxValue
{
get => EditorPrefs.GetInt(PREF_TARGET_FRAME_RATE_MAX, 144);
set => EditorPrefs.SetInt(PREF_TARGET_FRAME_RATE_MAX, value);
}
public void Initialize()
{
}
public void Draw()
{
IsTargetFrameRateEnabled = EditorGUILayout.Toggle("Enable Frame Rate", IsTargetFrameRateEnabled);
GUI.enabled = IsTargetFrameRateEnabled;
int minValue = EditorGUILayout.IntField("Min", TargetFrameRateMinValue);
int maxValue = EditorGUILayout.IntField("Max", TargetFrameRateMaxValue);
if (minValue != TargetFrameRateMinValue)
{
if (minValue < 1)
minValue = 1;
if (minValue > maxValue)
maxValue = minValue;
}
else if (maxValue != TargetFrameRateMaxValue)
{
if (maxValue < 1)
maxValue = 1;
if (maxValue < minValue)
minValue = maxValue;
}
TargetFrameRateMinValue = minValue;
TargetFrameRateMaxValue = maxValue;
GUI.enabled = true;
}
}
}

View file

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 3f20d59ea6be4e4ab06ab8960c16fcd2
timeCreated: 1670355420

View file

@ -35,7 +35,7 @@ namespace Module.NavigationTool.Editor.Toolbar
public void Draw()
{
IsTimeScaleEnabled = EditorGUILayout.Toggle("Enable Time Scale slider", IsTimeScaleEnabled);
IsTimeScaleEnabled = EditorGUILayout.Toggle("Enable Time slider", IsTimeScaleEnabled);
GUI.enabled = IsTimeScaleEnabled;
float timeScaleMinValue = EditorGUILayout.FloatField("Min Value", TimeScaleMinValue);

View file

@ -23,10 +23,14 @@ namespace Module.NavigationTool.Editor.Toolbar
if (!IS_DIRTY)
return;
const string TOOLTIP = "Build project with current EditorBuildSettings and target platform";
const string TOOLTIP_RUN = "Build & Run project with current EditorBuildSettings and target platform";
const string TOOLTIP_PLATFORM = "Select build or build & run options";
BUTTON_LIST = new[]
{
new GUIContent("Build"),
new GUIContent("Build & Run")
new GUIContent("Build", TOOLTIP),
new GUIContent("Build & Run", TOOLTIP_RUN)
};
CONTENT_LIST = new[]
@ -35,7 +39,8 @@ namespace Module.NavigationTool.Editor.Toolbar
new GUIContent("Build and Run")
};
DROPDOWN = EditorGUIUtility.IconContent("d_icon dropdown");
GUIContent iconContent = EditorGUIUtility.IconContent("d_icon dropdown");
DROPDOWN = new GUIContent(iconContent.image, TOOLTIP_PLATFORM);
IS_DIRTY = false;
}
@ -59,7 +64,7 @@ namespace Module.NavigationTool.Editor.Toolbar
BuildPlayerWindow.DefaultBuildMethods.BuildPlayer(options);
}
if (GUI.Button(rect1, DROPDOWN, styles.button))
if (GUI.Button(rect1, DROPDOWN, styles.buttonNoPadding))
{
// Note: Do not discard the parameters: userData and options, since they throw an error in 2019, if there are two of them
EditorUtility.DisplayCustomMenu(rect, CONTENT_LIST, currentSelected, (userData, options, selected) =>

View file

@ -22,7 +22,7 @@ namespace Module.NavigationTool.Editor.Toolbar
private static BuildTarget[] TARGETS = new BuildTarget[0];
private static GUIContent[] TARGET_LIST = new GUIContent[0];
private static int SELECTED_INDEX = -1;
private static void Initialize()
{
if (!IS_DIRTY)
@ -128,12 +128,16 @@ namespace Module.NavigationTool.Editor.Toolbar
private static GUIContent GetButtonContent(BuildTargetGroup group)
{
const string TOOLTIP = "Select target platform for build";
var name = $"BuildSettings.{group}.Small";
if (group == BuildTargetGroup.WSA)
name = "BuildSettings.Metro.Small";
return EditorGUIUtility.IconContent(name);
GUIContent iconContent = EditorGUIUtility.IconContent(name);
var content = new GUIContent(iconContent.image, TOOLTIP);
return content;
}
private static int GetHashCode(BuildTargetGroup group, BuildTarget target)

View file

@ -0,0 +1,37 @@
using JetBrains.Annotations;
using UnityEditor;
using UnityEngine;
using UTools = UnityEditor.Tools;
namespace Module.NavigationTool.Editor.Toolbar
{
[UsedImplicitly]
internal sealed class ToolPlayerPrefs : AbstractToolbarDrawer
{
public override bool Visible => ToolbarPlayerPrefsSettings.IsPlayerPrefsEnabled;
public override bool Enabled => true;
public override EToolbarPlacement Placement => EToolbarPlacement.Right;
public override int Priority => (int)EToolbarPriority.Low;
private static readonly GUIContent LABEL_DELETE = new GUIContent(string.Empty, "Deletes all PlayerPrefs entries");
protected override void Draw(Rect rect)
{
bool isDeleteButtonPressed = GUI.Button(rect, styles.iconDisconnect, styles.button);
GUI.Label(rect, LABEL_DELETE, styles.labelCenter);
if (!isDeleteButtonPressed)
return;
if (!EditorUtility.DisplayDialog("Delete PlayerPrefs", "Are you sure you want to delete all PlayerPrefs data?", "Yes", "No"))
return;
PlayerPrefs.DeleteAll();
PlayerPrefs.Save();
}
public override float CalculateWidth()
{
return 24.0f;
}
}
}

View file

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 30a4a911912a49c0a00fd8953ad0ba41
timeCreated: 1670362836

View file

@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Collections.Generic;
using System.IO;
using System.Runtime.CompilerServices;
using System.Text;
using JetBrains.Annotations;
using UnityEditor;
using UnityEditor.SceneManagement;
@ -17,31 +18,48 @@ namespace Module.NavigationTool.Editor.Toolbar
public override EToolbarPlacement Placement => EToolbarPlacement.Right;
public override int Priority => (int)EToolbarPriority.Medium;
private static bool IS_DIRTY = true;
private static int SELECTED_INDEX = -1;
private static string[] OPTIONS = new string[0];
private static string[] PATHS = new string[0];
private static readonly List<int> SELECTED_INDICES = new List<int>();
private static readonly StringBuilder STRING_BUILDER = new StringBuilder();
private static string SCENE_LABEL = string.Empty;
private static string[] SCENE_NAMES = new string[0];
private static string[] SCENE_SHORT_NAMES = new string[0];
private static string[] SCENE_PATHS = new string[0];
private static readonly GUIContent LABEL_ADDITIVE = new GUIContent(string.Empty, "Toggles between Single and Additive scene loading");
private static bool IS_DIRTY = true;
private static void Initialize()
{
if (!IS_DIRTY)
return;
SELECTED_INDICES.Clear();
var listNames = new List<string>();
var listShortNames = new List<string>();
var listPaths = new List<string>();
InitializeBuildSettingsScenes(listNames, listPaths);
InitializeRemainingScenes(listNames, listPaths);
OPTIONS = listNames.ToArray();
PATHS = listPaths.ToArray();
Scene activeScene = SceneManager.GetActiveScene();
SELECTED_INDEX = listPaths.IndexOf(activeScene.path);
InitializeBuildSettingsScenes(listNames, listShortNames, listPaths);
InitializeRemainingScenes(listNames, listShortNames, listPaths);
for (var i = 0; i < SceneManager.sceneCount; i++)
{
Scene scene = SceneManager.GetSceneAt(i);
int index = listPaths.IndexOf(scene.path);
if (index != -1)
SELECTED_INDICES.Add(listPaths.IndexOf(scene.path));
}
SCENE_NAMES = listNames.ToArray();
SCENE_SHORT_NAMES = listShortNames.ToArray();
SCENE_PATHS = listPaths.ToArray();
RefreshSceneLabel();
IS_DIRTY = false;
}
private static void InitializeBuildSettingsScenes(List<string> listNames, List<string> listPaths)
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static void InitializeBuildSettingsScenes(List<string> listNames, List<string> listShortNames, List<string> listPaths)
{
EditorBuildSettingsScene[] scenes = EditorBuildSettings.scenes;
@ -50,12 +68,14 @@ namespace Module.NavigationTool.Editor.Toolbar
if (string.IsNullOrEmpty(scenes[i].path))
continue;
listNames.Add($"{Path.GetFileNameWithoutExtension(scenes[i].path)}");
listNames.Add(Path.GetFileNameWithoutExtension(scenes[i].path));
listShortNames.Add(listNames[i]);
listPaths.Add(scenes[i].path);
}
}
private static void InitializeRemainingScenes(List<string> listNames, List<string> listPaths)
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static void InitializeRemainingScenes(List<string> listNames, List<string> listShortNames, List<string> listPaths)
{
List<string> sortByAssetLabels = ToolbarScenePickerSettings.SceneAssetLabels;
var assetLabelToScenes = new SceneSortElement[sortByAssetLabels.Count + 1];
@ -93,6 +113,7 @@ namespace Module.NavigationTool.Editor.Toolbar
assetLabelToScenes[index] = new SceneSortElement();
assetLabelToScenes[index].names.Add(sceneName);
assetLabelToScenes[index].shortNames.Add(Path.GetFileName(sceneName));
assetLabelToScenes[index].paths.Add(path);
}
@ -104,13 +125,15 @@ namespace Module.NavigationTool.Editor.Toolbar
continue;
listNames.Add(string.Empty);
listShortNames.Add(string.Empty);
listPaths.Add(string.Empty);
listNames.AddRange(e.names);
listShortNames.AddRange(e.shortNames);
listPaths.AddRange(e.paths);
}
}
public override void Update()
{
Initialize();
@ -119,29 +142,81 @@ namespace Module.NavigationTool.Editor.Toolbar
protected override void Draw(Rect rect)
{
Initialize();
int temp = EditorGUI.Popup(rect, SELECTED_INDEX, OPTIONS, styles.popup);
var rect0 = new Rect(rect.x, rect.y, rect.width - 24.0f, rect.height);
var rect1 = new Rect(rect0.xMax, rect.y, 24.0f, rect.height);
if (temp <= -1 || temp == SELECTED_INDEX || OPTIONS.Length == 0)
return;
if (string.IsNullOrEmpty(PATHS[temp]))
return;
if (GUI.Button(rect0, SCENE_LABEL, styles.popup))
ShowDropDown(rect0);
try
bool isScenePickerSetAsAdditive = ToolbarScenePickerSettings.IsScenePickerSetAsAdditive;
bool temp = EditorGUI.Toggle(rect1, isScenePickerSetAsAdditive, styles.button);
GUI.Label(rect1, temp ? styles.iconPlusSmall : styles.iconPlusTiny, styles.labelCenter);
GUI.Label(rect1, LABEL_ADDITIVE, styles.labelCenter);
if (temp != isScenePickerSetAsAdditive)
ToolbarScenePickerSettings.IsScenePickerSetAsAdditive = temp;
}
private static void ShowDropDown(Rect rect)
{
var menu = new GenericMenu();
for (var i = 0; i < SCENE_NAMES.Length; i++)
{
Scene scene = EditorSceneManager.OpenScene(PATHS[temp], OpenSceneMode.Single);
if (scene.isLoaded)
SELECTED_INDEX = temp;
int sceneIndex = i;
menu.AddItem(new GUIContent(SCENE_NAMES[i]), SELECTED_INDICES.Contains(i), () => SelectScene(sceneIndex));
}
catch (Exception e)
menu.DropDown(rect);
}
private static void SelectScene(int index)
{
string path = SCENE_PATHS[index];
Scene scene = SceneManager.GetSceneByPath(path);
bool isScenePickerSetAsAdditive = ToolbarScenePickerSettings.IsScenePickerSetAsAdditive;
if (scene.isLoaded)
{
Debug.LogWarningFormat("Failed to load scene ({0}), due to exception: {1}", PATHS[temp], e.Message);
if (SceneManager.sceneCount == 1)
return;
EditorSceneManager.CloseScene(scene, true);
SELECTED_INDICES.Remove(index);
}
else if (isScenePickerSetAsAdditive)
{
EditorSceneManager.OpenScene(SCENE_PATHS[index], OpenSceneMode.Additive);
SELECTED_INDICES.Add(index);
}
else
{
EditorSceneManager.OpenScene(SCENE_PATHS[index], OpenSceneMode.Single);
SELECTED_INDICES.Clear();
SELECTED_INDICES.Add(index);
}
RefreshSceneLabel();
}
private static void RefreshSceneLabel()
{
STRING_BUILDER.Clear();
for (var i = 0; i < SELECTED_INDICES.Count; i++)
{
if (i > 0)
STRING_BUILDER.Append(", ");
STRING_BUILDER.Append(SCENE_SHORT_NAMES[SELECTED_INDICES[i]]);
}
SCENE_LABEL = STRING_BUILDER.ToString();
}
public override float CalculateWidth()
{
return 100.0f;
return 124.0f;
}
public static void SetAsDirty()
@ -152,6 +227,7 @@ namespace Module.NavigationTool.Editor.Toolbar
private sealed class SceneSortElement
{
public readonly List<string> names = new List<string>();
public readonly List<string> shortNames = new List<string>();
public readonly List<string> paths = new List<string>();
}
}

View file

@ -11,8 +11,12 @@ namespace Module.NavigationTool.Editor.Toolbar
{
EditorApplication.playModeStateChanged += OnPlayModeStateChanged;
SceneManager.activeSceneChanged += OnActiveSceneChanged;
SceneManager.sceneLoaded += OnSceneLoaded;
SceneManager.sceneUnloaded += OnSceneUnloaded;
EditorSceneManager.newSceneCreated += OnNewSceneCreated;
EditorSceneManager.activeSceneChangedInEditMode += OnActiveSceneChangedInEditMode;
EditorSceneManager.sceneOpened += OnSceneOpened;
EditorSceneManager.sceneClosed += OnSceneClosed;
}
private static void OnPlayModeStateChanged(PlayModeStateChange state)
@ -24,6 +28,16 @@ namespace Module.NavigationTool.Editor.Toolbar
{
ToolScenePicker.SetAsDirty();
}
private static void OnSceneLoaded(Scene scene, LoadSceneMode mode)
{
ToolScenePicker.SetAsDirty();
}
private static void OnSceneUnloaded(Scene arg0)
{
ToolScenePicker.SetAsDirty();
}
private static void OnActiveSceneChangedInEditMode(Scene from, Scene to)
{
@ -34,5 +48,15 @@ namespace Module.NavigationTool.Editor.Toolbar
{
ToolScenePicker.SetAsDirty();
}
private static void OnSceneOpened(Scene scene, OpenSceneMode mode)
{
ToolScenePicker.SetAsDirty();
}
private static void OnSceneClosed(Scene scene)
{
ToolScenePicker.SetAsDirty();
}
}
}

View file

@ -0,0 +1,45 @@
using JetBrains.Annotations;
using UnityEditor;
using UnityEngine;
using UTools = UnityEditor.Tools;
namespace Module.NavigationTool.Editor.Toolbar
{
[UsedImplicitly]
internal sealed class ToolTargetFrameRate : AbstractToolbarDrawer
{
public override bool Visible => ToolbarTargetFrameRateSettings.IsTargetFrameRateEnabled;
public override bool Enabled => true;
public override EToolbarPlacement Placement => EToolbarPlacement.Left;
public override int Priority => (int)EToolbarPriority.Low;
private const string TOOLTIP = "Adjust Application.targetFrameRate from [min;max] target frame rate";
private static readonly GUIContent LABEL_TARGET_FRAME_RATE = new GUIContent("Target frame rate", TOOLTIP);
private static readonly GUIContent LABEL_TARGET_FRAME_RATE_VALUE = new GUIContent("0", TOOLTIP);
protected override void Draw(Rect rect)
{
int value = Application.targetFrameRate;
LABEL_TARGET_FRAME_RATE_VALUE.text = value.ToString("0");
var r0 = new Rect(rect.x, rect.y - 2.0f, rect.width, rect.height * 0.5f);
var r1 = new Rect(rect.x + 4.0f, rect.y + 2.0f, rect.width - 8.0f, rect.height * 0.5f);
var r2 = new Rect(rect.x, r1.yMax, rect.width, rect.height * 0.5f);
EditorGUI.LabelField(r0, LABEL_TARGET_FRAME_RATE, styles.centeredMiniLabel);
EditorGUI.LabelField(r2, LABEL_TARGET_FRAME_RATE_VALUE, styles.centeredMiniLabel);
float temp = GUI.HorizontalSlider(r1, value, ToolbarTargetFrameRateSettings.TargetFrameRateMinValue, ToolbarTargetFrameRateSettings.TargetFrameRateMaxValue);
int iTemp = Mathf.RoundToInt(temp);
iTemp = Mathf.Clamp(iTemp, ToolbarTargetFrameRateSettings.TargetFrameRateMinValue, ToolbarTargetFrameRateSettings.TargetFrameRateMaxValue);
if (value != iTemp)
Application.targetFrameRate = iTemp;
}
public override float CalculateWidth()
{
return 100.0f;
}
}
}

View file

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: f4bbeb2ad2654431a57c36b7af639000
timeCreated: 1670355402

View file

@ -13,16 +13,21 @@ namespace Module.NavigationTool.Editor.Toolbar
public override EToolbarPlacement Placement => EToolbarPlacement.Left;
public override int Priority => (int)EToolbarPriority.Low;
private const string TOOLTIP = "Adjust Time.timeScale from [min;max] and snaps when value is approximately 1.0";
private static readonly GUIContent LABEL_TIME_SCALE = new GUIContent("Time scale", TOOLTIP);
private static readonly GUIContent LABEL_TIME_VALUE = new GUIContent("0.00", TOOLTIP);
protected override void Draw(Rect rect)
{
float value = Time.timeScale;
LABEL_TIME_VALUE.text = value.ToString("0.00");
var r0 = new Rect(rect.x, rect.y - 2.0f, rect.width, rect.height * 0.5f);
var r1 = new Rect(rect.x + 4.0f, rect.y + 2.0f, rect.width - 8.0f, rect.height * 0.5f);
var r2 = new Rect(rect.x, r1.yMax, rect.width, rect.height * 0.5f);
EditorGUI.LabelField(r0, "Time scale", EditorStyles.centeredGreyMiniLabel);
EditorGUI.LabelField(r2, value.ToString("0.00"), EditorStyles.centeredGreyMiniLabel);
EditorGUI.LabelField(r0, LABEL_TIME_SCALE, styles.centeredMiniLabel);
EditorGUI.LabelField(r2, LABEL_TIME_VALUE, styles.centeredMiniLabel);
float temp = GUI.HorizontalSlider(r1, value, ToolbarTimeSettings.TimeScaleMinValue, ToolbarTimeSettings.TimeScaleMaxValue);
temp = Mathf.Clamp(temp, ToolbarTimeSettings.TimeScaleMinValue, ToolbarTimeSettings.TimeScaleMaxValue);

View file

@ -13,12 +13,15 @@ namespace Module.NavigationTool.Editor.Toolbar
public override EToolbarPlacement Placement => EToolbarPlacement.Left;
public override int Priority => (int)EToolbarPriority.Medium - 1;
private static readonly GUIContent LABEL = new GUIContent("UI", "Toggles UI visible layer in SceneView");
protected override void Draw(Rect rect)
{
int layer = 1 << LayerMask.NameToLayer("UI");
bool value = (UTools.visibleLayers & layer) != 0;
bool temp = EditorGUI.Toggle(rect, value, styles.button);
GUI.Label(rect, "UI", styles.labelCenter);
GUI.Label(rect, LABEL, styles.labelCenter);
if (temp == value)
return;

View file

@ -1,4 +1,5 @@
using UnityEngine;
using UnityEditor;
using UnityEngine;
namespace Module.NavigationTool.Editor.Toolbar
{
@ -11,6 +12,12 @@ namespace Module.NavigationTool.Editor.Toolbar
public GUIStyle label;
public GUIStyle labelCenter;
public GUIStyle settingsGroup;
public GUIStyle centeredMiniLabel;
public GUIContent iconPlusSmall;
public GUIContent iconPlusTiny;
public GUIContent iconDisconnect;
private GUISkin skin;
public void Initialize(GUISkin skin)
@ -24,6 +31,16 @@ namespace Module.NavigationTool.Editor.Toolbar
slider = new GUIStyle(skin.FindStyle("ToolbarSlider"));
label = new GUIStyle(skin.FindStyle("ToolbarLabel"));
if (EditorGUIUtility.isProSkin)
{
centeredMiniLabel = EditorStyles.centeredGreyMiniLabel;
}
else
{
centeredMiniLabel = new GUIStyle(EditorStyles.centeredGreyMiniLabel);
centeredMiniLabel.normal.textColor = label.normal.textColor;
}
buttonNoPadding = new GUIStyle(skin.FindStyle("toolbarbutton"))
{
padding = new RectOffset()
@ -38,6 +55,10 @@ namespace Module.NavigationTool.Editor.Toolbar
{
margin = new RectOffset(8, 0, 8, 0)
};
iconPlusSmall = EditorGUIUtility.IconContent("d_CreateAddNew");
iconPlusTiny = EditorGUIUtility.IconContent("Toolbar Plus");
iconDisconnect = EditorGUIUtility.IconContent("d_CacheServerDisconnected");
}
}
}