public override VisualElement CreateInspectorGUI() { StyleSheet selectedTBStyle = Resources.Load <StyleSheet>("TMEditorUi"); var ve = new VisualElement(); var tb = new Toolbar(); tb.Add(new ToolbarButton()); tb.Add(new ToolbarButton()); tb.Add(new ToolbarButton()); foreach (var visualElement in tb.Children()) { ToolbarButton child = (ToolbarButton)visualElement; if (child != null) { child.styleSheets.Add(selectedTBStyle); } } IMGUIContainer defaultInspectorIMGUI = new IMGUIContainer() { onGUIHandler = () => { DrawDefaultInspector(); } }; ve.Add(tb); ve.Add(defaultInspectorIMGUI); return(ve); }
/// <summary> /// Sets up a "homemade" toggle button in the toolbar. /// <para> /// sets the "inactive" class on all the toolbar's buttons, and sets the given tool as the active one if it isn't active, otherwise sets the active tool to none /// </para> /// </summary> void SetupToolButton(ToolbarButton button, Tools tool) { button.clickable.clicked += () => { Toolbar toolbar = rootVisualElement.Q <Toolbar>("toolbar"); foreach (VisualElement e in toolbar.Children()) { e.RemoveFromClassList("tool-active"); e.AddToClassList("tool-inactive"); } if (activeTool != tool) { button.AddToClassList("tool-active"); button.RemoveFromClassList("tool-inactive"); activeTool = tool; } else { activeTool = Tools.none; } }; }