Creating Toolbar Items

Creating Toolbar Items is a relative simple task.

How it works

Create an editor class

Toolbar items are created by creating an editor class that inherits from one of the ToolbarItem base classes:

Class Purpose
DTToolbarButton Simple Button
DTToolbarToggleButton State Button
DTToolbarRadioButton State Button being part of a Radiogroup (always one selected)
DTToolbarRadioOffButton State Button being part of a Radiogroup (one or none selected)

ToolbarItemAttribute

To make the toolbar recognize your class, add a class attribute to your class:

[ToolbarItem(10,"Curvy","MyButton","My tooltip","myIcon,24,24","myLightSkinIcon,24,24")] 
  • Order - items are sorted by their order (ascending)
  • Project - the project name. Needs to be “Curvy”
  • Label - the button's label
  • Tooltip - a tooltip
  • Icon - item's icon in the form “name,width,height”. The file needs to be in a folder called “Resources”
  • LightIcon - (optional) the icon to use for light skin editor.

Add functionality

After that, you'll want to override or implement a few methods and properties to add functionality:

Method/Property Purpose Remarks
Ctor Constructor Add hotkey bindings here!
StatusBarInfo Gets the statusbar text to show when hovering over the item
OnSelectionChange() Called when hierarchy selection changes Set Visibility here at least!
OnClick() Called when the item is clicked
OnOtherItemClicked() Called when any other item is clicked Use this to e.g. set ShowClientArea
RenderClientArea() Called when additional UI should be drawn
OnSceneGUI() Regular OnSceneGUI call For preview or other SceneView drawing
HandleEvents() Called for UI events Use to catch additional hotkeys etc.

The best way to get you started is to check CurvyToolbar.cs and examine an item with same or similiar functionality you have in mind!

Example

    [ToolbarItem(161,"Curvy","Set 1.","Set as first Control Point","setfirstcp,24,24")]
    public class TBCPSetFirst : DTToolbarButton
    {
        public override string StatusBarInfo { get { return "Make this Control Point the first of the spline"; } }

        public TBCPSetFirst()
        {
            KeyBindings.Add(new EditorKeyBinding("Set 1. CP",""));
        }

        public override void OnClick()
        {
            base.OnClick();
            var cp = DTSelection.GetAs<CurvySplineSegment>();
            if (cp)
            {
                Undo.RegisterFullObjectHierarchyUndo(cp.Spline, "Set first CP");
                cp.SetAsFirstCP();
            }
        }

        public override void OnSelectionChange()
        {
            base.OnSelectionChange();
            var cp=DTSelection.GetAs<CurvySplineSegment>();
            Visible = (cp != null);
            Enabled= Visible && cp.ControlPointIndex>0;
        }
    }
    

Item Types Reference

For all item types, use OnSelectionChange() to set Visible and Enabled

Buttons

OnClick() is called on button click

Toggle Buttons

Use the On property to get or set the button's state.

Additional UI

Override RenderClientArea() to show additional UI when the item is selected. The provided Rect parameter defines the starting position of the client area. Because toolbars can be shown on any side of the SceneView, you should use the provided methods to change the rect according to the toolbar's orientation:

  • Background() - renders a background box to host your content
  • SetElementSize() - define a single emement's size, used by the following methods (this is most useful if you're showing a submenu):
  • Advance() - advance the rect to a new line (top,bottom) or towards the inner (left,right)
  • AdvanceBelow() - advance the rect to a new line only

RadioButton

Use RadioGroup to define the button's group.

Discussion

Enter your comment:
Y S N W P
 
Last modified: 2015/09/25 20:49 by Jake