Allow registering "runtime classes"

This commit is contained in:
David Snopek
2023-09-29 16:30:59 -05:00
parent 5fcc43e54d
commit fb884573ea
7 changed files with 104 additions and 9 deletions

View File

@@ -637,3 +637,23 @@ String Example::test_virtual_implemented_in_script(const String &p_name, int p_v
}
return "Unimplemented";
}
void ExampleRuntime::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_prop_value", "value"), &ExampleRuntime::set_prop_value);
ClassDB::bind_method(D_METHOD("get_prop_value"), &ExampleRuntime::get_prop_value);
ADD_PROPERTY(PropertyInfo(Variant::INT, "prop_value"), "set_prop_value", "get_prop_value");
}
void ExampleRuntime::set_prop_value(int p_prop_value) {
prop_value = p_prop_value;
}
int ExampleRuntime::get_prop_value() const {
return prop_value;
}
ExampleRuntime::ExampleRuntime() {
}
ExampleRuntime::~ExampleRuntime() {
}

View File

@@ -220,4 +220,20 @@ protected:
virtual int test_function() override { return 25; }
};
class ExampleRuntime : public Node {
GDCLASS(ExampleRuntime, Node);
int prop_value = 12;
protected:
static void _bind_methods();
public:
void set_prop_value(int p_prop_value);
int get_prop_value() const;
ExampleRuntime();
~ExampleRuntime();
};
#endif // EXAMPLE_CLASS_H

View File

@@ -27,6 +27,7 @@ void initialize_example_module(ModuleInitializationLevel p_level) {
ClassDB::register_class<ExampleVirtual>(true);
ClassDB::register_abstract_class<ExampleAbstractBase>();
ClassDB::register_class<ExampleConcrete>();
ClassDB::register_runtime_class<ExampleRuntime>();
}
void uninitialize_example_module(ModuleInitializationLevel p_level) {