Skip to main content

Codely Bridge Customization

Overview

Codely Bridge lets you register static methods as custom tools. By marking methods with a dedicated attribute, you can enable AI assistants to call custom logic and quickly extend Unity Editor functionality.

The core marking component is the CustomToolAttribute attribute. This attribute applies only to methods and cannot be applied more than once. It defines the tool name and description, identifying custom methods that can be called by Tuanjie AI.

Quick Start

Create a Custom Tool Class

Create a static class in your Unity project and define static methods:

using Codely.Newtonsoft.Json.Linq;
using UnityTcp.Editor.Tools;

public static class MyCustomTools
{
[ExecuteCustomTool.CustomTool("create_folder", "Create a folder at the specified path")]
public static object CreateFolder(JObject parameters)
{
string path = parameters["path"]?.ToString();
string folderName = parameters["folderName"]?.ToString();

if (string.IsNullOrEmpty(path) || string.IsNullOrEmpty(folderName))
{
return new { success = false, error = "Missing required parameters" };
}

// Execute the logic to create the folder
// ...

return new { success = true, message = $"Folder {folderName} created successfully" };
}
}

Method Signature Requirements

Custom tool methods must follow a fixed signature format so that Tuanjie AI can recognize and call them:

public static object MethodName(JObject parameters)

Note: The original document contains Lark Base table content that cannot be directly embedded during MDX conversion. Table content needs to be manually obtained from the original document.

Attribute Parameters

By specifying the attribute parameters, you set the tool's unique name and description, binding the method to the custom tool.

[ExecuteCustomTool.CustomTool(name, description)]

Note: The original document contains Lark Base table content that cannot be directly embedded during MDX conversion. Table content needs to be manually obtained from the original document.

Complete Example

This example demonstrates how to retrieve project information through a custom tool.

Write the Tool Script

using System.Collections.Generic;
using Codely.Newtonsoft.Json.Linq;
using UnityTcp.Editor.Tools;
using UnityEditor;

public static class ProjectTools
{
[ExecuteCustomTool.CustomTool("get_project_info", "Get basic project information, including project name, version, scene list, etc.")]
public static object GetProjectInfo(JObject parameters)
{
var scenes = new List<string>();
foreach (var scene in EditorBuildSettings.scenes)
{
if (scene.enabled)
{
scenes.Add(scene.path);
}
}

return new
{
success = true,
projectName = PlayerSettings.productName,
version = PlayerSettings.bundleVersion,
scenes,
targetPlatform = EditorUserBuildSettings.activeBuildTarget.ToString()
};
}
}

Configure SKILL Documentation

The purpose of adding SKILL documentation is to tell the AI model about the new tool's capabilities — clearly defining the tool's use cases, calling conventions, parameter rules, and return values so the model knows when and how to call the custom tool. The document should define the tool name, description, usage scenarios, calling format, return fields, and usage examples. After making changes, start a new conversation session for the changes to take effect.

---
name: getprojectinfo
description: Retrieve basic information about the current Unity project, including project name, version, enabled scenes in build settings, and target platform.
---

# getProjectInfo

<!-- IMPORTANT: After creating or modifying this file, start a NEW chat session
for changes to take effect. Skills are loaded when a new session starts. -->

## When to Use

- When the user asks about project information
- When you need to know the project name or version
- When checking which scenes are included in the build
- When determining the current build target platform

## Instructions

Use the `get_project_info` custom tool to retrieve project information.

**Tool Name:** `get_project_info`

**Parameters:** None required

Invoke the tool with an empty parameters object:

```json
{
"tool_name": "get_project_info",
"parameters": {}
}

Response Fields:

FieldTypeDescription
successboolWhether the operation succeeded
projectNamestringThe product name from PlayerSettings
versionstringThe bundle version from PlayerSettings
scenesstring[]List of enabled scene paths in build settings
targetPlatformstringCurrent active build target (e.g., "StandaloneWindows", "Android")

Examples

Example 1: Get project overview

User: "What's the current project info?"

Invoke:

{
"tool_name": "get_project_info",
"parameters": {}
}

Response:

{
"success": true,
"projectName": "My Game",
"version": "1.0.0",
"scenes": [
"Assets/Scenes/MainMenu.unity",
"Assets/Scenes/Game.unity"
],
"targetPlatform": "StandaloneWindows"
}

Example 2: Check build configuration

User: "Which scenes are included in the build?"

Invoke the tool and report the scenes array from the response.


### Run Tests

After writing the script and configuring the SKILL, you can trigger tool calls to test the functionality.

![Run test screenshot](./images/IH7IbWp8doLOPXxJJVfcIbPlnmV.png)

## API Reference

### CustomToolAttribute

```typescript
[AttributeUsage(AttributeTargets.Method, AllowMultiple = false)]
public class CustomToolAttribute : Attribute
{
public string Name { get; } // Tool name
public string Description { get; } // Tool description

public CustomToolAttribute(string name, string description = null);
}

ExecuteCustomTool

public static class ExecuteCustomTool
{
// Execute tool
public static object HandleCommand(JObject @params);

// Manually register tool
public static void RegisterTool(string name, MethodInfo method);

// Get all registered tool names
public static IEnumerable<string> GetRegisteredTools();
}

Notes

  1. Table Processing: Lark Base tables in the original document cannot be directly embedded in MDX. Table content must be manually obtained from the source document
  2. Image Paths: All images are stored in the ./images/ directory
  3. Code Highlighting: Supports syntax highlighting for multiple programming languages, including C#, TypeScript, Java, and SQL
  4. Table Markers: Table markers (<sheet token="..."/>) in the original document have been replaced with comment descriptions in the MDX output