Skip to content

Godot addon to make it a bit easier to add custom inspector controls to nodes

License

Notifications You must be signed in to change notification settings

ProFiLeR4100/ExtendableInspectorForCS

 
 

Repository files navigation

Extendable Inspector

Makes it easier to add custom inspector controls to nodes.

Screenshot showing the example code in res://addons/extendable_inspector_for_cs/example/ChangeRandomColor/ChangeRandomColor.cs 3d scene of a cube with a button in the inspector that says 'Change To Random Color' 3d scene of a cube with a button in the inspector that says 'Change To Random Color' but now the cube is of a different color

How to install

Download the project and copy the addon folder into your godot project.

Go to Project Settings > Plugins, and enable Extendable Inspector (C#).

Quick Start / Tutorial

Let's add a button that prints the node name in godot's output:

image

  • Define a method called ExtendInspectorBegin that receives a parameter, let's call that parameter inspector. Don't forget to wrap code with preprocessor #if directive, because ExtendableInspector is only accessible in editor. If you want, you can type it as ExtendableInspector to get some autocomplete features:

image

  • Create a button that when pressed, it prints the node's name. Then, simply add it to the inspector with inspector.AddCustomControl(ourNewControl). You will have to unfocus the node and focus it again for the button to appear:

image

Here's the entire code in case you want to try it out:

using Godot;

[Tool]
public partial class SayYourName : Node2D {
    #if TOOLS
    public void ExtendInspectorBegin(ExtendableInspector inspector) {
        Button button = new() {
            Text = "Say your name"
        };
        button.Pressed += () => GD.Print(Name);
        inspector.AddCustomControl(button);
    }
    #endif
}

How to use

What this plugin does is allow extending the inspector by declaring some methods in the script for which you want to add custom extensions to the inspector.

The supported methods are analogous to methods that can be defined in an EditorInspectorPlugin to add new features to the inspector. https://docs.godotengine.org/en/latest/classes/class_editorinspectorplugin.html#class-editorinspectorplugin-method-add-property-editor-for-multiple-properties

These methods are:

void ExtendInspectorBegin(ExtendableInspector inspector)

Allows adding controls at the beginning of the inspector.

void ExtendInspectorEnd(ExtendableInspector inspector)

Allows adding controls at the end of the inspector.

void ExtendInspectorGroup(inspector: ExtendableInspector, string group)

Allows adding controls at the beginning of a group in the property list for object.

void ExtendInspectorCategory(inspector: ExtendableInspector, string category)

Allows adding controls at the beginning of a category in the property list for object.

bool ExtendInspectorProperty(ExtendableInspector inspector, Variant.Type type, string name, PropertyHint hintType, string hintString, PropertyUsageFlags usageFlags, bool wide)

Allows adding property-specific editors to the property list for object. The added editor control must extend EditorProperty. Returning true removes the built-in editor for this property, otherwise allows to insert a custom editor before the built-in one.

Examples

Examples can be found in the example folder

About

Godot addon to make it a bit easier to add custom inspector controls to nodes

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • C# 100.0%