Game Development Reference
In-Depth Information
void Initialize(IEditor* pEditor)
{
REGISTER_COMMAND(example_my_command1);
REGISTER_COMMAND(example_my_command2);
}
// used to check if a command is disabled at that time
// can be helpful for UI to disable buttons in toolbars
// or other related visual feedback
bool IsCommandEnabled(TPfnCommand pCmdFunc)
{
return true;
}
void Shutdown()
{
}
END_PLUGIN
Note that
BEGIN_PLUGIN
and
END_PLUGIN
are macros hiding the start/end of the
IPlugin
interface
implementation. The
Initialize
method is called when the plug-in is loaded into the editor. You are also registering
the plug-in's commands by just referring invoking the global functions
example_my_command1
and
example_my_
command1
. The
Shutdown
method is called when the plug-in is unloaded (no need to call the unregister commands;
this can be tracked and executed by the editor core itself, since it knows the
IPlugin p
ointer when the commands are
registered). The
IsCommandEnabled
method is used to verify whether a command has the status of “enabled” so it can
be called/executed.
Be sure to name the commands in a way that avoids conflicts. Usually some sort of group naming, like the name
of the plug-in and the actual command action name, should be enough, like
assets_reload
,
assets_set_tag
,
assets_delete
, or if you prefer camel-case style,
Assets_SetTag
.
The generated plug-in will be named
example.dll
and will be accompanied by its manifest file,
example.plugin.xml
. Of course, the plug-in must export a
CreatePluginInstance
global function so the editor core
can load it and instantiate the
IPlugin
implementation.
Events
To make the plug-ins aware of events occurring in the editor ecosystem, they can register themselves as event sinks,
as shown in Listing 11-16.
Listing 11-16.
An Event Sink, Which Can Be Implemented by the Plug-ins
// Every plug-in can register its event sink so it can
// receive notifications about events happening in the
// editor ecosystem, coming from other plug-ins or the
// editor core itself
struct IEventSink
{
// When the event sink call is received, before, during or
// after the event was consumed
// The eTriggerContext_During can be used to have
// lengthy events being processed and many triggered to