Skip to content

Commit

Permalink
Add C# tool demo
Browse files Browse the repository at this point in the history
  • Loading branch information
pkdawson committed Apr 30, 2024
1 parent 20aff1d commit 52c8ee8
Show file tree
Hide file tree
Showing 9 changed files with 155 additions and 0 deletions.
7 changes: 7 additions & 0 deletions doc/examples/ToolCSharp/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Run:

```
godotenv addons install
```

Open the project, then restart the editor.
34 changes: 34 additions & 0 deletions doc/examples/ToolCSharp/SpriteTool.cs
Original file line number Diff line number Diff line change
@@ -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();
}
}
}
10 changes: 10 additions & 0 deletions doc/examples/ToolCSharp/ToolCSharp.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<Project Sdk="Godot.NET.Sdk/4.2.2">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<EnableDynamicLoading>true</EnableDynamicLoading>
<AllowUnsafeBlocks>True</AllowUnsafeBlocks>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="ImGui.NET" Version="1.90.1.1" />
</ItemGroup>
</Project>
19 changes: 19 additions & 0 deletions doc/examples/ToolCSharp/ToolCSharp.sln
Original file line number Diff line number Diff line change
@@ -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
8 changes: 8 additions & 0 deletions doc/examples/ToolCSharp/addons.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"addons": {
"imgui-godot": {
"url": "../../../../addons/imgui-godot",
"source": "symlink"
}
}
}
1 change: 1 addition & 0 deletions doc/examples/ToolCSharp/icon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
37 changes: 37 additions & 0 deletions doc/examples/ToolCSharp/icon.svg.import
Original file line number Diff line number Diff line change
@@ -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
11 changes: 11 additions & 0 deletions doc/examples/ToolCSharp/main.tscn
Original file line number Diff line number Diff line change
@@ -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")
28 changes: 28 additions & 0 deletions doc/examples/ToolCSharp/project.godot
Original file line number Diff line number Diff line change
@@ -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")

0 comments on commit 52c8ee8

Please sign in to comment.