unity-agentic-tools 0.3.2 → 0.3.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -3
- package/dist/cli.js +700 -253
- package/dist/index.js +418 -184
- package/native/unity-file-tools.darwin-arm64.node +0 -0
- package/native/unity-file-tools.darwin-x64.node +0 -0
- package/native/unity-file-tools.linux-x64-gnu.node +0 -0
- package/native/unity-file-tools.win32-x64-msvc.node +0 -0
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -205,7 +205,7 @@ var require_package = __commonJS((exports2, module2) => {
|
|
|
205
205
|
module2.exports = {
|
|
206
206
|
name: "unity-agentic-tools",
|
|
207
207
|
packageManager: "bun@latest",
|
|
208
|
-
version: "0.3.
|
|
208
|
+
version: "0.3.3",
|
|
209
209
|
description: "Fast, token-efficient Unity YAML parser for AI agents",
|
|
210
210
|
exports: {
|
|
211
211
|
".": {
|
|
@@ -2402,188 +2402,61 @@ function resolve_enum_fields(fields, project_path) {
|
|
|
2402
2402
|
}
|
|
2403
2403
|
} catch {}
|
|
2404
2404
|
}
|
|
2405
|
-
|
|
2406
|
-
|
|
2407
|
-
|
|
2408
|
-
|
|
2409
|
-
|
|
2410
|
-
|
|
2411
|
-
|
|
2412
|
-
|
|
2413
|
-
|
|
2414
|
-
|
|
2415
|
-
|
|
2416
|
-
|
|
2417
|
-
|
|
2418
|
-
|
|
2419
|
-
|
|
2420
|
-
|
|
2421
|
-
|
|
2422
|
-
|
|
2423
|
-
|
|
2424
|
-
Boolean: "0",
|
|
2425
|
-
String: "",
|
|
2426
|
-
Byte: "0",
|
|
2427
|
-
SByte: "0",
|
|
2428
|
-
Int16: "0",
|
|
2429
|
-
UInt16: "0",
|
|
2430
|
-
UInt32: "0",
|
|
2431
|
-
Int64: "0",
|
|
2432
|
-
UInt64: "0",
|
|
2433
|
-
Char: "0"
|
|
2434
|
-
};
|
|
2435
|
-
var STRUCT_DEFAULTS = {
|
|
2436
|
-
Vector2: "{x: 0, y: 0}",
|
|
2437
|
-
Vector3: "{x: 0, y: 0, z: 0}",
|
|
2438
|
-
Vector4: "{x: 0, y: 0, z: 0, w: 0}",
|
|
2439
|
-
Vector2Int: "{x: 0, y: 0}",
|
|
2440
|
-
Vector3Int: "{x: 0, y: 0, z: 0}",
|
|
2441
|
-
Quaternion: "{x: 0, y: 0, z: 0, w: 1}",
|
|
2442
|
-
Color: "{r: 0, g: 0, b: 0, a: 0}",
|
|
2443
|
-
Color32: "{r: 0, g: 0, b: 0, a: 0}",
|
|
2444
|
-
Rect: `serializedVersion: 2
|
|
2445
|
-
x: 0
|
|
2446
|
-
y: 0
|
|
2447
|
-
width: 0
|
|
2448
|
-
height: 0`,
|
|
2449
|
-
RectInt: "{x: 0, y: 0, width: 0, height: 0}",
|
|
2450
|
-
RectOffset: "{m_Left: 0, m_Right: 0, m_Top: 0, m_Bottom: 0}",
|
|
2451
|
-
Matrix4x4: "{e00: 1, e01: 0, e02: 0, e03: 0, e10: 0, e11: 1, e12: 0, e13: 0, e20: 0, e21: 0, e22: 1, e23: 0, e30: 0, e31: 0, e32: 0, e33: 1}",
|
|
2452
|
-
LayerMask: `serializedVersion: 2
|
|
2453
|
-
m_Bits: 0`
|
|
2454
|
-
};
|
|
2455
|
-
var VERSION_GATED_STRUCT_DEFAULTS = {
|
|
2456
|
-
Hash128: { value: `serializedVersion: 2
|
|
2457
|
-
Hash: 00000000000000000000000000000000`, min_major: 2021, min_minor: 1 },
|
|
2458
|
-
RenderingLayerMask: { value: `serializedVersion: 2
|
|
2459
|
-
m_Bits: 0`, min_major: 6000, min_minor: 0 }
|
|
2460
|
-
};
|
|
2461
|
-
var BLOCK_STRUCT_DEFAULTS = {
|
|
2462
|
-
Bounds: `m_Center: {x: 0, y: 0, z: 0}
|
|
2463
|
-
m_Extent: {x: 0, y: 0, z: 0}`,
|
|
2464
|
-
BoundsInt: `m_Position: {x: 0, y: 0, z: 0}
|
|
2465
|
-
m_Size: {x: 0, y: 0, z: 0}`
|
|
2466
|
-
};
|
|
2467
|
-
var OBJECT_REF_TYPES = new Set([
|
|
2468
|
-
"GameObject",
|
|
2469
|
-
"Transform",
|
|
2470
|
-
"RectTransform",
|
|
2471
|
-
"Material",
|
|
2472
|
-
"Texture",
|
|
2473
|
-
"Texture2D",
|
|
2474
|
-
"Texture3D",
|
|
2475
|
-
"RenderTexture",
|
|
2476
|
-
"Sprite",
|
|
2477
|
-
"AudioClip",
|
|
2478
|
-
"VideoClip",
|
|
2479
|
-
"Mesh",
|
|
2480
|
-
"Shader",
|
|
2481
|
-
"ComputeShader",
|
|
2482
|
-
"AnimationClip",
|
|
2483
|
-
"AnimatorController",
|
|
2484
|
-
"RuntimeAnimatorController",
|
|
2485
|
-
"PhysicMaterial",
|
|
2486
|
-
"PhysicsMaterial",
|
|
2487
|
-
"PhysicsMaterial2D",
|
|
2488
|
-
"Font",
|
|
2489
|
-
"TMP_FontAsset",
|
|
2490
|
-
"Object",
|
|
2491
|
-
"Component",
|
|
2492
|
-
"Behaviour",
|
|
2493
|
-
"MonoBehaviour",
|
|
2494
|
-
"ScriptableObject",
|
|
2495
|
-
"Rigidbody",
|
|
2496
|
-
"Rigidbody2D",
|
|
2497
|
-
"Collider",
|
|
2498
|
-
"Collider2D",
|
|
2499
|
-
"Camera",
|
|
2500
|
-
"Light",
|
|
2501
|
-
"Canvas",
|
|
2502
|
-
"CanvasGroup",
|
|
2503
|
-
"EventSystem",
|
|
2504
|
-
"AudioSource",
|
|
2505
|
-
"ParticleSystem",
|
|
2506
|
-
"TextAsset",
|
|
2507
|
-
"TerrainData"
|
|
2508
|
-
]);
|
|
2509
|
-
function version_at_least(version, min_major, min_minor) {
|
|
2510
|
-
if (!version)
|
|
2511
|
-
return false;
|
|
2512
|
-
if (version.major > min_major)
|
|
2513
|
-
return true;
|
|
2514
|
-
if (version.major === min_major)
|
|
2515
|
-
return version.minor >= min_minor;
|
|
2516
|
-
return false;
|
|
2517
|
-
}
|
|
2518
|
-
function yaml_default_for_type(csharp_type, version) {
|
|
2519
|
-
if (csharp_type.endsWith("?")) {
|
|
2520
|
-
return null;
|
|
2521
|
-
}
|
|
2522
|
-
if (csharp_type in PRIMITIVE_DEFAULTS) {
|
|
2523
|
-
return PRIMITIVE_DEFAULTS[csharp_type];
|
|
2524
|
-
}
|
|
2525
|
-
if (csharp_type in STRUCT_DEFAULTS) {
|
|
2526
|
-
return STRUCT_DEFAULTS[csharp_type];
|
|
2527
|
-
}
|
|
2528
|
-
if (csharp_type in VERSION_GATED_STRUCT_DEFAULTS) {
|
|
2529
|
-
const gated = VERSION_GATED_STRUCT_DEFAULTS[csharp_type];
|
|
2530
|
-
if (version_at_least(version, gated.min_major, gated.min_minor)) {
|
|
2531
|
-
return gated.value;
|
|
2532
|
-
}
|
|
2533
|
-
return null;
|
|
2534
|
-
}
|
|
2535
|
-
if (csharp_type in BLOCK_STRUCT_DEFAULTS) {
|
|
2536
|
-
return BLOCK_STRUCT_DEFAULTS[csharp_type];
|
|
2537
|
-
}
|
|
2538
|
-
if (csharp_type.endsWith("[]")) {
|
|
2539
|
-
return "[]";
|
|
2540
|
-
}
|
|
2541
|
-
if (csharp_type.startsWith("List<") && csharp_type.endsWith(">")) {
|
|
2542
|
-
return "[]";
|
|
2543
|
-
}
|
|
2544
|
-
if (OBJECT_REF_TYPES.has(csharp_type)) {
|
|
2545
|
-
return "{fileID: 0}";
|
|
2546
|
-
}
|
|
2547
|
-
return "{fileID: 0}";
|
|
2548
|
-
}
|
|
2549
|
-
function generate_field_yaml(fields, version, indent = " ") {
|
|
2550
|
-
const lines = [];
|
|
2551
|
-
for (const field of fields) {
|
|
2552
|
-
if (field.hasSerializeReference) {
|
|
2553
|
-
const t = field.typeName;
|
|
2554
|
-
if (t.endsWith("[]") || t.startsWith("List<") && t.endsWith(">")) {
|
|
2555
|
-
lines.push(`${indent}${field.name}: []`);
|
|
2556
|
-
} else {
|
|
2557
|
-
lines.push(`${indent}${field.name}:`);
|
|
2558
|
-
lines.push(`${indent} rid: 0`);
|
|
2405
|
+
function build_type_lookup(project_path) {
|
|
2406
|
+
let extractFn = null;
|
|
2407
|
+
try {
|
|
2408
|
+
const { getNativeExtractSerializedFields: getNativeExtractSerializedFields2 } = (init_scanner(), __toCommonJS(exports_scanner));
|
|
2409
|
+
extractFn = getNativeExtractSerializedFields2();
|
|
2410
|
+
} catch {}
|
|
2411
|
+
if (!extractFn)
|
|
2412
|
+
return () => null;
|
|
2413
|
+
const assetsDir = path3.join(project_path, "Assets");
|
|
2414
|
+
const csIndex = new Map;
|
|
2415
|
+
try {
|
|
2416
|
+
const { readdirSync: readdirSync4 } = require("fs");
|
|
2417
|
+
const entries = readdirSync4(assetsDir, { recursive: true, withFileTypes: false });
|
|
2418
|
+
for (const entry of entries) {
|
|
2419
|
+
if (typeof entry === "string" && entry.endsWith(".cs")) {
|
|
2420
|
+
const basename4 = entry.substring(entry.lastIndexOf("/") + 1).replace(/\.cs$/, "");
|
|
2421
|
+
if (!csIndex.has(basename4)) {
|
|
2422
|
+
csIndex.set(basename4, path3.join(assetsDir, entry));
|
|
2423
|
+
}
|
|
2559
2424
|
}
|
|
2560
|
-
continue;
|
|
2561
2425
|
}
|
|
2562
|
-
|
|
2563
|
-
|
|
2564
|
-
|
|
2426
|
+
} catch {}
|
|
2427
|
+
if (csIndex.size === 0)
|
|
2428
|
+
return () => null;
|
|
2429
|
+
const cache = new Map;
|
|
2430
|
+
return (typeName) => {
|
|
2431
|
+
if (cache.has(typeName))
|
|
2432
|
+
return cache.get(typeName) ?? null;
|
|
2433
|
+
const shortName = typeName.includes(".") ? typeName.substring(typeName.lastIndexOf(".") + 1) : typeName;
|
|
2434
|
+
const csPath = csIndex.get(shortName);
|
|
2435
|
+
if (!csPath || !import_fs8.existsSync(csPath)) {
|
|
2436
|
+
cache.set(typeName, null);
|
|
2437
|
+
return null;
|
|
2565
2438
|
}
|
|
2566
|
-
|
|
2567
|
-
|
|
2568
|
-
|
|
2569
|
-
|
|
2570
|
-
|
|
2571
|
-
lines.push(`${indent}${sub_line}`);
|
|
2439
|
+
try {
|
|
2440
|
+
const typeInfos = extractFn(csPath);
|
|
2441
|
+
if (!typeInfos || typeInfos.length === 0) {
|
|
2442
|
+
cache.set(typeName, null);
|
|
2443
|
+
return null;
|
|
2572
2444
|
}
|
|
2573
|
-
|
|
2574
|
-
|
|
2445
|
+
const match = typeInfos.find((t) => t.name === shortName);
|
|
2446
|
+
if (match && match.fields && match.fields.length > 0) {
|
|
2447
|
+
resolve_enum_fields(match.fields, project_path);
|
|
2448
|
+
cache.set(typeName, match.fields);
|
|
2449
|
+
return match.fields;
|
|
2450
|
+
}
|
|
2451
|
+
cache.set(typeName, null);
|
|
2452
|
+
return null;
|
|
2453
|
+
} catch {
|
|
2454
|
+
cache.set(typeName, null);
|
|
2455
|
+
return null;
|
|
2575
2456
|
}
|
|
2576
|
-
}
|
|
2577
|
-
return lines.length > 0 ? `
|
|
2578
|
-
` + lines.join(`
|
|
2579
|
-
`) + `
|
|
2580
|
-
` : `
|
|
2581
|
-
`;
|
|
2457
|
+
};
|
|
2582
2458
|
}
|
|
2583
2459
|
|
|
2584
|
-
// src/editor/unity-document.ts
|
|
2585
|
-
var import_fs9 = require("fs");
|
|
2586
|
-
|
|
2587
2460
|
// src/editor/unity-block.ts
|
|
2588
2461
|
var HEADER_PATTERN = /^--- !u!(\d+) &(-?\d+)(\s+stripped)?/;
|
|
2589
2462
|
function parse_header(raw) {
|
|
@@ -2679,10 +2552,36 @@ class UnityBlock {
|
|
|
2679
2552
|
const old_raw = this._raw;
|
|
2680
2553
|
const effective_ref = object_reference && object_reference !== "{fileID: 0}" ? object_reference : undefined;
|
|
2681
2554
|
if (!path4.includes(".") && !path4.includes("Array")) {
|
|
2682
|
-
const prop_pattern = new RegExp(`(^\\s*${escape_regex(path4)}
|
|
2683
|
-
|
|
2555
|
+
const prop_pattern = new RegExp(`(^\\s*${escape_regex(path4)}:[ \\t]*)(.*)$`, "m");
|
|
2556
|
+
const match = this._raw.match(prop_pattern);
|
|
2557
|
+
if (match && match.index !== undefined) {
|
|
2684
2558
|
const replacement_value = effective_ref ?? yaml_quote_if_needed(value);
|
|
2685
|
-
|
|
2559
|
+
const current_inline = match[2];
|
|
2560
|
+
if (current_inline.trim() === "") {
|
|
2561
|
+
const key_indent = (match[0].match(/^[ \t]*/)?.[0] || "").length;
|
|
2562
|
+
const after = match.index + match[0].length;
|
|
2563
|
+
let end = after;
|
|
2564
|
+
const rest = this._raw.slice(after);
|
|
2565
|
+
const rest_lines = rest.split(`
|
|
2566
|
+
`);
|
|
2567
|
+
for (let i = 1;i < rest_lines.length; i++) {
|
|
2568
|
+
const line = rest_lines[i];
|
|
2569
|
+
if (line.trim() === "") {
|
|
2570
|
+
end += 1 + line.length;
|
|
2571
|
+
continue;
|
|
2572
|
+
}
|
|
2573
|
+
const line_indent = (line.match(/^[ \t]*/)?.[0] || "").length;
|
|
2574
|
+
if (line_indent > key_indent) {
|
|
2575
|
+
end += 1 + line.length;
|
|
2576
|
+
} else {
|
|
2577
|
+
break;
|
|
2578
|
+
}
|
|
2579
|
+
}
|
|
2580
|
+
const prefix = match[1].trimEnd() + " ";
|
|
2581
|
+
this._raw = this._raw.slice(0, match.index) + prefix + replacement_value + this._raw.slice(end);
|
|
2582
|
+
} else {
|
|
2583
|
+
this._raw = this._raw.replace(prop_pattern, (_match, prefix) => prefix + replacement_value);
|
|
2584
|
+
}
|
|
2686
2585
|
} else {
|
|
2687
2586
|
const insert_value = effective_ref ?? yaml_quote_if_needed(value);
|
|
2688
2587
|
this._insert_property(path4, insert_value);
|
|
@@ -2762,6 +2661,11 @@ class UnityBlock {
|
|
|
2762
2661
|
if (parent_pattern.test(this._raw)) {
|
|
2763
2662
|
return;
|
|
2764
2663
|
}
|
|
2664
|
+
const alt = parent.startsWith("m_") ? parent.slice(2) : "m_" + parent;
|
|
2665
|
+
const alt_pattern = new RegExp(`^[ \\t]*${escape_regex(alt)}:`, "m");
|
|
2666
|
+
if (alt_pattern.test(this._raw)) {
|
|
2667
|
+
return;
|
|
2668
|
+
}
|
|
2765
2669
|
const struct_block = ` ${parent}:
|
|
2766
2670
|
${child}: ${value}`;
|
|
2767
2671
|
const eci_pattern = /^([ \t]*m_EditorClassIdentifier:[ \t]*[^\n]*)/m;
|
|
@@ -3138,7 +3042,285 @@ ${element_indent2}- ${value}`);
|
|
|
3138
3042
|
}
|
|
3139
3043
|
}
|
|
3140
3044
|
|
|
3045
|
+
// src/editor/yaml-fields.ts
|
|
3046
|
+
var PRIMITIVE_DEFAULTS = {
|
|
3047
|
+
int: "0",
|
|
3048
|
+
float: "0",
|
|
3049
|
+
double: "0",
|
|
3050
|
+
bool: "0",
|
|
3051
|
+
string: "",
|
|
3052
|
+
byte: "0",
|
|
3053
|
+
sbyte: "0",
|
|
3054
|
+
short: "0",
|
|
3055
|
+
ushort: "0",
|
|
3056
|
+
uint: "0",
|
|
3057
|
+
long: "0",
|
|
3058
|
+
ulong: "0",
|
|
3059
|
+
char: "0",
|
|
3060
|
+
Int32: "0",
|
|
3061
|
+
Single: "0",
|
|
3062
|
+
Double: "0",
|
|
3063
|
+
Boolean: "0",
|
|
3064
|
+
String: "",
|
|
3065
|
+
Byte: "0",
|
|
3066
|
+
SByte: "0",
|
|
3067
|
+
Int16: "0",
|
|
3068
|
+
UInt16: "0",
|
|
3069
|
+
UInt32: "0",
|
|
3070
|
+
Int64: "0",
|
|
3071
|
+
UInt64: "0",
|
|
3072
|
+
Char: "0"
|
|
3073
|
+
};
|
|
3074
|
+
var STRUCT_DEFAULTS = {
|
|
3075
|
+
Vector2: "{x: 0, y: 0}",
|
|
3076
|
+
Vector3: "{x: 0, y: 0, z: 0}",
|
|
3077
|
+
Vector4: "{x: 0, y: 0, z: 0, w: 0}",
|
|
3078
|
+
Vector2Int: "{x: 0, y: 0}",
|
|
3079
|
+
Vector3Int: "{x: 0, y: 0, z: 0}",
|
|
3080
|
+
Quaternion: "{x: 0, y: 0, z: 0, w: 1}",
|
|
3081
|
+
Color: "{r: 0, g: 0, b: 0, a: 0}",
|
|
3082
|
+
Color32: "{r: 0, g: 0, b: 0, a: 0}",
|
|
3083
|
+
Rect: `serializedVersion: 2
|
|
3084
|
+
x: 0
|
|
3085
|
+
y: 0
|
|
3086
|
+
width: 0
|
|
3087
|
+
height: 0`,
|
|
3088
|
+
RectInt: "{x: 0, y: 0, width: 0, height: 0}",
|
|
3089
|
+
RectOffset: "{m_Left: 0, m_Right: 0, m_Top: 0, m_Bottom: 0}",
|
|
3090
|
+
Matrix4x4: "{e00: 1, e01: 0, e02: 0, e03: 0, e10: 0, e11: 1, e12: 0, e13: 0, e20: 0, e21: 0, e22: 1, e23: 0, e30: 0, e31: 0, e32: 0, e33: 1}",
|
|
3091
|
+
LayerMask: `serializedVersion: 2
|
|
3092
|
+
m_Bits: 0`
|
|
3093
|
+
};
|
|
3094
|
+
var VERSION_GATED_STRUCT_DEFAULTS = {
|
|
3095
|
+
Hash128: { value: `serializedVersion: 2
|
|
3096
|
+
Hash: 00000000000000000000000000000000`, min_major: 2021, min_minor: 1 },
|
|
3097
|
+
RenderingLayerMask: { value: `serializedVersion: 2
|
|
3098
|
+
m_Bits: 0`, min_major: 6000, min_minor: 0 }
|
|
3099
|
+
};
|
|
3100
|
+
var BLOCK_STRUCT_DEFAULTS = {
|
|
3101
|
+
Bounds: `m_Center: {x: 0, y: 0, z: 0}
|
|
3102
|
+
m_Extent: {x: 0, y: 0, z: 0}`,
|
|
3103
|
+
BoundsInt: `m_Position: {x: 0, y: 0, z: 0}
|
|
3104
|
+
m_Size: {x: 0, y: 0, z: 0}`
|
|
3105
|
+
};
|
|
3106
|
+
var OBJECT_REF_TYPES = new Set([
|
|
3107
|
+
"GameObject",
|
|
3108
|
+
"Transform",
|
|
3109
|
+
"RectTransform",
|
|
3110
|
+
"Material",
|
|
3111
|
+
"Texture",
|
|
3112
|
+
"Texture2D",
|
|
3113
|
+
"Texture3D",
|
|
3114
|
+
"RenderTexture",
|
|
3115
|
+
"Sprite",
|
|
3116
|
+
"AudioClip",
|
|
3117
|
+
"VideoClip",
|
|
3118
|
+
"Mesh",
|
|
3119
|
+
"Shader",
|
|
3120
|
+
"ComputeShader",
|
|
3121
|
+
"AnimationClip",
|
|
3122
|
+
"AnimatorController",
|
|
3123
|
+
"RuntimeAnimatorController",
|
|
3124
|
+
"PhysicMaterial",
|
|
3125
|
+
"PhysicsMaterial",
|
|
3126
|
+
"PhysicsMaterial2D",
|
|
3127
|
+
"Font",
|
|
3128
|
+
"TMP_FontAsset",
|
|
3129
|
+
"Object",
|
|
3130
|
+
"Component",
|
|
3131
|
+
"Behaviour",
|
|
3132
|
+
"MonoBehaviour",
|
|
3133
|
+
"ScriptableObject",
|
|
3134
|
+
"Rigidbody",
|
|
3135
|
+
"Rigidbody2D",
|
|
3136
|
+
"Collider",
|
|
3137
|
+
"Collider2D",
|
|
3138
|
+
"Camera",
|
|
3139
|
+
"Light",
|
|
3140
|
+
"Canvas",
|
|
3141
|
+
"CanvasGroup",
|
|
3142
|
+
"EventSystem",
|
|
3143
|
+
"AudioSource",
|
|
3144
|
+
"ParticleSystem",
|
|
3145
|
+
"TextAsset",
|
|
3146
|
+
"TerrainData"
|
|
3147
|
+
]);
|
|
3148
|
+
function version_at_least(version, min_major, min_minor) {
|
|
3149
|
+
if (!version)
|
|
3150
|
+
return false;
|
|
3151
|
+
if (version.major > min_major)
|
|
3152
|
+
return true;
|
|
3153
|
+
if (version.major === min_major)
|
|
3154
|
+
return version.minor >= min_minor;
|
|
3155
|
+
return false;
|
|
3156
|
+
}
|
|
3157
|
+
function yaml_default_for_type(csharp_type, version) {
|
|
3158
|
+
if (csharp_type.endsWith("?")) {
|
|
3159
|
+
return null;
|
|
3160
|
+
}
|
|
3161
|
+
if (csharp_type in PRIMITIVE_DEFAULTS) {
|
|
3162
|
+
return PRIMITIVE_DEFAULTS[csharp_type];
|
|
3163
|
+
}
|
|
3164
|
+
if (csharp_type in STRUCT_DEFAULTS) {
|
|
3165
|
+
return STRUCT_DEFAULTS[csharp_type];
|
|
3166
|
+
}
|
|
3167
|
+
if (csharp_type in VERSION_GATED_STRUCT_DEFAULTS) {
|
|
3168
|
+
const gated = VERSION_GATED_STRUCT_DEFAULTS[csharp_type];
|
|
3169
|
+
if (version_at_least(version, gated.min_major, gated.min_minor)) {
|
|
3170
|
+
return gated.value;
|
|
3171
|
+
}
|
|
3172
|
+
return null;
|
|
3173
|
+
}
|
|
3174
|
+
if (csharp_type in BLOCK_STRUCT_DEFAULTS) {
|
|
3175
|
+
return BLOCK_STRUCT_DEFAULTS[csharp_type];
|
|
3176
|
+
}
|
|
3177
|
+
if (csharp_type.endsWith("[]")) {
|
|
3178
|
+
return "[]";
|
|
3179
|
+
}
|
|
3180
|
+
if (csharp_type.startsWith("List<") && csharp_type.endsWith(">")) {
|
|
3181
|
+
return "[]";
|
|
3182
|
+
}
|
|
3183
|
+
if (OBJECT_REF_TYPES.has(csharp_type)) {
|
|
3184
|
+
return "{fileID: 0}";
|
|
3185
|
+
}
|
|
3186
|
+
return "{fileID: 0}";
|
|
3187
|
+
}
|
|
3188
|
+
function generate_field_yaml(fields, version, indent = " ", type_lookup) {
|
|
3189
|
+
const lines = [];
|
|
3190
|
+
for (const field of fields) {
|
|
3191
|
+
if (field.hasSerializeReference) {
|
|
3192
|
+
const t = field.typeName;
|
|
3193
|
+
if (t.endsWith("[]") || t.startsWith("List<") && t.endsWith(">")) {
|
|
3194
|
+
lines.push(`${indent}${field.name}: []`);
|
|
3195
|
+
} else {
|
|
3196
|
+
lines.push(`${indent}${field.name}:`);
|
|
3197
|
+
lines.push(`${indent} rid: 0`);
|
|
3198
|
+
}
|
|
3199
|
+
continue;
|
|
3200
|
+
}
|
|
3201
|
+
const default_value = yaml_default_for_type(field.typeName, version);
|
|
3202
|
+
if (default_value === null) {
|
|
3203
|
+
continue;
|
|
3204
|
+
}
|
|
3205
|
+
if (default_value === "{fileID: 0}" && type_lookup) {
|
|
3206
|
+
const struct_fields = type_lookup(field.typeName);
|
|
3207
|
+
if (struct_fields && struct_fields.length > 0) {
|
|
3208
|
+
lines.push(`${indent}${field.name}:`);
|
|
3209
|
+
const nested = generate_field_yaml(struct_fields, version, indent + " ", type_lookup);
|
|
3210
|
+
const nested_lines = nested.slice(1).replace(/\n$/, "").split(`
|
|
3211
|
+
`);
|
|
3212
|
+
for (const nl of nested_lines) {
|
|
3213
|
+
lines.push(nl);
|
|
3214
|
+
}
|
|
3215
|
+
continue;
|
|
3216
|
+
}
|
|
3217
|
+
}
|
|
3218
|
+
if (default_value.includes(`
|
|
3219
|
+
`)) {
|
|
3220
|
+
lines.push(`${indent}${field.name}:`);
|
|
3221
|
+
for (const sub_line of default_value.split(`
|
|
3222
|
+
`)) {
|
|
3223
|
+
lines.push(`${indent}${sub_line}`);
|
|
3224
|
+
}
|
|
3225
|
+
} else {
|
|
3226
|
+
lines.push(`${indent}${field.name}: ${default_value}`);
|
|
3227
|
+
}
|
|
3228
|
+
}
|
|
3229
|
+
return lines.length > 0 ? `
|
|
3230
|
+
` + lines.join(`
|
|
3231
|
+
`) + `
|
|
3232
|
+
` : `
|
|
3233
|
+
`;
|
|
3234
|
+
}
|
|
3235
|
+
function json_value_to_yaml_lines(value, indent = " ") {
|
|
3236
|
+
if (value === null || value === undefined) {
|
|
3237
|
+
return [""];
|
|
3238
|
+
}
|
|
3239
|
+
if (typeof value === "string") {
|
|
3240
|
+
return [yaml_quote_if_needed(value)];
|
|
3241
|
+
}
|
|
3242
|
+
if (typeof value === "number" || typeof value === "boolean") {
|
|
3243
|
+
return [String(value)];
|
|
3244
|
+
}
|
|
3245
|
+
if (Array.isArray(value)) {
|
|
3246
|
+
if (value.length === 0)
|
|
3247
|
+
return ["[]"];
|
|
3248
|
+
const lines = [];
|
|
3249
|
+
for (const item of value) {
|
|
3250
|
+
if (is_scalar(item) || is_empty_collection(item)) {
|
|
3251
|
+
const scalar = json_value_to_yaml_lines(item);
|
|
3252
|
+
lines.push(`${indent}- ${scalar[0]}`);
|
|
3253
|
+
} else if (is_flow_mappable(item)) {
|
|
3254
|
+
lines.push(`${indent}- ${to_flow_mapping(item)}`);
|
|
3255
|
+
} else {
|
|
3256
|
+
const child_lines = json_value_to_yaml_lines(item, indent + " ");
|
|
3257
|
+
lines.push(`${indent}- ${child_lines[0].trimStart()}`);
|
|
3258
|
+
for (let i = 1;i < child_lines.length; i++) {
|
|
3259
|
+
lines.push(child_lines[i]);
|
|
3260
|
+
}
|
|
3261
|
+
}
|
|
3262
|
+
}
|
|
3263
|
+
return lines;
|
|
3264
|
+
}
|
|
3265
|
+
if (typeof value === "object") {
|
|
3266
|
+
const entries = Object.entries(value);
|
|
3267
|
+
if (entries.length === 0)
|
|
3268
|
+
return ["{}"];
|
|
3269
|
+
const lines = [];
|
|
3270
|
+
for (const [key, val] of entries) {
|
|
3271
|
+
if (is_scalar(val) || is_empty_collection(val)) {
|
|
3272
|
+
const scalar = json_value_to_yaml_lines(val);
|
|
3273
|
+
lines.push(`${indent}${key}: ${scalar[0]}`);
|
|
3274
|
+
} else if (is_flow_mappable(val)) {
|
|
3275
|
+
lines.push(`${indent}${key}: ${to_flow_mapping(val)}`);
|
|
3276
|
+
} else {
|
|
3277
|
+
const child_indent = Array.isArray(val) ? indent : indent + " ";
|
|
3278
|
+
lines.push(`${indent}${key}:`);
|
|
3279
|
+
const child_lines = json_value_to_yaml_lines(val, child_indent);
|
|
3280
|
+
for (const cl of child_lines) {
|
|
3281
|
+
lines.push(cl);
|
|
3282
|
+
}
|
|
3283
|
+
}
|
|
3284
|
+
}
|
|
3285
|
+
return lines;
|
|
3286
|
+
}
|
|
3287
|
+
return [String(value)];
|
|
3288
|
+
}
|
|
3289
|
+
function is_scalar(value) {
|
|
3290
|
+
return value === null || value === undefined || typeof value === "string" || typeof value === "number" || typeof value === "boolean";
|
|
3291
|
+
}
|
|
3292
|
+
function is_empty_collection(value) {
|
|
3293
|
+
if (Array.isArray(value))
|
|
3294
|
+
return value.length === 0;
|
|
3295
|
+
if (typeof value === "object" && value !== null)
|
|
3296
|
+
return Object.keys(value).length === 0;
|
|
3297
|
+
return false;
|
|
3298
|
+
}
|
|
3299
|
+
function is_flow_mappable(value) {
|
|
3300
|
+
if (typeof value !== "object" || value === null || Array.isArray(value))
|
|
3301
|
+
return false;
|
|
3302
|
+
const entries = Object.entries(value);
|
|
3303
|
+
if (entries.length === 0)
|
|
3304
|
+
return false;
|
|
3305
|
+
return entries.every(([, v]) => is_scalar(v) || is_empty_collection(v));
|
|
3306
|
+
}
|
|
3307
|
+
function to_flow_mapping(obj) {
|
|
3308
|
+
const parts = Object.entries(obj).map(([k, v]) => {
|
|
3309
|
+
if (v === null || v === undefined)
|
|
3310
|
+
return `${k}: `;
|
|
3311
|
+
if (typeof v === "string")
|
|
3312
|
+
return `${k}: ${yaml_quote_if_needed(v)}`;
|
|
3313
|
+
if (Array.isArray(v) && v.length === 0)
|
|
3314
|
+
return `${k}: []`;
|
|
3315
|
+
if (typeof v === "object" && v !== null && Object.keys(v).length === 0)
|
|
3316
|
+
return `${k}: {}`;
|
|
3317
|
+
return `${k}: ${String(v)}`;
|
|
3318
|
+
});
|
|
3319
|
+
return `{${parts.join(", ")}}`;
|
|
3320
|
+
}
|
|
3321
|
+
|
|
3141
3322
|
// src/editor/unity-document.ts
|
|
3323
|
+
var import_fs9 = require("fs");
|
|
3142
3324
|
class UnityDocument {
|
|
3143
3325
|
file_path;
|
|
3144
3326
|
_header;
|
|
@@ -4108,8 +4290,8 @@ function addComponentToGameObject(doc, gameObjectId, componentId) {
|
|
|
4108
4290
|
`);
|
|
4109
4291
|
goBlock.replace_raw(raw);
|
|
4110
4292
|
}
|
|
4111
|
-
function createMonoBehaviourYAML(componentId, gameObjectId, scriptGuid, fields, version, scriptFileId = 11500000) {
|
|
4112
|
-
const field_yaml = fields && fields.length > 0 ? generate_field_yaml(fields, version) : `
|
|
4293
|
+
function createMonoBehaviourYAML(componentId, gameObjectId, scriptGuid, fields, version, scriptFileId = 11500000, type_lookup) {
|
|
4294
|
+
const field_yaml = fields && fields.length > 0 ? generate_field_yaml(fields, version, " ", type_lookup) : `
|
|
4113
4295
|
`;
|
|
4114
4296
|
const has_serialize_ref = fields?.some((f) => f.hasSerializeReference) ?? false;
|
|
4115
4297
|
const references_section = has_serialize_ref ? ` references:
|
|
@@ -4812,7 +4994,8 @@ function createScriptableObject(options) {
|
|
|
4812
4994
|
} catch {}
|
|
4813
4995
|
}
|
|
4814
4996
|
const baseName = path5.basename(output_path, ".asset");
|
|
4815
|
-
const
|
|
4997
|
+
const type_lookup = project_path ? build_type_lookup(project_path) : undefined;
|
|
4998
|
+
const field_yaml = resolved.fields && resolved.fields.length > 0 ? generate_field_yaml(resolved.fields, version, " ", type_lookup) : `
|
|
4816
4999
|
`;
|
|
4817
5000
|
let assetYaml = `%YAML 1.1
|
|
4818
5001
|
%TAG !u! tag:unity3d.com,2011:
|
|
@@ -4832,8 +5015,58 @@ MonoBehaviour:
|
|
|
4832
5015
|
const doc = UnityDocument.from_string(assetYaml);
|
|
4833
5016
|
const block = doc.blocks[0];
|
|
4834
5017
|
if (block) {
|
|
5018
|
+
const complex_entries = [];
|
|
4835
5019
|
for (const [key, val] of Object.entries(options.initial_values)) {
|
|
4836
|
-
|
|
5020
|
+
if (val === null || val === undefined || typeof val === "string" || typeof val === "number" || typeof val === "boolean") {
|
|
5021
|
+
block.set_property(key, String(val ?? ""));
|
|
5022
|
+
} else if (Array.isArray(val) && val.length === 0) {
|
|
5023
|
+
block.set_property(key, "[]");
|
|
5024
|
+
} else if (typeof val === "object" && val !== null && !Array.isArray(val) && Object.keys(val).length === 0) {
|
|
5025
|
+
block.set_property(key, "{}");
|
|
5026
|
+
} else {
|
|
5027
|
+
complex_entries.push([key, val]);
|
|
5028
|
+
}
|
|
5029
|
+
}
|
|
5030
|
+
if (complex_entries.length > 0) {
|
|
5031
|
+
let raw = block.raw;
|
|
5032
|
+
for (const [key, val] of complex_entries) {
|
|
5033
|
+
const yaml_lines = json_value_to_yaml_lines(val, " ");
|
|
5034
|
+
const key_pattern = new RegExp(`^([ \\t]*${key}:)[^\\n]*$`, "m");
|
|
5035
|
+
const key_match = raw.match(key_pattern);
|
|
5036
|
+
if (key_match && key_match.index !== undefined) {
|
|
5037
|
+
const key_indent = key_match[0].match(/^[ \t]*/)?.[0].length ?? 0;
|
|
5038
|
+
const after_key = key_match.index + key_match[0].length;
|
|
5039
|
+
let end = after_key;
|
|
5040
|
+
const remaining = raw.slice(after_key);
|
|
5041
|
+
const remaining_lines = remaining.split(`
|
|
5042
|
+
`);
|
|
5043
|
+
for (let i = 1;i < remaining_lines.length; i++) {
|
|
5044
|
+
const line = remaining_lines[i];
|
|
5045
|
+
if (line.trim() === "") {
|
|
5046
|
+
end += 1 + line.length;
|
|
5047
|
+
continue;
|
|
5048
|
+
}
|
|
5049
|
+
const line_indent = line.match(/^[ \t]*/)?.[0].length ?? 0;
|
|
5050
|
+
if (line_indent > key_indent) {
|
|
5051
|
+
end += 1 + line.length;
|
|
5052
|
+
} else {
|
|
5053
|
+
break;
|
|
5054
|
+
}
|
|
5055
|
+
}
|
|
5056
|
+
const block_yaml = ` ${key}:
|
|
5057
|
+
${yaml_lines.join(`
|
|
5058
|
+
`)}`;
|
|
5059
|
+
raw = raw.slice(0, key_match.index) + block_yaml + raw.slice(end);
|
|
5060
|
+
} else {
|
|
5061
|
+
const block_yaml = ` ${key}:
|
|
5062
|
+
${yaml_lines.join(`
|
|
5063
|
+
`)}`;
|
|
5064
|
+
raw = raw.trimEnd() + `
|
|
5065
|
+
` + block_yaml + `
|
|
5066
|
+
`;
|
|
5067
|
+
}
|
|
5068
|
+
}
|
|
5069
|
+
block.replace_raw(raw);
|
|
4837
5070
|
}
|
|
4838
5071
|
assetYaml = doc.serialize();
|
|
4839
5072
|
}
|
|
@@ -5106,7 +5339,8 @@ function addComponent(options) {
|
|
|
5106
5339
|
if (resolved.path?.endsWith(".dll") && resolved.class_name) {
|
|
5107
5340
|
scriptFileId = compute_dll_script_file_id(resolved.namespace ?? "", resolved.class_name);
|
|
5108
5341
|
}
|
|
5109
|
-
|
|
5342
|
+
const type_lookup_comp = project_path ? build_type_lookup(project_path) : undefined;
|
|
5343
|
+
componentYAML = createMonoBehaviourYAML(componentId, gameObjectId, resolved.guid, resolved.fields, version, scriptFileId, type_lookup_comp);
|
|
5110
5344
|
scriptGuid = resolved.guid;
|
|
5111
5345
|
scriptPath = resolved.path || undefined;
|
|
5112
5346
|
extractionError = resolved.extraction_error;
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|