Skip to content
This repository has been archived by the owner on Mar 9, 2023. It is now read-only.

Fractural/FracturalCSharpResourceRegistry

Repository files navigation

Arhive Notice ⚠️

This repository has been archived since resource registering functionality has been moved directly into FracturalCommons.

FracturalCSharpResourceRegistry

Deploy Unit Tests

This is a Godot C# plugin that registers custom C# resources and custom nodes for Godot. This plugin serves as a workaround for the Godot engine's C# resource missing in context menu issue.

Based off of CustomResourceRegisterPlugin made by wmigor

How to Use

Adding custom C# resources/nodes:

  1. Add the RegisteredTypeAttribute to your resource/node class. The file containing your class must have the same name as the class in order to be detected by the plugin. Make sure to add using MonoCustomResourceRegistry; to the top of your file to import this plugin's namespace, which contains RegisteredTypeAttribute.
  2. Make sure your C# file is under one of the Resource Script Directories
  3. Rebuild the solution
  4. Press the "CRR" button to update the registered types

Deleting custom C# resources/nodes:

  1. Delete the C# resource/node script
  2. Rebuild the solution
  3. Press the "CRR" button to update the registered types

Anytime the Plugin registers/unregisters a resource/node, the plugin will print its actions into the Output window.

RegisteredTypeAttribute

[RegisteredType(string name, string iconPath = "", string baseType = ""))]
  • name - Name of the custom type.
  • iconPath (Optional) - File path to the icon displayed for the custom type. Leave empty for no custom icon.
  • baseType (Optional) - Name of the base type. Leave empty for the default base type ("Node" for custom nodes and "Resource" for custom resources).

Sample usage:

// Inside a file named CustomNodeDemo.cs
using MonoCustomResourceRegistry;

// Registers a custom type with 
// 	a name of "CustomNodeDemo",
//	an icon located at "res://custom_icon.png",
//	and a base type of "Node2D"
[RegisteredType(nameof(CustomNodeDemo), "res://custom_icon.png", nameof(Node2D))]
public class CustomNodeDemo : Node2D
{
	...
}
// Inside a file named CustomNodeDemo2.cs
using MonoCustomResourceRegistry;

// Registers a custom type with 
// 	a name of "CustomNodeDemo",
//	no icon,
//	and a base type of "Button"
[RegisteredType(nameof(CustomNodeDemo), "", nameof(Button))]
public class CustomNodeDemo2 : Button
{
	...
}
// Inside a file named CustomNodeDemo3.cs
using MonoCustomResourceRegistry;

// Registers a custom type with 
// 	a name of "CustomNodeDemo",
//	no icon,
//	and a default base type of "Resource"
[RegisteredType(nameof(CustomNodeDemo))]
public class CustomNodeDemo3 : Resource
{
	...
}

Settings

This plugin comes with some settings to configure how C# resources are loaded. The settings can be accessed by going to Project > ProjectSettings > General > Mono Custom Resource Registry.

All settings are listed below:

Class Prefix - The prefix that is seen before all custom nodes and resources.

Resource Script Directories - The paths to the directories where you want to scan for C# resource scripts to register as custom resources. By default, it only contains "res://".

Search Type - The method used to gather custom C# resource scripts.

  • Namespace - Looks for scripts by using their namespace as a directory.

    For example with the C# script below, the plugin will look under each resource script directory for the script by using the path "./Some/Long/Namespace/Something.cs".

     namespace Some.Long.Namespace
     {
     	public class Something : Resource
     	{
     	}
     }
  • Recursive - Looks for scripts by searching through all "Resource Script Directories" and the directories within them.