Metal666.GodotUtilities
0.2.3
Prefix Reserved
See the version list below for details.
dotnet add package Metal666.GodotUtilities --version 0.2.3
NuGet\Install-Package Metal666.GodotUtilities -Version 0.2.3
<PackageReference Include="Metal666.GodotUtilities" Version="0.2.3" />
paket add Metal666.GodotUtilities --version 0.2.3
#r "nuget: Metal666.GodotUtilities, 0.2.3"
// Install Metal666.GodotUtilities as a Cake Addin #addin nuget:?package=Metal666.GodotUtilities&version=0.2.3 // Install Metal666.GodotUtilities as a Cake Tool #tool nuget:?package=Metal666.GodotUtilities&version=0.2.3
GodotUtilities
A set of utilities I use in my Godot projects.
Features
Architecture
Singletons - turn custom Nodes into Singletons by adding the
Singleton
attribute.The included source generator will add the
Instance
property + a parameterless constructor, where it is set.State (experimental) - use the
State
attribute to mark static classes as states.The following things will be generated for each private field in the state:
A public property
Use it to modify the field.
An
On<Property>Changed
eventInvoked when a property is set.
An interface with a single
On<Property>Changed
method.Implement it on any node and the method will be automatically called when the property is changed.
Logging
A modular logging system is available. In order to log a message, call the
Log
method on the staticLogManager
class. By default, the message will be processed by 2 loggers:EditorLogger
(activated when running the game from the editor)Prints the message to the Godot console using one of the
GD.PrintRich
/GD.PushWarning
/GD.PushError
(based on the message log level).ConsoleLogger
(activated when running the game standalone)Prints the message using
Console.WriteLine
.
When logging, parameters such as
logLevel
,sourceType
andindentation
can be specified to format the output.Loggers extend a base
LoggerBase
class. If you need to implement a custom logging solution you can extend either of the stock loggers, or the base class. Then you can override the available methods and properties to change how the message is processed and output. Finally, set theLoggers
value on theLogManager
class (overriding the default loggers).Two additional logging features are available:
Extension methods
A vast selection of extension methods are available for convenient logging. For example, if you call the
LogMessage
extension method, the object'sType
will be automatically passed as thesourceType
parameter and the log level will be set toLogLevel.Message
. All extension methods are contained inside the staticLogging
class inside theMetal666.GodotUtilities.Extensions
namespace.LogSource
attributeAttach it to a custom node class, and specify the
Color
property (use HTML color names, such asred
). When a log arrives with that node's type as thesourceType
, the output will be colored using the specified color. TheEditorLogger
will use the[color]
BBCode
, while theConsoleLogger
will convert the color to the closestConsoleColor
enum value and set theConsole.ForegroundColor
.
Networking
LocalInstanceController
This class can be used as an alternative to the "Launch multiple instances" editor function. Use the
Initialize
method to spawn additional game instances. At the moment it is rather basic and doesn't offer much benefit over the editor functionality. I will be extending it with more features in the future.
Extension methods
- Controls
Range.ValueF()
- retrieve the value of aRange
node as afloat
.Range.ValueF()
- retrieve the value of aRange
node as a roundedint
.
- LINQ
IEnumerable.If(bool condition, Func<IEnumerable<TSource>, IEnumerable<TSource>> branch)
- branches inside LINQ chains.
- Math
Vector2.IsEqualApprox(Vector2 b, float tolerance)
- compare vectors with tolerance.Vector3.IsEqualApprox(Vector3 b, float tolerance)
- compare vectors with tolerance.Vector2.CopyWith(float? x = null, float? y = null)
- copy vector with components modified.Vector2I.CopyWith(int? x = null, int? y = null)
- copy vector with components modified.Vector3.CopyWith(float? x = null, float? y = null, float? z = null)
- copy vector with components modified.Vector3I.CopyWith(int? x = null, int? y = null, int? z = null)
- copy vector with components modified.Vector3.RotatedDeg(Vector3 axis, float angle)
-Vector3.Rotated
, but in degrees.int.ToDeg()
,float.ToDeg()
,double.ToDeg()
- shortcuts toMathf.RadToDeg
.int.ToRad()
,float.ToRad()
,double.ToRad()
- shortcuts toMathf.DegToRad
.Vector2.ToDeg()
,Vector3.ToDeg()
,Vector2.ToRad()
,Vector3.ToRad()
- performsfloat.ToDeg()
/float.ToRad()
on all vector components.float.RoundToInt()
,float.FloorToInt()
,float.CeilToInt()
- shortcuts toMathf.RoundToInt
,Mathf.FloorToInt
andMathf.CeilToInt
.double.RoundToInt()
,double.FloorToInt()
,double.CeilToInt()
- shortcuts toMathf.RoundToInt
,Mathf.FloorToInt
andMathf.CeilToInt
.Vector2.RoundToInt()
,Vector2.FloorToInt()
,Vector2.CeilToInt()
- performsfloat.RoundToInt()
/float.FloorToInt()
/float.CeilToInt()
on all vector components.Vector3.RoundToInt()
,Vector3.FloorToInt()
,Vector3.CeilToInt()
- performsfloat.RoundToInt()
/float.FloorToInt()
/float.CeilToInt()
on all vector components.
- Physics
Node3D.RayCast(PhysicsRayQueryParameters3D parameters)
- performsPhysicsDirectSpaceState3D.IntersectRay
. Returns a strongly typedRaycastResult3D
object.Node2D.RayCast(PhysicsRayQueryParameters2D parameters)
- performsPhysicsDirectSpaceState2D.IntersectRay
. Returns a strongly typedRaycastResult2D
object.
- Threading
Action.InvokeOnMainThread()
(+ 16 overloads) - a shortcut toCallable.From(action).CallDeferred()
.
- Transforms
Node2D.RotateDeg(int angle)
,Node2D.RotateDeg(float angle)
,Node2D.RotateDeg(double angle)
-Node2D.Rotate
, but in degrees.Node3D.RotateDeg(Vector3 axis, int angle)
,Node3D.RotateDeg(Vector3 axis, float angle)
,Node3D.RotateDeg(Vector3 axis, double angle)
-Node3D.Rotate
, but in degrees.Node3D.RotateXDeg(int angle)
,Node3D.RotateXDeg(float angle)
,Node3D.RotateXDeg(double angle)
-Node2D.RotateX
, but in degrees.Node3D.RotateYDeg(int angle)
,Node3D.RotateYDeg(float angle)
,Node3D.RotateYDeg(double angle)
-Node2D.RotateY
, but in degrees.Node3D.RotateZDeg(int angle)
,Node3D.RotateZDeg(float angle)
,Node3D.RotateZDeg(double angle)
-Node2D.RotateX
, but in degrees.
- Tree
Node.Unparent()
- self-explanatory.
- Visual
Color.ToVector3()
- creates a vector from theR
,G
andB
values.Color.ToVector3I()
- creates a vector from theR8
,G8
andB8
values.
- Controls
Additional utilities
- Access
Is.Editor
orIs.Standalone
to determine if the game was launched from the editor or not.
- Access
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. |
-
net8.0
- GodotSharp (>= 4.3.0)
- Metal666.GodotUtilities.SourceGenerators (>= 0.0.7)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.