From 52c8ee8a8f20b4bf7383d66caee3fe28eb80cc2f Mon Sep 17 00:00:00 2001 From: Patrick Dawson Date: Tue, 30 Apr 2024 23:40:59 +0200 Subject: [PATCH] Add C# tool demo --- doc/examples/ToolCSharp/README.md | 7 +++++ doc/examples/ToolCSharp/SpriteTool.cs | 34 +++++++++++++++++++++ doc/examples/ToolCSharp/ToolCSharp.csproj | 10 ++++++ doc/examples/ToolCSharp/ToolCSharp.sln | 19 ++++++++++++ doc/examples/ToolCSharp/addons.json | 8 +++++ doc/examples/ToolCSharp/icon.svg | 1 + doc/examples/ToolCSharp/icon.svg.import | 37 +++++++++++++++++++++++ doc/examples/ToolCSharp/main.tscn | 11 +++++++ doc/examples/ToolCSharp/project.godot | 28 +++++++++++++++++ 9 files changed, 155 insertions(+) create mode 100644 doc/examples/ToolCSharp/README.md create mode 100644 doc/examples/ToolCSharp/SpriteTool.cs create mode 100644 doc/examples/ToolCSharp/ToolCSharp.csproj create mode 100644 doc/examples/ToolCSharp/ToolCSharp.sln create mode 100644 doc/examples/ToolCSharp/addons.json create mode 100644 doc/examples/ToolCSharp/icon.svg create mode 100644 doc/examples/ToolCSharp/icon.svg.import create mode 100644 doc/examples/ToolCSharp/main.tscn create mode 100644 doc/examples/ToolCSharp/project.godot diff --git a/doc/examples/ToolCSharp/README.md b/doc/examples/ToolCSharp/README.md new file mode 100644 index 0000000..649fcbf --- /dev/null +++ b/doc/examples/ToolCSharp/README.md @@ -0,0 +1,7 @@ +Run: + +``` +godotenv addons install +``` + +Open the project, then restart the editor. diff --git a/doc/examples/ToolCSharp/SpriteTool.cs b/doc/examples/ToolCSharp/SpriteTool.cs new file mode 100644 index 0000000..eb100ec --- /dev/null +++ b/doc/examples/ToolCSharp/SpriteTool.cs @@ -0,0 +1,34 @@ +using Godot; +using ImGuiNET; +using ImGuiGodot; + +[Tool] +public partial class SpriteTool : Sprite2D +{ + private bool _showImGui = false; + + public override void _Ready() + { + if (Engine.IsEditorHint()) + { + _showImGui = ImGuiGD.ToolInit(); + var io = ImGui.GetIO(); + io.ConfigFlags |= ImGuiConfigFlags.ViewportsEnable; + io.ConfigViewportsNoAutoMerge = true; + } + } + + public override void _Process(double delta) + { + if (_showImGui) + { + ImGui.Begin($"SpriteTool: {Name}"); + float scale = Scale.X; + if (ImGui.DragFloat("scale", ref scale, 0.1f)) + { + Scale = new(scale, scale); + } + ImGui.End(); + } + } +} diff --git a/doc/examples/ToolCSharp/ToolCSharp.csproj b/doc/examples/ToolCSharp/ToolCSharp.csproj new file mode 100644 index 0000000..9c94b73 --- /dev/null +++ b/doc/examples/ToolCSharp/ToolCSharp.csproj @@ -0,0 +1,10 @@ + + + net8.0 + true + True + + + + + \ No newline at end of file diff --git a/doc/examples/ToolCSharp/ToolCSharp.sln b/doc/examples/ToolCSharp/ToolCSharp.sln new file mode 100644 index 0000000..e84ba80 --- /dev/null +++ b/doc/examples/ToolCSharp/ToolCSharp.sln @@ -0,0 +1,19 @@ +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 2012 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ToolCSharp", "ToolCSharp.csproj", "{E08468D9-B6AE-4EBA-BE2B-B18B0194FEAF}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + ExportDebug|Any CPU = ExportDebug|Any CPU + ExportRelease|Any CPU = ExportRelease|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {E08468D9-B6AE-4EBA-BE2B-B18B0194FEAF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {E08468D9-B6AE-4EBA-BE2B-B18B0194FEAF}.Debug|Any CPU.Build.0 = Debug|Any CPU + {E08468D9-B6AE-4EBA-BE2B-B18B0194FEAF}.ExportDebug|Any CPU.ActiveCfg = ExportDebug|Any CPU + {E08468D9-B6AE-4EBA-BE2B-B18B0194FEAF}.ExportDebug|Any CPU.Build.0 = ExportDebug|Any CPU + {E08468D9-B6AE-4EBA-BE2B-B18B0194FEAF}.ExportRelease|Any CPU.ActiveCfg = ExportRelease|Any CPU + {E08468D9-B6AE-4EBA-BE2B-B18B0194FEAF}.ExportRelease|Any CPU.Build.0 = ExportRelease|Any CPU + EndGlobalSection +EndGlobal diff --git a/doc/examples/ToolCSharp/addons.json b/doc/examples/ToolCSharp/addons.json new file mode 100644 index 0000000..f74fb9e --- /dev/null +++ b/doc/examples/ToolCSharp/addons.json @@ -0,0 +1,8 @@ +{ + "addons": { + "imgui-godot": { + "url": "../../../../addons/imgui-godot", + "source": "symlink" + } + } +} diff --git a/doc/examples/ToolCSharp/icon.svg b/doc/examples/ToolCSharp/icon.svg new file mode 100644 index 0000000..3fe4f4a --- /dev/null +++ b/doc/examples/ToolCSharp/icon.svg @@ -0,0 +1 @@ + diff --git a/doc/examples/ToolCSharp/icon.svg.import b/doc/examples/ToolCSharp/icon.svg.import new file mode 100644 index 0000000..0de2634 --- /dev/null +++ b/doc/examples/ToolCSharp/icon.svg.import @@ -0,0 +1,37 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://g0surar1un43" +path="res://.godot/imported/icon.svg-218a8f2b3041327d8a5756f3a245f83b.ctex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://icon.svg" +dest_files=["res://.godot/imported/icon.svg-218a8f2b3041327d8a5756f3a245f83b.ctex"] + +[params] + +compress/mode=0 +compress/high_quality=false +compress/lossy_quality=0.7 +compress/hdr_compression=1 +compress/normal_map=0 +compress/channel_pack=0 +mipmaps/generate=false +mipmaps/limit=-1 +roughness/mode=0 +roughness/src_normal="" +process/fix_alpha_border=true +process/premult_alpha=false +process/normal_map_invert_y=false +process/hdr_as_srgb=false +process/hdr_clamp_exposure=false +process/size_limit=0 +detect_3d/compress_to=1 +svg/scale=1.0 +editor/scale_with_editor_scale=false +editor/convert_colors_with_editor_theme=false diff --git a/doc/examples/ToolCSharp/main.tscn b/doc/examples/ToolCSharp/main.tscn new file mode 100644 index 0000000..5c5adeb --- /dev/null +++ b/doc/examples/ToolCSharp/main.tscn @@ -0,0 +1,11 @@ +[gd_scene load_steps=3 format=3 uid="uid://ceybxiw6agvb2"] + +[ext_resource type="Texture2D" uid="uid://g0surar1un43" path="res://icon.svg" id="1_vsk0a"] +[ext_resource type="Script" path="res://SpriteTool.cs" id="2_a7b6t"] + +[node name="Node2D" type="Node2D"] + +[node name="Icon" type="Sprite2D" parent="."] +position = Vector2(470, 223) +texture = ExtResource("1_vsk0a") +script = ExtResource("2_a7b6t") diff --git a/doc/examples/ToolCSharp/project.godot b/doc/examples/ToolCSharp/project.godot new file mode 100644 index 0000000..2f7894c --- /dev/null +++ b/doc/examples/ToolCSharp/project.godot @@ -0,0 +1,28 @@ +; Engine configuration file. +; It's best edited using the editor UI and not directly, +; since the parameters that go here are not all obvious. +; +; Format: +; [section] ; section goes between [] +; param=value ; assign values to parameters + +config_version=5 + +[application] + +config/name="ToolCSharp" +run/main_scene="res://main.tscn" +config/features=PackedStringArray("4.2", "C#", "Forward Plus") +config/icon="res://icon.svg" + +[autoload] + +ImGuiRoot="*res://addons/imgui-godot/data/ImGuiRoot.tscn" + +[dotnet] + +project/assembly_name="ToolCSharp" + +[editor_plugins] + +enabled=PackedStringArray("res://addons/imgui-godot/plugin.cfg")