mirror of
https://github.com/godotengine/godot-cpp-template.git
synced 2025-12-31 21:48:10 +03:00
Add an example class and some demo code to the project.
This commit is contained in:
6
demo/example.gd
Normal file
6
demo/example.gd
Normal file
@@ -0,0 +1,6 @@
|
||||
extends Node
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
var example := ExampleClass.new()
|
||||
example.print_type(example)
|
||||
6
demo/example.tscn
Normal file
6
demo/example.tscn
Normal file
@@ -0,0 +1,6 @@
|
||||
[gd_scene load_steps=2 format=3 uid="uid://dh0oj81pufivs"]
|
||||
|
||||
[ext_resource type="Script" path="res://example.gd" id="1_jdh55"]
|
||||
|
||||
[node name="Node" type="Node"]
|
||||
script = ExtResource("1_jdh55")
|
||||
20
doc_classes/ExampleClass.xml
Normal file
20
doc_classes/ExampleClass.xml
Normal file
@@ -0,0 +1,20 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<class name="ExampleClass" inherits="RefCounted" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://raw.githubusercontent.com/godotengine/godot/master/doc/class.xsd">
|
||||
<brief_description>
|
||||
Example class.
|
||||
</brief_description>
|
||||
<description>
|
||||
An example class.
|
||||
</description>
|
||||
<tutorials>
|
||||
</tutorials>
|
||||
<methods>
|
||||
<method name="print_type" qualifiers="const">
|
||||
<return type="void" />
|
||||
<param index="0" name="variant" type="Variant" />
|
||||
<description>
|
||||
Print the type of the variant.
|
||||
</description>
|
||||
</method>
|
||||
</methods>
|
||||
</class>
|
||||
9
src/example_class.cpp
Normal file
9
src/example_class.cpp
Normal file
@@ -0,0 +1,9 @@
|
||||
#include "example_class.h"
|
||||
|
||||
void ExampleClass::_bind_methods() {
|
||||
godot::ClassDB::bind_method(D_METHOD("print_type", "variant"), &ExampleClass::print_type);
|
||||
}
|
||||
|
||||
void ExampleClass::print_type(const Variant &p_variant) const {
|
||||
print_line(vformat("Type: %d", p_variant.get_type()));
|
||||
}
|
||||
20
src/example_class.h
Normal file
20
src/example_class.h
Normal file
@@ -0,0 +1,20 @@
|
||||
#pragma once
|
||||
|
||||
#include "godot_cpp/classes/ref_counted.hpp"
|
||||
#include "godot_cpp/classes/wrapped.hpp"
|
||||
#include "godot_cpp/variant/variant.hpp"
|
||||
|
||||
using namespace godot;
|
||||
|
||||
class ExampleClass : public RefCounted {
|
||||
GDCLASS(ExampleClass, RefCounted)
|
||||
|
||||
protected:
|
||||
static void _bind_methods();
|
||||
|
||||
public:
|
||||
ExampleClass() = default;
|
||||
~ExampleClass() override = default;
|
||||
|
||||
void print_type(const Variant &p_variant) const;
|
||||
};
|
||||
@@ -1,9 +1,12 @@
|
||||
#include "register_types.h"
|
||||
|
||||
#include <gdextension_interface.h>
|
||||
#include <godot_cpp/core/class_db.hpp>
|
||||
#include <godot_cpp/core/defs.hpp>
|
||||
#include <godot_cpp/godot.hpp>
|
||||
|
||||
#include "example_class.h"
|
||||
|
||||
using namespace godot;
|
||||
|
||||
void initialize_gdextension_types(ModuleInitializationLevel p_level)
|
||||
@@ -11,7 +14,7 @@ void initialize_gdextension_types(ModuleInitializationLevel p_level)
|
||||
if (p_level != MODULE_INITIALIZATION_LEVEL_SCENE) {
|
||||
return;
|
||||
}
|
||||
//GDREGISTER_CLASS(YourClass);
|
||||
GDREGISTER_CLASS(ExampleClass);
|
||||
}
|
||||
|
||||
void uninitialize_gdextension_types(ModuleInitializationLevel p_level) {
|
||||
|
||||
Reference in New Issue
Block a user