The edit modes are used for contextual separation of operations executed in the editor.
A single edit mode can be active only in the editor.
The current edit mode is updated by the editor main loop (by calling its onUpdate) every frame.
There you can check for example ray scene intersections if you have some specific operation for that, you can also render various debug geometry and so on.
To add a new edit mode to the editor, you create a new field in the editor.editModes
table, check the available field names in that array Built-in Edit Modes
.
The edit modes will appear (sorted by name) in the edit modes toolbar.
For example, selecting the object select edit mode: editor.selectEditMode(editor.editModes.objectSelect)
To add new icons in the editor icon atlas, read Adding custom icons
To add an edit mode to the editor it is recommended you do it in your extension onEditorInitialized
function,
like so:
local function myCustomEditModeActivate()
-- here you prepare your edit mode variables
end
local function myCustomEditModeDeactivate()
-- here you cleanup your edit mode caches or other things
end
local function myCustomEditModeUpdate()
-- here you draw your debug edit mode geometry, check mouse clicks, etc.
end
local function myCustomEditModeToolbar()
-- here you draw your custom mode vertical toolbar buttons
-- example two buttons for translate and rotate
if editor.uiIconImageButton(editor.icons.open_with, nil, imgui.ImColorByRGB(255,255,255,255).Value, nil, imgui.ImColorByRGB(128,128,128,128).Value) then
worldEditorCppApi.setAxisGizmoMode(1)
end
if imgui.IsItemHovered() then imgui.BeginTooltip() imgui.Text("Translate") imgui.EndTooltip() end
if editor.uiIconImageButton(editor.icons.refresh, nil, imgui.ImColorByRGB(255,255,255,255).Value, nil, imgui.ImColorByRGB(128,128,128,128).Value) then
worldEditorCppApi.setAxisGizmoMode(2)
end
if imgui.IsItemHovered() then imgui.BeginTooltip() imgui.Text("Rotate") imgui.EndTooltip() end
end
local function onEditorInitialized()
editor.editModes.myCustomEditMode =
{
displayName = "My Custom Edit Mode"
onActivate = myCustomEditModeActivate,
onDeactivate = myCustomEditModeDeactivate,
onUpdate = myCustomEditModeUpdate,
onToolbar = myCustomEditModeToolbar,
actionMap = "myCustom", -- if available, not required
icon = editor.icons.satellite,
iconTooltip = "My Custom"
}
end
M.onEditorInitialized = onEditorInitialized
--..........................................
-- and for example somewhere in a menu or toolbar button, you activate your edit mode
editor.selectEditMode(editor.editModes.myCustomEditMode)