summaryrefslogtreecommitdiff
path: root/modules/mono/editor_templates
diff options
context:
space:
mode:
Diffstat (limited to 'modules/mono/editor_templates')
-rw-r--r--modules/mono/editor_templates/CharacterBody2D/basic_movement.cs41
-rw-r--r--modules/mono/editor_templates/CharacterBody3D/basic_movement.cs44
-rw-r--r--modules/mono/editor_templates/EditorPlugin/plugin.cs19
-rw-r--r--modules/mono/editor_templates/EditorScript/basic_editor_script.cs14
-rw-r--r--modules/mono/editor_templates/Node/default.cs19
-rw-r--r--modules/mono/editor_templates/Object/empty.cs9
-rw-r--r--modules/mono/editor_templates/SCsub16
7 files changed, 162 insertions, 0 deletions
diff --git a/modules/mono/editor_templates/CharacterBody2D/basic_movement.cs b/modules/mono/editor_templates/CharacterBody2D/basic_movement.cs
new file mode 100644
index 0000000000..6e9547ce9b
--- /dev/null
+++ b/modules/mono/editor_templates/CharacterBody2D/basic_movement.cs
@@ -0,0 +1,41 @@
+// meta-description: Classic movement for gravity games (platformer, ...)
+
+using _BINDINGS_NAMESPACE_;
+using System;
+
+public partial class _CLASS_ : _BASE_
+{
+ public const float Speed = 300.0f;
+ public const float JumpForce = -400.0f;
+
+ // Get the gravity from the project settings to be synced with RigidDynamicBody nodes.
+ public float gravity = (float)ProjectSettings.GetSetting("physics/2d/default_gravity");
+
+ public override void _PhysicsProcess(float delta)
+ {
+ Vector2 motionVelocity = MotionVelocity;
+
+ // Add the gravity.
+ if (!IsOnFloor())
+ motionVelocity.y += gravity * delta;
+
+ // Handle Jump.
+ if (Input.IsActionJustPressed("ui_accept") && IsOnFloor())
+ motionVelocity.y = JumpForce;
+
+ // Get the input direction and handle the movement/deceleration.
+ // As good practice, you should replace UI actions with custom gameplay actions.
+ Vector2 direction = Input.GetVector("ui_left", "ui_right", "ui_up", "ui_down");
+ if (direction != Vector2.Zero)
+ {
+ motionVelocity.x = direction.x * Speed;
+ }
+ else
+ {
+ motionVelocity.x = Mathf.MoveToward(MotionVelocity.x, 0, Speed);
+ }
+
+ MotionVelocity = motionVelocity;
+ MoveAndSlide();
+ }
+}
diff --git a/modules/mono/editor_templates/CharacterBody3D/basic_movement.cs b/modules/mono/editor_templates/CharacterBody3D/basic_movement.cs
new file mode 100644
index 0000000000..13be4bbcb1
--- /dev/null
+++ b/modules/mono/editor_templates/CharacterBody3D/basic_movement.cs
@@ -0,0 +1,44 @@
+// meta-description: Classic movement for gravity games (FPS, TPS, ...)
+
+using _BINDINGS_NAMESPACE_;
+using System;
+
+public partial class _CLASS_ : _BASE_
+{
+ public const float Speed = 5.0f;
+ public const float JumpForce = 4.5f;
+
+ // Get the gravity from the project settings to be synced with RigidDynamicBody nodes.
+ public float gravity = (float)ProjectSettings.GetSetting("physics/3d/default_gravity");
+
+ public override void _PhysicsProcess(float delta)
+ {
+ Vector3 motionVelocity = MotionVelocity;
+
+ // Add the gravity.
+ if (!IsOnFloor())
+ motionVelocity.y -= gravity * delta;
+
+ // Handle Jump.
+ if (Input.IsActionJustPressed("ui_accept") && IsOnFloor())
+ motionVelocity.y = JumpForce;
+
+ // Get the input direction and handle the movement/deceleration.
+ // As good practice, you should replace UI actions with custom gameplay actions.
+ Vector2 inputDir = Input.GetVector("ui_left", "ui_right", "ui_up", "ui_down");
+ Vector3 direction = Transform.basis.Xform(new Vector3(inputDir.x, 0, inputDir.y)).Normalized();
+ if (direction != Vector3.Zero)
+ {
+ motionVelocity.x = direction.x * Speed;
+ motionVelocity.z = direction.z * Speed;
+ }
+ else
+ {
+ motionVelocity.x = Mathf.MoveToward(MotionVelocity.x, 0, Speed);
+ motionVelocity.z = Mathf.MoveToward(MotionVelocity.z, 0, Speed);
+ }
+
+ MotionVelocity = motionVelocity;
+ MoveAndSlide();
+ }
+}
diff --git a/modules/mono/editor_templates/EditorPlugin/plugin.cs b/modules/mono/editor_templates/EditorPlugin/plugin.cs
new file mode 100644
index 0000000000..6e6a799be6
--- /dev/null
+++ b/modules/mono/editor_templates/EditorPlugin/plugin.cs
@@ -0,0 +1,19 @@
+// meta-description: Basic plugin template
+#if TOOLS
+using _BINDINGS_NAMESPACE_;
+using System;
+
+[Tool]
+public partial class _CLASS_ : _BASE_
+{
+ public override void _EnterTree()
+ {
+ // Initialization of the plugin goes here.
+ }
+
+ public override void _ExitTree()
+ {
+ // Clean-up of the plugin goes here.
+ }
+}
+#endif
diff --git a/modules/mono/editor_templates/EditorScript/basic_editor_script.cs b/modules/mono/editor_templates/EditorScript/basic_editor_script.cs
new file mode 100644
index 0000000000..2088822890
--- /dev/null
+++ b/modules/mono/editor_templates/EditorScript/basic_editor_script.cs
@@ -0,0 +1,14 @@
+// meta-description: Basic editor script template
+#if TOOLS
+using _BINDINGS_NAMESPACE_;
+using System;
+
+[Tool]
+public partial class _CLASS_ : _BASE_
+{
+ public override void _Run()
+ {
+ // Called when the script is executed (using File -> Run in Script Editor).
+ }
+}
+#endif
diff --git a/modules/mono/editor_templates/Node/default.cs b/modules/mono/editor_templates/Node/default.cs
new file mode 100644
index 0000000000..73d69dd993
--- /dev/null
+++ b/modules/mono/editor_templates/Node/default.cs
@@ -0,0 +1,19 @@
+// meta-description: Base template for Node with default Godot cycle methods
+
+using _BINDINGS_NAMESPACE_;
+using System;
+
+public partial class _CLASS_ : _BASE_
+{
+ // Called when the node enters the scene tree for the first time.
+ public override void _Ready()
+ {
+
+ }
+
+ // Called every frame. 'delta' is the elapsed time since the previous frame.
+ public override void _Process(float delta)
+ {
+
+ }
+}
diff --git a/modules/mono/editor_templates/Object/empty.cs b/modules/mono/editor_templates/Object/empty.cs
new file mode 100644
index 0000000000..e5bee64fe1
--- /dev/null
+++ b/modules/mono/editor_templates/Object/empty.cs
@@ -0,0 +1,9 @@
+// meta-description: Empty template suitable for all Objects
+
+using _BINDINGS_NAMESPACE_;
+using System;
+
+public partial class _CLASS_ : _BASE_
+{
+
+}
diff --git a/modules/mono/editor_templates/SCsub b/modules/mono/editor_templates/SCsub
new file mode 100644
index 0000000000..39f6cb5c01
--- /dev/null
+++ b/modules/mono/editor_templates/SCsub
@@ -0,0 +1,16 @@
+#!/usr/bin/env python
+
+Import("env")
+
+import editor.template_builders as build_template_cs
+
+env["BUILDERS"]["MakeCSharpTemplateBuilder"] = Builder(
+ action=env.Run(build_template_cs.make_templates, "Generating C# templates header."),
+ suffix=".h",
+ src_suffix=".cs",
+)
+
+# Template files
+templates_sources = Glob("*/*.cs")
+
+env.Alias("editor_template_cs", [env.MakeCSharpTemplateBuilder("templates.gen.h", templates_sources)])