- Notifications
You must be signed in to change notification settings - Fork2
A collection of tools for accelerating Godot + C# game development, including resource loading, feature tags, and high-DPI utilities.
License
chickensoft-games/GameTools
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
A collection of tools for accelerating Godot + C# game development.
# Install this templatedotnet add package Chickensoft.GameTools --prereleaseGodot provides a wonderful mechanism calledResourceLoader that can load engine resources in the background, but leveraging it correctly to load more than one thing at once issurprisingly complicated.
You can leverage theLoader class provided by GameTools to simplify loading:
usingGodot;usingChickensoft.GameTools;publicpartialclassMyNode:Node{publicLoaderLoader{get;set;}=default!;publicMeshMyMesh{get;set;}=default!;publicPackedSceneMyScene{get;set;}=default!;publicoverridevoid_Ready(){Loader=new();// Add a job for everything you want to load. The callback will be// invoked with your loaded resource, allowing you to hang onto it.Loader.AddJob<Mesh>("res://my_mesh.tscn",(resource)=>MyMesh=resource);Loader.AddJob<PackedScene>("res://my_scene.tscn",(resource)=>MyScene=resource);// Subscribe to events to track progress and completion.Loader.Progress+=OnLoaderProgress;// There are other loading events you can subscribe to, if needed:// Loader.Started += () => GD.Print("Loader started!");// Loader.Completed += () => GD.Print("Loader completed!");// Start loading everything.Loader.Load();}publicoverridevoid_Process(doubledelta){// Call Update every frame to track progress and ensure events are invoked.if(!Loader.IsCompleted){Loader.Update();}}publicoverridevoid_ExitTree(){Loader.Progress-=OnLoaderProgress;}publicvoidOnLoaderProgress(floatprogress){GD.Print($"Total loading percent:{progress}");}}
Tip
To facilitate simple UI construction, the loader guarantees that you will receive progress updates for 0.0 and 1.0. The progress amount is the progress of all jobs as a percentage between 0 and 1.
Godot providesFeature Tags which allow you to examine the runtime environment of the application. The game tools provides a way to easily access these tags through a strongly-typed interface for C#. It also enables the feature tags to be overridden for testing purposes.
if(Features.OperatingSystemisOSFamily.macOS orOSFamily.Linux){GD.Print("Unix-based system");}// Whenever you need to test a specific environment, you can override the// feature tags to simulate that environment.Features.FakeOperatingSystem(OSFamily.Linux);// Reset overridden features back to the system's actual environment.Features.Reset();
| Feature | C# Enum Type | Code |
|---|---|---|
| Operating System | OSFamily | Features.OperatingSystem |
| Platform | Platform | Features.Platform |
| Interactivity Mode | InteractivityMode | Features.InteractivityMode |
| Build Type | BuildType | Features.BuildType |
| Tool Environment | ToolEnvironment | Features.ToolEnvironment |
| Precision | Precision | Features.Precision |
| Bit Length | BitLength | Features.BitLength |
| Architecture | Architecture | Features.Architecture |
| Texture Compression | TextureCompression | Features.TextureCompression |
For all possible values, check each enum type.
GameTools can help you manage display scaling on desktop platforms by automatically guessing or computing the correct scale factor for the game window's screen. On macOS and Windows, it can determine the exact user-defined scale factor by leveragingChickensoft.Platform to invoke the relevant system API's natively.
Check out thedemo project which lets you select between both scaling behaviors and toggle fullscreen mode.
Two high-level scaling behaviors are provided by GameTools. Both work well when windowed or full-screen and automatically correct for the scale factor of the screen that the window is on.
Scales the UI (and your game) down as the window shrinks. Everything remains the same size relative to each other, enabling you to create games for a specific resolution or highly custom visual style.
varinfo=GetWindow().LookGood(WindowScaleBehavior.UIProportional,BaseResolution,isFullscreen:false// or true);
Leaves the UI at a fixed size. You can easily configure your game to clip behind it or scale to fit the window using aSubViewport. For the demo, we've opted to configure the game to scale to fit the window while the UI remains unchanged.
varinfo=GetWindow().LookGood(WindowScaleBehavior.UIFixed,BaseResolution,isFullscreen:true// or false);
Tip
For more on display scaling, check out Chickensoft's blog article titledDisplay Scaling in Godot 4.
You can use the information provided by GameTools in your own scaling computations.
usingChickensoft.GameTools;publicoverridevoid_Ready(){varwindow=GetWindow();varwindow=GetWindow();varscaleInfo=window.GetWindowScaleInfo(Display.UHD4k);varsizeInfo=Display.GetWindowSizeInfo(scaleInfo.LogicalResolution);window.ContentScaleFactor=scaleInfo.ContentScaleFactor;// There are many other properties on scaleInfo, such as// SystemScale, LogicalResolution, NativeResolution, DisplayScale, etc.// sizeInfo has a recommended size for the window and a recommended min and// max size for the window. In case you can't be bothered to do all that.}
🐣 Package generated from a 🐤 Chickensoft Template —https://chickensoft.games
About
A collection of tools for accelerating Godot + C# game development, including resource loading, feature tags, and high-DPI utilities.
Resources
License
Contributing
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Packages0
Uh oh!
There was an error while loading.Please reload this page.

