diff options
author | fabriceci <fabricecipolla@gmail.com> | 2021-10-11 11:30:59 +0200 |
---|---|---|
committer | jmb462 <jmb462@gmail.com> | 2022-01-02 21:52:09 +0100 |
commit | 9d5b80705912d85c3c7301ac0ea0afbf9372a660 (patch) | |
tree | e9528ac06fcfc29bc43846713d1c3ddb94becc22 /modules/mono/editor_templates | |
parent | 28174d531b7128f0281fc2b88da2f4962fd3513e (diff) |
Improve editor template workflow
Co-Authored-By: jmb462 <jmb462@gmail.com>
Diffstat (limited to 'modules/mono/editor_templates')
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)]) |