一、创建自定义属性类型及代码分析
向插件的构造函数中添加一些代码,其中,第5-23行为新添加代码
class PLUGINDEMO_API Plugindemo : public kanzi::Node3D
{
public:
//字符串属性
static kanzi::PropertyType<kanzi::string> StringProperty;
//引用节点的字符串
static kanzi::PropertyType<kanzi::string> NodeRefByStringProperty;
//引用预设件的字符串
static kanzi::PropertyType<kanzi::string> PrefabRefByStringProperty;
//引用预设件的共享指针
static kanzi::PropertyType<kanzi::ResourceSharedPtr> PrefabRefBySharedPtrProperty;
//引用材质的共享指针
static kanzi::PropertyType<kanzi::ResourceSharedPtr> MaterialRefBySharedPtrProperty;
KZ_METACLASS_BEGIN(Plugindemo, Node3D, "MyNode")
//将属性类型添加到类元数据。
KZ_METACLASS_PROPERTY_TYPE(StringProperty)
KZ_METACLASS_PROPERTY_TYPE(NodeRefByStringProperty)
KZ_METACLASS_PROPERTY_TYPE(PrefabRefByStringProperty)
KZ_METACLASS_PROPERTY_TYPE(PrefabRefBySharedPtrProperty)
KZ_METACLASS_PROPERTY_TYPE(MaterialRefBySharedPtrProperty)
KZ_METACLASS_END()
static kanzi::PropertyTypeEditorInfoSharedPtr makeEditorInfo();
// Creates a Plugindemo.
static PlugindemoSharedPtr create(kanzi::Domain* domain, kanzi::string_view name);
protected:
// Constructor.
explicit Plugindemo(kanzi::Domain* domain, kanzi::string_view name):
kanzi::Node3D(domain, name)
{
}
// Initializes the created Kanzi Engine plugin.
// Kanzi node classes typically have a static create() member function, which creates the instance of a node,
// initializes it, and returns a shared pointer to the instance. To initialize the instance, the initialize()
// function is called on it. You must initialize a node in the initialize() function, not in the constructor.
void initialize();
};
上述代码中PropertyType是一个模板类,利用该模板类声明了五个属性对象。在
K

本文介绍如何在Kanzi Engine中创建自定义属性类型并应用于插件。通过实例展示了不同类型的属性如字符串、资源引用等的定义过程及其编辑器元数据配置。
最低0.47元/天 解锁文章
1279

被折叠的 条评论
为什么被折叠?



