AgentSkillsCN

unity

通过TCP套接字连接使用Unity Bridge Lite控制Unity编辑器。创建/修改GameObject、管理包、控制动画等。适用于用户要求与Unity编辑器交互时使用。需要安装Unity Bridge Lite包(Unity加载时自动启动)。

SKILL.md
--- frontmatter
name: unity
description: >
  Control Unity Editor via TCP socket connection using Unity Bridge Lite.
  Create/modify GameObjects, manage packages, control animations, and more.
  Use when user asks to interact with Unity Editor. Requires Unity Bridge Lite
  package installed (auto-starts when Unity loads).

Unity Bridge Lite Control

Fast TCP socket communication with Unity Editor - minimal latency, no HTTP overhead.

Prerequisites

  • Unity Editor running with Unity Bridge Lite package installed
  • Bridge auto-starts on port 6400 when Unity loads

Install via Package Manager:

code
https://github.com/rafaqat/unitybridgelite.git?path=UnityPackage

Quick Commands

bash
# Ping Unity
python3 <skill-path>/scripts/unity_client.py ping

# Get scene hierarchy
python3 <skill-path>/scripts/unity_client.py hierarchy --pretty

# Create a cube
python3 <skill-path>/scripts/unity_client.py menu path="GameObject/3D Object/Cube"

# Change object color
python3 <skill-path>/scripts/unity_client.py color name=Cube color=FF0000

Available Commands

Basic Commands

CommandDescription
pingHealth check
list_commandsList all commands
hierarchyGet scene hierarchy
sceneGet scene info
selectionGet selected objects

GameObject Commands

Create via menu:

bash
python3 <skill-path>/scripts/unity_client.py menu path="GameObject/3D Object/Cube"
python3 <skill-path>/scripts/unity_client.py menu path="GameObject/3D Object/Sphere"
python3 <skill-path>/scripts/unity_client.py menu path="GameObject/Light/Point Light"

Create empty GameObject:

bash
python3 <skill-path>/scripts/unity_client.py create name=MyObject
python3 <skill-path>/scripts/unity_client.py create name=Child parent=MyObject

Select object:

bash
python3 <skill-path>/scripts/unity_client.py select name=Cube

Set material color (hex):

bash
python3 <skill-path>/scripts/unity_client.py color name=Cube color=FF0000
python3 <skill-path>/scripts/unity_client.py color name=Sphere color=00FF00

Animation Commands

Start rotation (degrees/second):

bash
# Rotate on Y axis at 45 deg/sec
python3 <skill-path>/scripts/unity_client.py rotate name=Cube y=45

# Rotate on multiple axes
python3 <skill-path>/scripts/unity_client.py rotate name=Cube x=10 y=45 z=5

Stop rotation:

bash
python3 <skill-path>/scripts/unity_client.py stop_rotation name=Cube
python3 <skill-path>/scripts/unity_client.py stop_rotation all=true

Start orbit (circle around point):

bash
# Orbit around origin, radius 3, speed 60 deg/sec
python3 <skill-path>/scripts/unity_client.py orbit name=Cube radius=3 speed=60

# Orbit around custom center
python3 <skill-path>/scripts/unity_client.py orbit name=Cube radius=5 speed=30 center_x=0 center_y=1 center_z=0

Stop orbit:

bash
python3 <skill-path>/scripts/unity_client.py stop_orbit name=Cube
python3 <skill-path>/scripts/unity_client.py stop_orbit all=true

Package Management

Install package:

bash
# By package name
python3 <skill-path>/scripts/unity_client.py install package=com.unity.xr.arkit

# From git URL
python3 <skill-path>/scripts/unity_client.py install package="https://github.com/user/repo.git"

List installed packages:

bash
python3 <skill-path>/scripts/unity_client.py packages --pretty

Settings & Editor Control

Open Project Settings:

bash
# Open XR settings
python3 <skill-path>/scripts/unity_client.py settings path="Project/XR Plug-in Management"

# Open Player settings
python3 <skill-path>/scripts/unity_client.py settings path="Project/Player"

# Open Quality settings
python3 <skill-path>/scripts/unity_client.py settings path="Project/Quality"

Play mode:

bash
python3 <skill-path>/scripts/unity_client.py play play=true   # Enter play mode
python3 <skill-path>/scripts/unity_client.py play play=false  # Exit play mode

Player Settings (iOS/Android)

Get current player settings:

bash
python3 <skill-path>/scripts/unity_client.py player platform=ios --pretty
python3 <skill-path>/scripts/unity_client.py player platform=android --pretty

Set iOS player settings:

bash
# Set bundle ID and company
python3 <skill-path>/scripts/unity_client.py set_player platform=ios bundleIdentifier=com.company.app companyName=MyCompany

# Configure for ARKit
python3 <skill-path>/scripts/unity_client.py set_player platform=ios \
  requiresARKitSupport=true \
  cameraUsageDescription="AR features require camera access"

# Enable automatic signing
python3 <skill-path>/scripts/unity_client.py set_player platform=ios \
  appleEnableAutomaticSigning=true \
  appleDeveloperTeamID=XXXXXXXXXX

# Set target iOS version
python3 <skill-path>/scripts/unity_client.py set_player platform=ios targetOSVersion=13.0

Set Android player settings:

bash
python3 <skill-path>/scripts/unity_client.py set_player platform=android \
  bundleIdentifier=com.company.app \
  minSdkVersion=AndroidApiLevel26

Build Target / Platform Switching

Get current build target:

bash
python3 <skill-path>/scripts/unity_client.py build_target --pretty

Switch build platform:

bash
python3 <skill-path>/scripts/unity_client.py switch_platform target=iOS
python3 <skill-path>/scripts/unity_client.py switch_platform target=Android
python3 <skill-path>/scripts/unity_client.py switch_platform target=macOS
python3 <skill-path>/scripts/unity_client.py switch_platform target=WebGL

MultiSet SDK Configuration

Get current MultiSet config:

bash
python3 <skill-path>/scripts/unity_client.py multiset --pretty

Set MultiSet credentials:

bash
# Set client ID and secret (creates Assets/Resources/MultiSetConfig.asset)
python3 <skill-path>/scripts/unity_client.py set_multiset \
  clientId=YOUR_CLIENT_ID \
  clientSecret=YOUR_CLIENT_SECRET

Create generic ScriptableObject:

bash
# Create any ScriptableObject asset
python3 <skill-path>/scripts/unity_client.py create_so \
  typeName=MultiSetConfig \
  path=Assets/Resources/MultiSetConfig.asset

Python API Usage

python
import sys, os
sys.path.append(os.path.expanduser('~/.claude/skills/unity/scripts'))
from unity_client import send_command

# Ping
result = send_command('ping')

# Create cube and color it
send_command('execute_menu', {'path': 'GameObject/3D Object/Cube'})
send_command('set_material_color', {'name': 'Cube', 'color': '0000FF'})

# Animate
send_command('start_rotation', {'name': 'Cube', 'y': 45})
send_command('start_orbit', {'name': 'Cube', 'radius': 3, 'speed': 60})

# Install package
send_command('install_package', {'package': 'com.unity.xr.arkit'})

# Open settings
send_command('open_settings', {'path': 'Project/XR Plug-in Management'})

# Configure MultiSet SDK
send_command('set_multiset_config', {
    'clientId': 'your_client_id',
    'clientSecret': 'your_client_secret'
})

Response Format

All commands return JSON:

json
{
  "status": "success",
  "result": { ... }
}

Or on error:

json
{
  "status": "error",
  "error": "Error description"
}

Troubleshooting

"No Unity port files found"

  • Unity must be running with Bridge Lite installed
  • Check ~/.unity-bridge/ for status files

"Connection refused"

  • Unity may be recompiling - wait and retry
  • Restart Unity if bridge is stuck

"Unknown command"

  • Unity needs to recompile after code changes
  • Click on Unity window to trigger recompile