GodotResourceGenerator 0.2.2
dotnet add package GodotResourceGenerator --version 0.2.2
NuGet\Install-Package GodotResourceGenerator -Version 0.2.2
<PackageReference Include="GodotResourceGenerator" Version="0.2.2" />
<PackageVersion Include="GodotResourceGenerator" Version="0.2.2" />
<PackageReference Include="GodotResourceGenerator" />
paket add GodotResourceGenerator --version 0.2.2
#r "nuget: GodotResourceGenerator, 0.2.2"
#:package GodotResourceGenerator@0.2.2
#addin nuget:?package=GodotResourceGenerator&version=0.2.2
#tool nuget:?package=GodotResourceGenerator&version=0.2.2
Godot Resource Generator
Godot Resource Generator is a .NET source generator that creates Godot Resource classes from existing C# model types.
It is designed for projects that keep regular domain models separate from Godot editor-facing resources, while still wanting strongly typed exported properties and simple model-to-resource mapping.
Prerequisites
- .NET SDK 8.0 or later for consuming projects.
- A Godot C# project that references Godot 4 C# assemblies.
Installation
Install the package:
dotnet add package GodotResourceGenerator --version 0.1.0
Mark it as a build-only dependency in your .csproj file:
<PackageReference Include="GodotResourceGenerator"
Version="0.1.0"
PrivateAssets="all"
ExcludeAssets="runtime" />
Basic Usage
Create a regular model type:
public sealed class User
{
public string Name { get; set; } = "";
public int Level { get; set; }
public Godot.Vector3 SpawnPosition { get; set; }
}
Add a partial resource class and point it at the model:
using GodotResourceGenerator;
[GodotResource(typeof(User))]
internal partial class UserResource;
The generator emits a Godot resource:
[global::Godot.GlobalClass]
internal partial class UserResource : global::Godot.Resource
{
[global::Godot.Export]
public string Name { get; set; }
[global::Godot.Export]
public int Level { get; set; }
[global::Godot.Export]
public global::Godot.Vector3 SpawnPosition { get; set; }
public static UserResource FromModel(User model) { ... }
public void CopyFrom(User model) { ... }
}
Custom Resource Bases
Generated resources derive from Godot.Resource by default. To use your own base resource type, either pass it as the second attribute argument:
public abstract class GameResource : Godot.Resource
{
}
[GodotResource(typeof(User), typeof(GameResource))]
internal partial class UserResource;
Or declare the base on the partial resource class:
[GodotResource(typeof(User))]
internal partial class UserResource : GameResource;
The custom base type must derive from Godot.Resource. If both forms are used, they must name the same base type.
Supported Types
The generator supports public readable instance properties whose types can be exported by Godot:
- C# primitive Variant-compatible types and
string. - Enums.
- Nullable value types when the underlying type is supported, such as
int?orMyEnum?. - Godot built-in structs such as
Vector2,Vector3, andColor. - Types deriving from
Godot.GodotObject. Godot.Collections.Array,Array<T>,Dictionary, andDictionary<TKey, TValue>when generic arguments are supported.- C# arrays.
- CLR sequences such as
List<T>andIReadOnlyList<T>, emitted asGodot.Collections.Array<T>. - Nested model classes or structs annotated with
[GodotResource], emitted as their generated resource type. - Derived model properties can use the nearest mapped base model resource.
Unsupported property types produce diagnostics and suppress generation for the affected resource.
Mapping Helpers
Generated resources include:
static FromModel(TModel model)to create a new resource.CopyFrom(TModel model)to update an existing resource.
Nested annotated models are mapped recursively. CLR sequences are copied into new Godot arrays.
License
Licensed under the MIT License.
Learn more about Target Frameworks and .NET Standard.
-
.NETStandard 2.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|