diff --git a/Editor/Scripts/Element.meta b/Editor/Scripts/Element.meta new file mode 100644 index 0000000..f1fd715 --- /dev/null +++ b/Editor/Scripts/Element.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: d7e9d742b236d154fa0d5d876d1d4401 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Editor/Scripts/Element/ToolbarDropdownToggle.cs b/Editor/Scripts/Element/ToolbarDropdownToggle.cs new file mode 100644 index 0000000..63688fb --- /dev/null +++ b/Editor/Scripts/Element/ToolbarDropdownToggle.cs @@ -0,0 +1,65 @@ +using UnityEditor.UIElements; +using UnityEngine.UIElements; + +namespace GBG.PlayableGraphMonitor.Editor +{ + public class ToolbarDropdownToggle : VisualElement, INotifyValueChanged + { + private readonly ToolbarToggle _toggle; + private readonly ToolbarMenu _menu; + + public string text + { + get => _toggle.text; + set => _toggle.text = value; + } + public string label + { + get => _toggle.label; + set => _toggle.label = value; + } + public Label labelElement => _toggle.labelElement; + public new string tooltip + { + get => _toggle.tooltip; + set => _toggle.tooltip = value; + } + public bool value + { + get => _toggle.value; + set => _toggle.value = value; + } + public string menuTooltip + { + get => _menu.tooltip; + set => _menu.tooltip = value; + } + public DropdownMenu menu => _menu.menu; + public ToolbarMenu.Variant menuVariant + { + get => _menu.variant; + set => _menu.variant = value; + } + + + public ToolbarDropdownToggle() + { + style.flexDirection = FlexDirection.Row; + style.flexShrink = 0; + + _toggle = new ToolbarToggle(); + _toggle.style.borderRightWidth = 0; + _toggle.style.minWidth = 0; + Add(_toggle); + + _menu = new ToolbarMenu(); + _menu.style.borderLeftWidth = 0; + Add(_menu); + } + + public void SetValueWithoutNotify(bool newValue) + { + _toggle.SetValueWithoutNotify(newValue); + } + } +} \ No newline at end of file diff --git a/Editor/Scripts/Element/ToolbarDropdownToggle.cs.meta b/Editor/Scripts/Element/ToolbarDropdownToggle.cs.meta new file mode 100644 index 0000000..50cb8a6 --- /dev/null +++ b/Editor/Scripts/Element/ToolbarDropdownToggle.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 71350c6849af6c845bf8031854ca8e71 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Editor/Scripts/Window/PlayableGraphMonitorWindow.cs b/Editor/Scripts/Window/PlayableGraphMonitorWindow.cs index caf89dd..570e024 100644 --- a/Editor/Scripts/Window/PlayableGraphMonitorWindow.cs +++ b/Editor/Scripts/Window/PlayableGraphMonitorWindow.cs @@ -228,12 +228,6 @@ private void OnDestroyingGraph(PlayableGraph graph) void IHasCustomMenu.AddItemsToMenu(GenericMenu menu) { -#if UNITY_2021_1_OR_NEWER - menu.AddItem(new GUIContent("Show clip progress bar title (will degrade performance)"), - _viewUpdateContext.ShowClipProgressBarTitle, OnToggleShowClipProgressBarTitle); - menu.AddSeparator(""); -#endif - // Source Code menu.AddItem(new GUIContent("Source Code"), false, () => { @@ -241,11 +235,6 @@ void IHasCustomMenu.AddItemsToMenu(GenericMenu menu) }); } - private void OnToggleShowClipProgressBarTitle() - { - _viewUpdateContext.ShowClipProgressBarTitle = !_viewUpdateContext.ShowClipProgressBarTitle; - } - #endregion } } \ No newline at end of file diff --git a/Editor/Scripts/Window/PlayableGraphMonitorWindow_Toolbar.cs b/Editor/Scripts/Window/PlayableGraphMonitorWindow_Toolbar.cs index c27067d..357c78c 100644 --- a/Editor/Scripts/Window/PlayableGraphMonitorWindow_Toolbar.cs +++ b/Editor/Scripts/Window/PlayableGraphMonitorWindow_Toolbar.cs @@ -95,16 +95,29 @@ private void CreateToolbar() _toolbar.Add(_inspectorToggle); // Clip ProgressBar toggle - var clipProgressBarToggle = new ToolbarToggle() + var clipProgressDropdownToggle = new ToolbarDropdownToggle() { text = "Clip Progress", tooltip = "Disabling this option can significantly improve performance.", value = _viewUpdateContext.ShowClipProgressBar, }; - clipProgressBarToggle.RegisterValueChangedCallback(ToggleDisplayClipProgressBar); - clipProgressBarToggle.Q(className: "unity-text-element").style.color = NormalTextColor; - _toolbar.Add(clipProgressBarToggle); + clipProgressDropdownToggle.RegisterValueChangedCallback(ToggleDisplayClipProgressBar); + clipProgressDropdownToggle.Q(className: "unity-text-element").style.color = NormalTextColor; + clipProgressDropdownToggle.menu.AppendAction("Progress Text (Low-Performance)", + ToggleDisplayClipProgressBarText, + (_) => + { + var @checked = _viewUpdateContext.ShowClipProgressBarTitle + ? DropdownMenuAction.Status.Checked + : DropdownMenuAction.Status.Normal; + var disabled = _viewUpdateContext.ShowClipProgressBar + ? DropdownMenuAction.Status.Normal + : DropdownMenuAction.Status.Disabled; + return @checked | disabled; + }); + _toolbar.Add(clipProgressDropdownToggle); + // Update edge toggle var updateEdgeToggle = new ToolbarToggle() { text = "Always Update Edges", @@ -157,6 +170,7 @@ private void CreateToolbar() var frameAllButton = new ToolbarButton(OnFrameAllButtonClicked) { text = "Frame All", + style = { flexShrink = 0 }, }; frameAllButton.Q(className: "unity-text-element").style.color = NormalTextColor; _toolbar.Add(frameAllButton); @@ -165,7 +179,8 @@ private void CreateToolbar() _toolbar.Add(new ToolbarSpacer()); _selectOutputNodeMenu = new ToolbarMenu { - text = "Select Output Node" + text = "Select Output Node", + style = { flexShrink = 0 }, }; _selectOutputNodeMenu.RegisterCallback(OnHoverSelectOutputNodeMenu); _toolbar.Add(_selectOutputNodeMenu); @@ -173,7 +188,8 @@ private void CreateToolbar() // Select root node _selectRootNodeMenu = new ToolbarMenu { - text = "Select Root Node" + text = "Select Root Node", + style = { flexShrink = 0 }, }; _selectRootNodeMenu.RegisterCallback(OnHoverSelectRootNodeMenu); _toolbar.Add(_selectRootNodeMenu); @@ -221,6 +237,11 @@ private void ToggleDisplayClipProgressBar(ChangeEvent evt) _viewUpdateContext.ShowClipProgressBar = evt.newValue; } + private void ToggleDisplayClipProgressBarText(DropdownMenuAction _) + { + _viewUpdateContext.ShowClipProgressBarTitle = !_viewUpdateContext.ShowClipProgressBarTitle; + } + private void ToggleKeepUpdatingEdges(ChangeEvent evt) { _viewUpdateContext.KeepUpdatingEdges = evt.newValue; diff --git a/package.json b/package.json index e573aa5..68ac680 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "com.greenbamboogames.playablegraphmonitor", - "version": "2.5.8", + "version": "2.5.9", "displayName": "PlayableGraph Monitor!", "description": "PlayableGraph monitor.", "unity": "2019.4",