xiSage.GodotResourceUID
0.1.0
dotnet add package xiSage.GodotResourceUID --version 0.1.0
NuGet\Install-Package xiSage.GodotResourceUID -Version 0.1.0
<PackageReference Include="xiSage.GodotResourceUID" Version="0.1.0" />
<PackageVersion Include="xiSage.GodotResourceUID" Version="0.1.0" />
<PackageReference Include="xiSage.GodotResourceUID" />
paket add xiSage.GodotResourceUID --version 0.1.0
#r "nuget: xiSage.GodotResourceUID, 0.1.0"
#:package xiSage.GodotResourceUID@0.1.0
#addin nuget:?package=xiSage.GodotResourceUID&version=0.1.0
#tool nuget:?package=xiSage.GodotResourceUID&version=0.1.0
GodotResourceUID
A C# library for handling Godot's Unique ID (UID) system, providing conversion between UID text format and numeric IDs, as well as UID-to-path mapping functionality.
Features
- UID Conversion: Convert between UID text format (
uid://d4n4ub6itg400) and numeric IDs - Cache Management: Load UID mappings from binary cache files
- Path Mapping: Map between UIDs and file paths
- Godot Compatible: Implements Godot's UID character mapping and format specification
- Thread Safe: Designed for safe use in multi-threaded environments
- Unit Tested: Comprehensive test suite ensuring reliable functionality
Installation
Prerequisites
- .NET 6.0 or later
- Godot 4.x (for Godot projects)
Usage in .NET Projects
Clone the repository:
git clone https://github.com/xiSage/GodotResourceUID.gitAdd the project reference to your .NET project:
<ProjectReference Include="path/to/GodotResourceUID/GodotResourceUID/GodotResourceUID.csproj" />Add the namespace to your code:
using GodotResourceUID;
Usage in Godot Projects
- Copy the
ResourceUID.csfile to your Godot project'saddonsorscriptsdirectory - Add the namespace to your GDScript or C# files
API Reference
ResourceUID Class
Constants
INVALID_ID: Constant representing an invalid UID (-1)
Static Methods
string IdToText(long id)Converts a numeric UID to its text format.- Parameters:
id- Numeric UID to convert - Returns: Text format UID (e.g.,
uid://d4n4ub6itg400)
- Parameters:
long TextToId(string text)Converts a text format UID to its numeric representation.- Parameters:
text- Text format UID to convert - Returns: Numeric UID, or
INVALID_IDif invalid
- Parameters:
string GetPathFromCache(string cacheFilePath, string uidString)Gets a path from a cache file directly by UID text, without loading the entire cache.- Parameters:
cacheFilePath- Path to the UID cache fileuidString- Text format UID to look up
- Returns: Corresponding file path, or empty string if not found
- Parameters:
Instance Methods
bool LoadFromCache(string cacheFilePath)Loads UID mapping from a cache file.- Parameters:
cacheFilePath- Path to the UID cache file - Returns:
trueif loading was successful,falseotherwise
- Parameters:
string GetIdPath(long id)Gets the path associated with a numeric UID.- Parameters:
id- Numeric UID to look up - Returns: Corresponding file path, or empty string if not found
- Parameters:
long GetPathId(string path)Gets the numeric UID associated with a file path.- Parameters:
path- File path to look up - Returns: Corresponding numeric UID, or
INVALID_IDif not found
- Parameters:
string UidToPath(string uid)Converts a text format UID to its corresponding file path.- Parameters:
uid- Text format UID to convert - Returns: Corresponding file path, or empty string if not found
- Parameters:
string EnsurePath(string pathOrUid)Ensures a path is returned, converting to path if input is a UID.- Parameters:
pathOrUid- File path or text format UID - Returns: File path
- Parameters:
Usage Examples
Basic UID Conversion
using GodotResourceUID;
// Convert numeric ID to text format
long numericId = 0x7FFFFFFFFFFFFFFF;
string textUid = ResourceUID.IdToText(numericId);
// textUid will be "uid://d4n4ub6itg400"
// Convert text format to numeric ID
long convertedId = ResourceUID.TextToId(textUid);
// convertedId will be 0x7FFFFFFFFFFFFFFF
Working with UID Cache
using GodotResourceUID;
ResourceUID uidManager = new ResourceUID();
// Load UID mappings from cache file
if (uidManager.LoadFromCache("res://.godot/uid_cache.bin"))
{
// Get path from UID
string texturePath = uidManager.UidToPath("uid://d4n4ub6itg400");
// texturePath will be something like "res://textures/player.png"
// Get UID from path
string modelPath = "res://models/enemy.tscn";
long modelUid = uidManager.GetPathId(modelPath);
// modelUid will be the numeric UID for the model
}
Ensuring Paths
using GodotResourceUID;
ResourceUID uidManager = new ResourceUID();
uidManager.LoadFromCache("res://.godot/uid_cache.bin");
// This works with both paths and UIDs
string path1 = uidManager.EnsurePath("res://scenes/level.tscn");
// path1 remains "res://scenes/level.tscn"
string path2 = uidManager.EnsurePath("uid://dm3rdgs30kfci");
// path2 becomes the actual file path
Testing
The project includes a comprehensive test suite using xUnit. To run the tests:
- Navigate to the project directory
- Run the test command:
dotnet test
Architecture
UID Format
Godot UIDs use a base-34 encoding with the following character set:
- Lowercase letters:
a-z(26 characters) - Digits:
0-9(10 characters)
Total: 34 characters
Cache Format
The UID cache file is a binary file with the following structure:
- 4 bytes: Number of entries (uint32)
- For each entry:
- 8 bytes: Numeric UID (int64)
- 4 bytes: Path length (int32)
- Variable: UTF-8 encoded path
License
This project is licensed under the MIT License - see the LICENSE.txt file for details.
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
Acknowledgments
- Based on Godot Engine's UID implementation
- Inspired by the need for UID handling in .NET applications working with Godot projects
Contact
For issues, questions, or suggestions, please open an issue on GitHub.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. 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. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
| .NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
| .NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
| MonoAndroid | monoandroid was computed. |
| MonoMac | monomac was computed. |
| MonoTouch | monotouch was computed. |
| Tizen | tizen40 was computed. tizen60 was computed. |
| Xamarin.iOS | xamarinios was computed. |
| Xamarin.Mac | xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos was computed. |
-
.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 |
|---|---|---|
| 0.1.0 | 148 | 1/7/2026 |