Custom Object Create Toolbar Buttons

The editor has a create object toolbar that is made of object classes groups buttons and for each group button when pressed, it will show the object classes available to create in that current group. To add a create group or a new button for creating new types of objects, we can use a special API like in the next example:

Custom Create Object Group Buttons
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
    local function buildMyObject1(obj)
            -- set some obj's default fields, do various linkings etc.
    end

    local function buildMyObject2(obj)
            -- set some obj's default fields, do various linkings etc.
    end

    local function buildMyObject3(obj)
            -- set some obj's default fields, do various linkings etc.
    end

    local function onEditorInitialized()
            -- add the new create object group with some new classes we have in C++
            editor.addObjectCreateGroup("Test Group", editor.icons.goat,
            {
            -- add some buttons for some classes to create instances for
            -- params:
            -- icon, C++ classname, display name,
            -- [optional] function where you setup the new object,
            -- [optional] single instance, true if clicking the button will create a single instance, false if you want to repeat clicking in the viewport and create multiple instances until ESC pressed
                    editor.makeCreateObjectItem(editor.icons.goat, "TestCppClass1", "Test Title1", buildMyObject1),
                    editor.makeCreateObjectItem(editor.icons.goat, "TestCppClass2", "Test Title2", buildMyObject2),
                    editor.makeCreateObjectItem(editor.icons.goat, "TestCppClass3", "Test Title3", buildMyObject3)
            })
    end

    M.onEditorInitialized = onEditorInitialized

Also check the API for Create Objects Toolbar API.

../../../_images/preferences.png