Usage

A C# wrapped version of G.U.I.D.E, a simple but powerful way to handle input in the Godot Engine.

Usage

G.U.I.D.E-CSharp is designed to follow all the normal behavior of G.U.I.D.E, so most of what you do with the wrapper is exactly the same other than using CamelCase instead of snake_case.

// GDScript
    GUIDE.enable_mapping_context();

// C#
    Guide.EnableMappingContext();

C# Editor resources are handled with a duplicate resource type, denoted by the blood orange color variation and a C# icon.

image image

Anything done directly in the editor, use GUIDE resources as normal.

Anything done in C#, use a GuideCs resource.

Workflow Tutorial

  1. Create a GUIDEAction or GUIDEMappingContext. image image
  2. The matching C# wrapper is created automatically. image
  3. The C# wrapper automatically takes the matchingGUIDEAction or GUIDEMappingContext as an export parameter. image
  4. In your C# script, create your [Export] variables as GuideCs types.
       using Godot;
       using GuideCs;
    
       public partial class Main : Node
       {
         [Export] public GuideMappingContext WalkMode;
    
         [Export] public GuideAction move;
    
            
       }
    
  5. Assign them in the editor with your GuideCs wrappers: image
  6. Use them in C# as you would in GDScript, keeping in mind the differences with C#. See the C# documentation.
       using Godot;
       using GuideCs;
    
       public partial class Main : Node
       {
         [Export] public GuideMappingContext WalkMode;
    
         [Export] public GuideAction move;
            
         public override void _Ready()
         {
           Guide.EnableMappingContext(WalkMode);
         }
            
       }
    

Code Only Examples

No Exports

If you don’t use [Export] properties and would prefer to load and manage your C# resources through code, you can also do so by using the Utility.CreateWrapper() function to generate wrapped resources:

    public Dictionary<string, GuideAction> WrappedActions;
    public override void _Ready()
    {
        Dictionary<string, string> guideActions = new ()
        {
            {"Jump", "uid://cm76dijjo3wm4"},
            {"Shoot", "uid://cki32mfnd6v7k"},
            {"walk", "uid://c0quxwokh6bm4"},
        };

        foreach (var kvp in guideActions)
        {
            var guideBaseObject = (GodotObject)ResourceLoader.Load<GDScript>(kvp.Value).New();
            var wrappedAction = Utility.CreateWrapper<GuideAction>(guideBaseObject);
            WrappedActions.TryAdd(kvp.Key, wrappedAction);
        }
        
        base._Ready();
    }

Direct Creation

These examples are NOT the only way, there are much better ways, keeping the code examples more readable was priority here.

You can also directly create the wrapper depending on how you prefer to manage your resources.

    GuideResource.ConnectBaseGuideResource()

    // or
    
    GuideResource.LoadAndConnectBaseGuideResource() 

If you loaded your own object(s), use connect.

public partial class Main : Node2D
{
  public List<GodotObject> BaseGuideMappingContextsLoaded = [];

  public override void _Ready()
  {
    var wrappedMappingContext = new GuideMappingContext();
    wrappedMappingContext.ConnectBaseGuideResource(BaseGuideMappingContextsLoaded[0]);
  }
}

If you want GuideCs to load the object(s) for you, use load and connect.

public partial class Main : Node2D
{
  public List<string> BaseGuideMappingContextPaths = [];

  public override void _Ready()
  {
    var wrappedMappingContext = new GuideMappingContext();
    wrappedMappingContext.LoadAndConnectBaseGuideResource(BaseGuideMappingContextPaths[0]);
  }
}

You can also create a new object and pass the loaded GUIDE resource as a constructor parameter.

public partial class Main : Node2D
{
  public override void _Ready()
  {
    var loadedGuideObject = (GodotObject)ResourceLoader.Load<GDScript>("uid or path").New();
    wrappedMappingContext = new GuideMappingContext(loadedGuideObject);
  }
}

Note: GuideCs cannot verify the GUIDE object type: