Custom Editor Plugins
With a plugin system, customizing the Unigine editor for project-specific needs is very easy. After a script with custom functionality is coded, adding new tabs into the default windows or new editor modules, as well as changing a set of editor features for different projects is just a few clicks away.
To load editor plugins, choose Tools panel -> Plugins tab -> Add option. Plugins are saved and automatically loaded on the next application start-up.
Step 1. Create an Editor Plugin
A plugin is any *.cpp file written in UnigineScript language.
- An editor plugin should contain getName() function that returns an arbitrary namespace name for the plugin. Use this namespace for all created GUI elements and callbacks, or if you need to call plugin functions from outside a plugin namespace.
- To code plugin logic, implement init() and shutdown() functions. They will be called on editor initialization and shutdown, respectively.
- If necessary, implement also update() function that is called each frame while the editor is loaded. The engine passes to this function need_reload flag that indicates you may need to reload your custom resources. This flag is 1 when:
Below is an example of a plugin that creates a simple titled window.
// editor_plugin.cpp
WidgetWindow window;
/*
*/
// This function should return your plugin namespace name.
string getName() {
return "TestPlugin";
}
/*
*/
// Implement plugin initialization logic.
void init() {
Gui gui = engine.getGui();
window = new WidgetWindow(gui);
window.setText("Title");
window.setSizeable(1);
window.setWidth(300);
window.setHeight(300);
gui.addChild(window,GUI_ALIGN_OVERLAP | GUI_ALIGN_CENTER);
// If you want to call a plugin function from the outside, add a plugin namespace name.
log.message("Plugin namespace: %s\n",call("TestPlugin::getName"));
}
/*
*/
// Implement plugin shutdown logic.
void shutdown() {
Gui gui = engine.getGui();
gui.removeChild(window);
delete window;
log.message("shut down");
}
/*
*/
// Implement plugin update logic.
void update(int need_reload) {
// The flag of 1 indicates that the editor resources should be updated.
if(need_reload) {
// Update custom resources, if necessary.
}
}
Step 2. Load Editor Plugins
To load the created editor plugin, all you need to do is:
The plugin will appear in a list. Multiple plugins can be loaded in editor runtime.
Step 3. Modify Editor Plugins
After the editor plugin is modified, you can quickly see changes in action:
- Select the plugin in the list of loaded ones.
- Click Reload button.