uloop-execute-dynamic-code

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

uloop execute-dynamic-code

uloop execute-dynamic-code

Execute C# code dynamically in Unity Editor.
在Unity Editor中动态执行C#代码。

Usage

使用方法

bash
uloop execute-dynamic-code --code '<c# code>'
bash
uloop execute-dynamic-code --code '<c# code>'

Parameters

参数

ParameterTypeDescription
--code
stringC# code to execute (direct statements, no class wrapper)
--compile-only
booleanCompile without execution
--auto-qualify-unity-types-once
booleanAuto-qualify Unity types
参数类型说明
--code
string要执行的C#代码(直接写语句,无需类包装)
--compile-only
boolean仅编译不执行
--auto-qualify-unity-types-once
boolean自动限定Unity类型

Code Format

代码格式

Write direct statements only (no classes/namespaces/methods). Return is optional.
csharp
// Using directives at top are hoisted
using UnityEngine;
var x = Mathf.PI;
return x;
只需编写直接执行的语句(无需类/命名空间/方法)。返回值可选。
csharp
// 顶部的using指令会被提升
using UnityEngine;
var x = Mathf.PI;
return x;

String Literals (Shell-specific)

字符串字面量(Shell相关)

ShellMethod
bash/zsh/MINGW64/Git Bash
'Debug.Log("Hello!");'
PowerShell
'Debug.Log(""Hello!"");'
Shell环境写法
bash/zsh/MINGW64/Git Bash
'Debug.Log("Hello!");'
PowerShell
'Debug.Log(""Hello!"");'

Allowed Operations

允许的操作

  • Prefab/material wiring (PrefabUtility)
  • AddComponent + reference wiring (SerializedObject)
  • Scene/hierarchy edits
  • Inspector modifications
  • 预制件/材质关联(PrefabUtility)
  • 添加组件 + 引用关联(SerializedObject)
  • 场景/层级编辑
  • 检视面板修改

Forbidden Operations

禁止的操作

  • System.IO.* (File/Directory/Path)
  • AssetDatabase.CreateFolder / file writes
  • Create/edit .cs/.asmdef files
  • System.IO.*(文件/目录/路径相关操作)
  • AssetDatabase.CreateFolder / 文件写入
  • 创建/编辑.cs/.asmdef文件

Examples

示例

bash / zsh / MINGW64 / Git Bash

bash / zsh / MINGW64 / Git Bash

bash
uloop execute-dynamic-code --code 'return Selection.activeGameObject?.name;'
uloop execute-dynamic-code --code 'new GameObject("MyObject");'
uloop execute-dynamic-code --code 'UnityEngine.Debug.Log("Hello from CLI!");'
bash
uloop execute-dynamic-code --code 'return Selection.activeGameObject?.name;'
uloop execute-dynamic-code --code 'new GameObject("MyObject");'
uloop execute-dynamic-code --code 'UnityEngine.Debug.Log("Hello from CLI!");'

PowerShell

PowerShell

powershell
uloop execute-dynamic-code --code 'return Selection.activeGameObject?.name;'
uloop execute-dynamic-code --code 'new GameObject(""MyObject"");'
uloop execute-dynamic-code --code 'UnityEngine.Debug.Log(""Hello from CLI!"");'
powershell
uloop execute-dynamic-code --code 'return Selection.activeGameObject?.name;'
uloop execute-dynamic-code --code 'new GameObject(""MyObject"");'
uloop execute-dynamic-code --code 'UnityEngine.Debug.Log(""Hello from CLI!"");'

Output

输出

Returns JSON with execution result or compile errors.
返回包含执行结果或编译错误的JSON数据。

Notes

注意事项

For file/directory operations, use terminal commands instead.
如需进行文件/目录操作,请使用终端命令。

Code Examples by Category

按分类划分的代码示例

For detailed code examples, refer to these files:
  • Prefab operations: See examples/prefab-operations.md
    • Create prefabs, instantiate, add components, modify properties
  • Material operations: See examples/material-operations.md
    • Create materials, set shaders/textures, modify properties
  • Asset operations: See examples/asset-operations.md
    • Find/search assets, duplicate, move, rename, load
  • ScriptableObject: See examples/scriptableobject.md
    • Create ScriptableObjects, modify with SerializedObject
  • Scene operations: See examples/scene-operations.md
    • Create/modify GameObjects, set parents, wire references, load scenes
如需查看详细代码示例,请参考以下文件:
  • 预制件操作:查看 examples/prefab-operations.md
    • 创建预制件、实例化、添加组件、修改属性
  • 材质操作:查看 examples/material-operations.md
    • 创建材质、设置着色器/纹理、修改属性
  • 资源操作:查看 examples/asset-operations.md
    • 查找/搜索资源、复制、移动、重命名、加载
  • ScriptableObject:查看 examples/scriptableobject.md
    • 创建ScriptableObject、借助SerializedObject修改
  • 场景操作:查看 examples/scene-operations.md
    • 创建/修改GameObject、设置父对象、关联引用、加载场景