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

249
CHANGELOG.md Normal file
View file

@ -0,0 +1,249 @@
# Change Log
All notable changes to this project will be documented in this file.
## [1.8.0] - 2022-12-07
### Added
- CHANGELOG.md
- Tooltips on all buttons and labels in toolbar tools
- Target frame rate with `[min;max]` slider in toolbar
- `PlayerPrefs` delete button added to toolbar
- Option to select Single/Additive scene load/unload to scene picker
- All `IToolbarSettings` will be grouped with a foldout-toggle in Preferences
## [1.7.2] - 2022-09-20
### Fixed
- Fixed issue, where changing scene by opening scene files would not refresh scene selection tool
## [1.7.1] - 2022-08-08
### Fixed
- Fixed compiler issue, due to `string.Join` with `char` not being available in Unity 2020
## [1.7.0] - 2022-06-26
### Added
- Option to sort scenes by asset labels in scene picker in toolbar
## [1.6.0] - 2022-06-25
### Added
- Position and rotation pivots for scene view toolbar menu which uses buttons, instead of toggle drop down menu
## [1.5.2] - 2022-02-15
### Fixed
- Fixed issue, where toolbar styles modified a style directly in a Unity GUISkin thereby given incorrect buttons in other windows
## [1.5.1] - 2022-02-14
### Added
- Added toolbar settings interface to readme file
## [1.5.0] - 2022-02-14
### Added
- Added interface and utility class for adding settings to toolbar settings provider
## [1.4.1] - 2022-02-13
### Fixed
- Fixed issue, where new build tools used unsupported styles in Unity 2019 and 2020
## [1.4.0] - 2022-02-13
### Added
- Build target picker and build button to toolbar
## [1.3.3] - 2022-01-28
### Added
- Setting time scale close to 1.0 in snap it to 1.0
## [1.3.2] - 2022-01-28
### Added
- Added min & max values for time slider
- Options for max time scale value in preferences
## [1.3.1] - 2022-01-21
### Fixed
- Removing all package scenes from ScenePicker, due to read-only scenes not being loadable
## [1.3.0] - 2022-01-20
### Added
- `EditorProjectPrefs`, so each project can have their own settings for history and favorites
## [1.2.0] - 2022-01-15
### Added
- Time scale to toolbar
## [1.1.0] - 2021-12-19
### Added
- README file with instructions about usage of the different tools
- ToolbarSettings, so visibility of tools can be set in Preferences/Module/Toolbar
- Priority for determining which order tools should be added on left and right side of play buttons
## [1.0.2] - 2021-12-17
### Fixed
- Fixed issue, where PrefabStage no longer was marked as experimental in Unity 2021
## [1.0.1] - 2021-11-19
### Changed
- Removed noisy debug log in toolbar, left in by mistake in [1.0.0]
## [1.0.0] - 2021-11-10
### Fixed
- Fixed issue, where toolbar elements could overlap with other toolbar elements in Unity 2020 and older
## [0.8.3] - 2021-10-16
### Fixed
- Fixed issue, where creating a new scene didn't set scene picker as dirty
## [0.8.2] - 2021-09-28
### Changed
- Removed scene listing from addressables, since it is too expensive (~220 times worse, then just running through entire `AssetDatabase` for scenes)
## [0.8.1] - 2021-09-26
### Fixed
- Fixed issue, where scenes in `EditorBuildSettings` and addressabels would appear multiple times, due to scenes in `EditorBuildSettings` automatically being added to addressables
## [0.8.0] - 2021-09-18
### Fixed
- Fixed issue, where a compiler error could result in a cascade of reflection exceptions from the toolbar
## [0.7.2] - 2021-09-17
### Added
- Added asset bundle and addressable scenes to scene picker
## [0.7.1] - 2021-09-13
### Changed
- Changed assembly definition name from `Game.NavigationTool.Editor` to `Module.NavigationTool.Editor`
## [0.7.0] - 2021-09-12
### Changed
- Changed namespace from `Game.*` to `Module.*`
## [0.6.6] - 2021-09-04
### Fixed
- Fixed issue, where scene picker wouldn't update correctly, when in play mode and changing active scene
- Fixed issue, where it wasn't possible to select canvas in prefab stage
## [0.6.5] - 2021-08-02
### Fixed
- Fixed issue, where canvas picker wouldn't update selection when changing scenes
## [0.6.4] - 2021-06-29
### Added
- Added log warning, if trying to focus on a canvas `NULL` object
## [0.6.3] - 2021-06-21
### Changed
- Replaced `IToolbarDrawer` with `AbstractToolbarDrawer` with rect and styles setup-handling
### Fixed
- Fixed issue, where toolbar items didn't accept mouse input in 2021 or newer versions
## [0.6.2] - 2021-04-27
### Added
- Added all scenes to Scene picker tool, where scenes from `EditorBuildSettings` will be marked with "(Build Settings)"-postfix
## [0.6.1] - 2021-04-12
### Fixed
- Fixed issue, where UI Canvas picker wasn't available in playmode
- Fixed issue, where UI Layer toggle wasn't available in playmode
## [0.6.0] - 2021-04-12
### Added
- UI Canvas picker to toolbar for easy selecting and centering a canvas in scene view
- UI Layer toggle to toolbar, so it can be turned on/off in scene view
## [0.5.0] - 2021-03-11
### Added
- Toolbar drawers for adding buttons next to play buttons
- Scene picker tool to toolbar for easy selecting between scenes in `EditorBuildSettings`
### Changed
- Keywords in manifest file to include toolbar
## [0.4.0] - 2021-02-14
### Added
- Double-clicking item in history window will now open asset in preferred tool
## [0.3.0] - 2021-02-14
### Added
- History window with a list of all prior selected objects
### Changed
- Keywords in manifest file to include favorites and history
## [0.2.0] - 2021-02-14
### Changed
- Added drag and drop between entries in favorites tree view
## [0.0.1] - 2021-02-14
### Added
- Favorites window with tree view, search and tools for adding, renaming, deleting items

7
CHANGELOG.md.meta Normal file
View file

@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 0c335fee33a70e64d980987fb90ddf68
TextScriptImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -1,3 +1,4 @@
using System;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
@ -9,6 +10,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()
{
@ -47,12 +50,43 @@ namespace Module.NavigationTool.Editor.Toolbar
{
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
{
@ -26,6 +27,12 @@ namespace Module.NavigationTool.Editor.Toolbar
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

@ -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 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 int SELECTED_INDEX = -1;
private static string[] OPTIONS = new string[0];
private static string[] PATHS = new string[0];
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);
InitializeBuildSettingsScenes(listNames, listShortNames, listPaths);
InitializeRemainingScenes(listNames, listShortNames, listPaths);
OPTIONS = listNames.ToArray();
PATHS = listPaths.ToArray();
for (var i = 0; i < SceneManager.sceneCount; i++)
{
Scene scene = SceneManager.GetSceneAt(i);
int index = listPaths.IndexOf(scene.path);
Scene activeScene = SceneManager.GetActiveScene();
SELECTED_INDEX = listPaths.IndexOf(activeScene.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,9 +125,11 @@ 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);
}
}
@ -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);
int sceneIndex = i;
menu.AddItem(new GUIContent(SCENE_NAMES[i]), SELECTED_INDICES.Contains(i), () => SelectScene(sceneIndex));
}
if (scene.isLoaded)
SELECTED_INDEX = temp;
}
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)
@ -25,6 +29,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)
{
ToolScenePicker.SetAsDirty();
@ -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");
}
}
}

View file

@ -1,6 +1,6 @@
{
"name": "com.module.navigationtool",
"version": "1.7.2",
"version": "1.8.0",
"displayName": "Module.NavigationTool",
"description": "Support for navigation tools, like favorites, history and toolbars",
"unity": "2019.2",