unity-agentic-tools 0.1.0

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.

Potentially problematic release.


This version of unity-agentic-tools might be problematic. Click here for more details.

package/dist/index.js ADDED
@@ -0,0 +1,2719 @@
1
+ // @bun @bun-cjs
2
+ (function(exports, require, module, __filename, __dirname) {var __create = Object.create;
3
+ var __getProtoOf = Object.getPrototypeOf;
4
+ var __defProp = Object.defineProperty;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __toESM = (mod, isNodeMode, target) => {
9
+ target = mod != null ? __create(__getProtoOf(mod)) : {};
10
+ const to = isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target;
11
+ for (let key of __getOwnPropNames(mod))
12
+ if (!__hasOwnProp.call(to, key))
13
+ __defProp(to, key, {
14
+ get: () => mod[key],
15
+ enumerable: true
16
+ });
17
+ return to;
18
+ };
19
+ var __moduleCache = /* @__PURE__ */ new WeakMap;
20
+ var __toCommonJS = (from) => {
21
+ var entry = __moduleCache.get(from), desc;
22
+ if (entry)
23
+ return entry;
24
+ entry = __defProp({}, "__esModule", { value: true });
25
+ if (from && typeof from === "object" || typeof from === "function")
26
+ __getOwnPropNames(from).map((key) => !__hasOwnProp.call(entry, key) && __defProp(entry, key, {
27
+ get: () => from[key],
28
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
29
+ }));
30
+ __moduleCache.set(from, entry);
31
+ return entry;
32
+ };
33
+ var __commonJS = (cb, mod) => () => (mod || cb((mod = { exports: {} }).exports, mod), mod.exports);
34
+ var __export = (target, all) => {
35
+ for (var name in all)
36
+ __defProp(target, name, {
37
+ get: all[name],
38
+ enumerable: true,
39
+ configurable: true,
40
+ set: (newValue) => all[name] = () => newValue
41
+ });
42
+ };
43
+
44
+ // ../rust-core/index.js
45
+ var require_rust_core = __commonJS((exports2, module2) => {
46
+ var __dirname = "/home/runner/work/unity-agentic-tools/unity-agentic-tools/rust-core";
47
+ var { existsSync, readFileSync } = require("fs");
48
+ var { join } = require("path");
49
+ var { platform, arch } = process;
50
+ var nativeBinding = null;
51
+ var localFileExisted = false;
52
+ var loadError = null;
53
+ function isMusl() {
54
+ if (!process.report || typeof process.report.getReport !== "function") {
55
+ try {
56
+ const lddPath = require("child_process").execSync("which ldd").toString().trim();
57
+ return readFileSync(lddPath, "utf8").includes("musl");
58
+ } catch (e) {
59
+ return true;
60
+ }
61
+ } else {
62
+ const { glibcVersionRuntime } = process.report.getReport().header;
63
+ return !glibcVersionRuntime;
64
+ }
65
+ }
66
+ switch (platform) {
67
+ case "android":
68
+ switch (arch) {
69
+ case "arm64":
70
+ localFileExisted = existsSync(join(__dirname, "unity-file-tools.android-arm64.node"));
71
+ try {
72
+ if (localFileExisted) {
73
+ nativeBinding = (()=>{throw new Error("Cannot require module "+"./unity-file-tools.android-arm64.node");})();
74
+ } else {
75
+ nativeBinding = (()=>{throw new Error("Cannot require module "+"unity-file-tools-android-arm64");})();
76
+ }
77
+ } catch (e) {
78
+ loadError = e;
79
+ }
80
+ break;
81
+ case "arm":
82
+ localFileExisted = existsSync(join(__dirname, "unity-file-tools.android-arm-eabi.node"));
83
+ try {
84
+ if (localFileExisted) {
85
+ nativeBinding = (()=>{throw new Error("Cannot require module "+"./unity-file-tools.android-arm-eabi.node");})();
86
+ } else {
87
+ nativeBinding = (()=>{throw new Error("Cannot require module "+"unity-file-tools-android-arm-eabi");})();
88
+ }
89
+ } catch (e) {
90
+ loadError = e;
91
+ }
92
+ break;
93
+ default:
94
+ throw new Error(`Unsupported architecture on Android ${arch}`);
95
+ }
96
+ break;
97
+ case "win32":
98
+ switch (arch) {
99
+ case "x64":
100
+ localFileExisted = existsSync(join(__dirname, "unity-file-tools.win32-x64-msvc.node"));
101
+ try {
102
+ if (localFileExisted) {
103
+ nativeBinding = (()=>{throw new Error("Cannot require module "+"./unity-file-tools.win32-x64-msvc.node");})();
104
+ } else {
105
+ nativeBinding = (()=>{throw new Error("Cannot require module "+"unity-file-tools-win32-x64-msvc");})();
106
+ }
107
+ } catch (e) {
108
+ loadError = e;
109
+ }
110
+ break;
111
+ case "ia32":
112
+ localFileExisted = existsSync(join(__dirname, "unity-file-tools.win32-ia32-msvc.node"));
113
+ try {
114
+ if (localFileExisted) {
115
+ nativeBinding = (()=>{throw new Error("Cannot require module "+"./unity-file-tools.win32-ia32-msvc.node");})();
116
+ } else {
117
+ nativeBinding = (()=>{throw new Error("Cannot require module "+"unity-file-tools-win32-ia32-msvc");})();
118
+ }
119
+ } catch (e) {
120
+ loadError = e;
121
+ }
122
+ break;
123
+ case "arm64":
124
+ localFileExisted = existsSync(join(__dirname, "unity-file-tools.win32-arm64-msvc.node"));
125
+ try {
126
+ if (localFileExisted) {
127
+ nativeBinding = (()=>{throw new Error("Cannot require module "+"./unity-file-tools.win32-arm64-msvc.node");})();
128
+ } else {
129
+ nativeBinding = (()=>{throw new Error("Cannot require module "+"unity-file-tools-win32-arm64-msvc");})();
130
+ }
131
+ } catch (e) {
132
+ loadError = e;
133
+ }
134
+ break;
135
+ default:
136
+ throw new Error(`Unsupported architecture on Windows: ${arch}`);
137
+ }
138
+ break;
139
+ case "darwin":
140
+ localFileExisted = existsSync(join(__dirname, "unity-file-tools.darwin-universal.node"));
141
+ try {
142
+ if (localFileExisted) {
143
+ nativeBinding = (()=>{throw new Error("Cannot require module "+"./unity-file-tools.darwin-universal.node");})();
144
+ } else {
145
+ nativeBinding = (()=>{throw new Error("Cannot require module "+"unity-file-tools-darwin-universal");})();
146
+ }
147
+ break;
148
+ } catch {}
149
+ switch (arch) {
150
+ case "x64":
151
+ localFileExisted = existsSync(join(__dirname, "unity-file-tools.darwin-x64.node"));
152
+ try {
153
+ if (localFileExisted) {
154
+ nativeBinding = (()=>{throw new Error("Cannot require module "+"./unity-file-tools.darwin-x64.node");})();
155
+ } else {
156
+ nativeBinding = (()=>{throw new Error("Cannot require module "+"unity-file-tools-darwin-x64");})();
157
+ }
158
+ } catch (e) {
159
+ loadError = e;
160
+ }
161
+ break;
162
+ case "arm64":
163
+ localFileExisted = existsSync(join(__dirname, "unity-file-tools.darwin-arm64.node"));
164
+ try {
165
+ if (localFileExisted) {
166
+ nativeBinding = (()=>{throw new Error("Cannot require module "+"./unity-file-tools.darwin-arm64.node");})();
167
+ } else {
168
+ nativeBinding = (()=>{throw new Error("Cannot require module "+"unity-file-tools-darwin-arm64");})();
169
+ }
170
+ } catch (e) {
171
+ loadError = e;
172
+ }
173
+ break;
174
+ default:
175
+ throw new Error(`Unsupported architecture on macOS: ${arch}`);
176
+ }
177
+ break;
178
+ case "freebsd":
179
+ if (arch !== "x64") {
180
+ throw new Error(`Unsupported architecture on FreeBSD: ${arch}`);
181
+ }
182
+ localFileExisted = existsSync(join(__dirname, "unity-file-tools.freebsd-x64.node"));
183
+ try {
184
+ if (localFileExisted) {
185
+ nativeBinding = (()=>{throw new Error("Cannot require module "+"./unity-file-tools.freebsd-x64.node");})();
186
+ } else {
187
+ nativeBinding = (()=>{throw new Error("Cannot require module "+"unity-file-tools-freebsd-x64");})();
188
+ }
189
+ } catch (e) {
190
+ loadError = e;
191
+ }
192
+ break;
193
+ case "linux":
194
+ switch (arch) {
195
+ case "x64":
196
+ if (isMusl()) {
197
+ localFileExisted = existsSync(join(__dirname, "unity-file-tools.linux-x64-musl.node"));
198
+ try {
199
+ if (localFileExisted) {
200
+ nativeBinding = (()=>{throw new Error("Cannot require module "+"./unity-file-tools.linux-x64-musl.node");})();
201
+ } else {
202
+ nativeBinding = (()=>{throw new Error("Cannot require module "+"unity-file-tools-linux-x64-musl");})();
203
+ }
204
+ } catch (e) {
205
+ loadError = e;
206
+ }
207
+ } else {
208
+ localFileExisted = existsSync(join(__dirname, "unity-file-tools.linux-x64-gnu.node"));
209
+ try {
210
+ if (localFileExisted) {
211
+ nativeBinding = (()=>{throw new Error("Cannot require module "+"./unity-file-tools.linux-x64-gnu.node");})();
212
+ } else {
213
+ nativeBinding = (()=>{throw new Error("Cannot require module "+"unity-file-tools-linux-x64-gnu");})();
214
+ }
215
+ } catch (e) {
216
+ loadError = e;
217
+ }
218
+ }
219
+ break;
220
+ case "arm64":
221
+ if (isMusl()) {
222
+ localFileExisted = existsSync(join(__dirname, "unity-file-tools.linux-arm64-musl.node"));
223
+ try {
224
+ if (localFileExisted) {
225
+ nativeBinding = (()=>{throw new Error("Cannot require module "+"./unity-file-tools.linux-arm64-musl.node");})();
226
+ } else {
227
+ nativeBinding = (()=>{throw new Error("Cannot require module "+"unity-file-tools-linux-arm64-musl");})();
228
+ }
229
+ } catch (e) {
230
+ loadError = e;
231
+ }
232
+ } else {
233
+ localFileExisted = existsSync(join(__dirname, "unity-file-tools.linux-arm64-gnu.node"));
234
+ try {
235
+ if (localFileExisted) {
236
+ nativeBinding = (()=>{throw new Error("Cannot require module "+"./unity-file-tools.linux-arm64-gnu.node");})();
237
+ } else {
238
+ nativeBinding = (()=>{throw new Error("Cannot require module "+"unity-file-tools-linux-arm64-gnu");})();
239
+ }
240
+ } catch (e) {
241
+ loadError = e;
242
+ }
243
+ }
244
+ break;
245
+ case "arm":
246
+ if (isMusl()) {
247
+ localFileExisted = existsSync(join(__dirname, "unity-file-tools.linux-arm-musleabihf.node"));
248
+ try {
249
+ if (localFileExisted) {
250
+ nativeBinding = (()=>{throw new Error("Cannot require module "+"./unity-file-tools.linux-arm-musleabihf.node");})();
251
+ } else {
252
+ nativeBinding = (()=>{throw new Error("Cannot require module "+"unity-file-tools-linux-arm-musleabihf");})();
253
+ }
254
+ } catch (e) {
255
+ loadError = e;
256
+ }
257
+ } else {
258
+ localFileExisted = existsSync(join(__dirname, "unity-file-tools.linux-arm-gnueabihf.node"));
259
+ try {
260
+ if (localFileExisted) {
261
+ nativeBinding = (()=>{throw new Error("Cannot require module "+"./unity-file-tools.linux-arm-gnueabihf.node");})();
262
+ } else {
263
+ nativeBinding = (()=>{throw new Error("Cannot require module "+"unity-file-tools-linux-arm-gnueabihf");})();
264
+ }
265
+ } catch (e) {
266
+ loadError = e;
267
+ }
268
+ }
269
+ break;
270
+ case "riscv64":
271
+ if (isMusl()) {
272
+ localFileExisted = existsSync(join(__dirname, "unity-file-tools.linux-riscv64-musl.node"));
273
+ try {
274
+ if (localFileExisted) {
275
+ nativeBinding = (()=>{throw new Error("Cannot require module "+"./unity-file-tools.linux-riscv64-musl.node");})();
276
+ } else {
277
+ nativeBinding = (()=>{throw new Error("Cannot require module "+"unity-file-tools-linux-riscv64-musl");})();
278
+ }
279
+ } catch (e) {
280
+ loadError = e;
281
+ }
282
+ } else {
283
+ localFileExisted = existsSync(join(__dirname, "unity-file-tools.linux-riscv64-gnu.node"));
284
+ try {
285
+ if (localFileExisted) {
286
+ nativeBinding = (()=>{throw new Error("Cannot require module "+"./unity-file-tools.linux-riscv64-gnu.node");})();
287
+ } else {
288
+ nativeBinding = (()=>{throw new Error("Cannot require module "+"unity-file-tools-linux-riscv64-gnu");})();
289
+ }
290
+ } catch (e) {
291
+ loadError = e;
292
+ }
293
+ }
294
+ break;
295
+ case "s390x":
296
+ localFileExisted = existsSync(join(__dirname, "unity-file-tools.linux-s390x-gnu.node"));
297
+ try {
298
+ if (localFileExisted) {
299
+ nativeBinding = (()=>{throw new Error("Cannot require module "+"./unity-file-tools.linux-s390x-gnu.node");})();
300
+ } else {
301
+ nativeBinding = (()=>{throw new Error("Cannot require module "+"unity-file-tools-linux-s390x-gnu");})();
302
+ }
303
+ } catch (e) {
304
+ loadError = e;
305
+ }
306
+ break;
307
+ default:
308
+ throw new Error(`Unsupported architecture on Linux: ${arch}`);
309
+ }
310
+ break;
311
+ default:
312
+ throw new Error(`Unsupported OS: ${platform}, architecture: ${arch}`);
313
+ }
314
+ if (!nativeBinding) {
315
+ if (loadError) {
316
+ throw loadError;
317
+ }
318
+ throw new Error(`Failed to load native binding`);
319
+ }
320
+ var { ChunkType, Scanner, Indexer, EmbeddingGenerator, walkProjectFiles, grepProject, buildGuidCache, getVersion, isNativeAvailable } = nativeBinding;
321
+ module2.exports.ChunkType = ChunkType;
322
+ module2.exports.Scanner = Scanner;
323
+ module2.exports.Indexer = Indexer;
324
+ module2.exports.EmbeddingGenerator = EmbeddingGenerator;
325
+ module2.exports.walkProjectFiles = walkProjectFiles;
326
+ module2.exports.grepProject = grepProject;
327
+ module2.exports.buildGuidCache = buildGuidCache;
328
+ module2.exports.getVersion = getVersion;
329
+ module2.exports.isNativeAvailable = isNativeAvailable;
330
+ });
331
+
332
+ // src/index.ts
333
+ var exports_src = {};
334
+ __export(exports_src, {
335
+ walk_project_files: () => walk_project_files,
336
+ setup: () => setup,
337
+ search_project: () => search_project,
338
+ read_settings: () => read_settings,
339
+ isNativeModuleAvailable: () => isNativeModuleAvailable,
340
+ grep_project: () => grep_project,
341
+ getNativeModuleError: () => getNativeModuleError,
342
+ generateGuid: () => generateGuid,
343
+ edit_tag: () => edit_tag,
344
+ edit_sorting_layer: () => edit_sorting_layer,
345
+ edit_settings: () => edit_settings,
346
+ edit_layer: () => edit_layer,
347
+ createScene: () => createScene,
348
+ cleanup: () => cleanup,
349
+ atomicWrite: () => atomicWrite,
350
+ UnityScanner: () => UnityScanner
351
+ });
352
+ module.exports = __toCommonJS(exports_src);
353
+
354
+ // src/scanner.ts
355
+ var import_module = require("module");
356
+ var RustScanner = null;
357
+ var nativeModuleError = null;
358
+ var nativeWalkProjectFiles = null;
359
+ var nativeGrepProject = null;
360
+ var nativeBuildGuidCache = null;
361
+ try {
362
+ const nativeRequire = import_module.createRequire("file:///home/runner/work/unity-agentic-tools/unity-agentic-tools/unity-agentic-tools/src/scanner.ts");
363
+ let rustModule;
364
+ try {
365
+ rustModule = nativeRequire("../native/index.js");
366
+ } catch {
367
+ rustModule = nativeRequire("unity-file-tools");
368
+ }
369
+ RustScanner = rustModule.Scanner;
370
+ nativeWalkProjectFiles = rustModule.walkProjectFiles || null;
371
+ nativeGrepProject = rustModule.grepProject || null;
372
+ nativeBuildGuidCache = rustModule.buildGuidCache || null;
373
+ } catch (err) {
374
+ nativeModuleError = `Failed to load native Rust module.
375
+ ` + `Run: bun install (in the project root)
376
+ ` + `Original error: ${err.message}`;
377
+ }
378
+ function isNativeModuleAvailable() {
379
+ return RustScanner !== null;
380
+ }
381
+ function getNativeModuleError() {
382
+ return nativeModuleError;
383
+ }
384
+
385
+ class UnityScanner {
386
+ scanner;
387
+ constructor() {
388
+ if (!RustScanner) {
389
+ throw new Error(nativeModuleError || "Native module not available");
390
+ }
391
+ this.scanner = new RustScanner;
392
+ }
393
+ setProjectRoot(path) {
394
+ this.scanner.setProjectRoot(path);
395
+ }
396
+ scan_scene_minimal(file) {
397
+ return this.scanner.scanSceneMinimal(file);
398
+ }
399
+ scan_scene_with_components(file, options) {
400
+ return this.scanner.scanSceneWithComponents(file, options);
401
+ }
402
+ find_by_name(file, pattern, fuzzy = true) {
403
+ return this.scanner.findByName(file, pattern, fuzzy);
404
+ }
405
+ inspect(options) {
406
+ return this.scanner.inspect({
407
+ file: options.file,
408
+ identifier: options.identifier,
409
+ includeProperties: options.include_properties,
410
+ verbose: options.verbose
411
+ });
412
+ }
413
+ inspect_all(file, include_properties = false, verbose = false) {
414
+ return this.scanner.inspectAll(file, include_properties, verbose);
415
+ }
416
+ inspect_all_paginated(options) {
417
+ return this.scanner.inspectAllPaginated({
418
+ file: options.file,
419
+ includeProperties: options.include_properties,
420
+ verbose: options.verbose,
421
+ pageSize: options.page_size,
422
+ cursor: options.cursor,
423
+ maxDepth: options.max_depth,
424
+ filterComponent: options.filter_component
425
+ });
426
+ }
427
+ read_asset(file) {
428
+ return this.scanner.readAsset(file);
429
+ }
430
+ }
431
+ function getNativeWalkProjectFiles() {
432
+ return nativeWalkProjectFiles;
433
+ }
434
+ function getNativeGrepProject() {
435
+ return nativeGrepProject;
436
+ }
437
+ function getNativeBuildGuidCache() {
438
+ return nativeBuildGuidCache;
439
+ }
440
+ // src/setup.ts
441
+ var import_fs = require("fs");
442
+ var import_path = require("path");
443
+ var __dirname = "/home/runner/work/unity-agentic-tools/unity-agentic-tools/unity-agentic-tools/src";
444
+ var pkg = JSON.parse(import_fs.readFileSync(import_path.resolve(__dirname, "../package.json"), "utf-8"));
445
+ var VERSION = pkg.version;
446
+ var CONFIG_DIR = ".unity-agentic";
447
+ var CONFIG_FILE = "config.json";
448
+ var GUID_CACHE_FILE = "guid-cache.json";
449
+ var DOC_INDEX_FILE = "doc-index.json";
450
+ function setup(options = {}) {
451
+ const projectPath = import_path.resolve(options.project || process.cwd());
452
+ const assetsPath = import_path.join(projectPath, "Assets");
453
+ if (!import_fs.existsSync(assetsPath)) {
454
+ return {
455
+ success: false,
456
+ project_path: projectPath,
457
+ config_path: "",
458
+ guid_cache_created: false,
459
+ doc_index_created: false,
460
+ error: `Not a Unity project: Assets folder not found at ${assetsPath}`
461
+ };
462
+ }
463
+ const configPath = import_path.join(projectPath, CONFIG_DIR);
464
+ if (!import_fs.existsSync(configPath)) {
465
+ import_fs.mkdirSync(configPath, { recursive: true });
466
+ }
467
+ const config = {
468
+ version: VERSION,
469
+ project_path: projectPath,
470
+ created_at: new Date().toISOString(),
471
+ rust_enabled: isRustAvailable()
472
+ };
473
+ import_fs.writeFileSync(import_path.join(configPath, CONFIG_FILE), JSON.stringify(config, null, 2));
474
+ const guidCache = buildGuidCache(projectPath);
475
+ const guidCachePath = import_path.join(configPath, GUID_CACHE_FILE);
476
+ import_fs.writeFileSync(guidCachePath, JSON.stringify(guidCache, null, 2));
477
+ let docIndexCreated = false;
478
+ if (options.indexDocs) {
479
+ const docIndex = { chunks: {}, last_updated: Date.now() };
480
+ import_fs.writeFileSync(import_path.join(configPath, DOC_INDEX_FILE), JSON.stringify(docIndex, null, 2));
481
+ docIndexCreated = true;
482
+ }
483
+ return {
484
+ success: true,
485
+ project_path: projectPath,
486
+ config_path: configPath,
487
+ guid_cache_created: true,
488
+ doc_index_created: docIndexCreated,
489
+ guid_count: Object.keys(guidCache).length
490
+ };
491
+ }
492
+ function buildGuidCache(projectRoot) {
493
+ const nativeBuild = getNativeBuildGuidCache();
494
+ if (nativeBuild) {
495
+ try {
496
+ return nativeBuild(projectRoot);
497
+ } catch {}
498
+ }
499
+ return buildGuidCacheJs(projectRoot);
500
+ }
501
+ function buildGuidCacheJs(projectRoot) {
502
+ const cache = {};
503
+ const assetsDir = import_path.join(projectRoot, "Assets");
504
+ if (!import_fs.existsSync(assetsDir)) {
505
+ return cache;
506
+ }
507
+ scanMetaFiles(assetsDir, projectRoot, cache);
508
+ return cache;
509
+ }
510
+ function scanMetaFiles(dir, projectRoot, cache) {
511
+ try {
512
+ const entries = import_fs.readdirSync(dir);
513
+ for (const entry of entries) {
514
+ const fullPath = import_path.join(dir, entry);
515
+ const stat = import_fs.statSync(fullPath);
516
+ if (stat.isDirectory()) {
517
+ scanMetaFiles(fullPath, projectRoot, cache);
518
+ } else if (entry.endsWith(".meta")) {
519
+ try {
520
+ const content = import_fs.readFileSync(fullPath, "utf-8");
521
+ const guidMatch = content.match(/^guid:\s*([a-f0-9]{32})/m);
522
+ if (guidMatch) {
523
+ const guid = guidMatch[1];
524
+ const assetPath = fullPath.slice(0, -5);
525
+ const relativePath = import_path.relative(projectRoot, assetPath);
526
+ cache[guid] = relativePath;
527
+ }
528
+ } catch {}
529
+ }
530
+ }
531
+ } catch {}
532
+ }
533
+ function isRustAvailable() {
534
+ try {
535
+ require_rust_core();
536
+ return true;
537
+ } catch {
538
+ return false;
539
+ }
540
+ }
541
+ // src/cleanup.ts
542
+ var import_fs2 = require("fs");
543
+ var import_path2 = require("path");
544
+ var CONFIG_DIR2 = ".unity-agentic";
545
+ var CONFIG_FILE2 = "config.json";
546
+ var GUID_CACHE_FILE2 = "guid-cache.json";
547
+ var DOC_INDEX_FILE2 = "doc-index.json";
548
+ function cleanup(options = {}) {
549
+ const projectPath = import_path2.resolve(options.project || process.cwd());
550
+ const configPath = import_path2.join(projectPath, CONFIG_DIR2);
551
+ if (!import_fs2.existsSync(configPath)) {
552
+ return {
553
+ success: true,
554
+ project_path: projectPath,
555
+ files_removed: [],
556
+ directory_removed: false,
557
+ error: `No ${CONFIG_DIR2} directory found`
558
+ };
559
+ }
560
+ const filesRemoved = [];
561
+ let directoryRemoved = false;
562
+ if (options.all) {
563
+ try {
564
+ removeDirectoryRecursive(configPath);
565
+ directoryRemoved = true;
566
+ filesRemoved.push(CONFIG_DIR2);
567
+ } catch (err) {
568
+ return {
569
+ success: false,
570
+ project_path: projectPath,
571
+ files_removed: filesRemoved,
572
+ directory_removed: false,
573
+ error: `Failed to remove directory: ${err}`
574
+ };
575
+ }
576
+ } else {
577
+ const filesToRemove = [GUID_CACHE_FILE2, DOC_INDEX_FILE2];
578
+ for (const file of filesToRemove) {
579
+ const filePath = import_path2.join(configPath, file);
580
+ if (import_fs2.existsSync(filePath)) {
581
+ try {
582
+ import_fs2.unlinkSync(filePath);
583
+ filesRemoved.push(file);
584
+ } catch {}
585
+ }
586
+ }
587
+ const remaining = import_fs2.readdirSync(configPath);
588
+ if (remaining.length === 0 || remaining.length === 1 && remaining[0] === CONFIG_FILE2) {}
589
+ }
590
+ return {
591
+ success: true,
592
+ project_path: projectPath,
593
+ files_removed: filesRemoved,
594
+ directory_removed: directoryRemoved
595
+ };
596
+ }
597
+ function removeDirectoryRecursive(dir) {
598
+ if (!import_fs2.existsSync(dir)) {
599
+ return;
600
+ }
601
+ const entries = import_fs2.readdirSync(dir, { withFileTypes: true });
602
+ for (const entry of entries) {
603
+ const fullPath = import_path2.join(dir, entry.name);
604
+ if (entry.isDirectory()) {
605
+ removeDirectoryRecursive(fullPath);
606
+ } else {
607
+ import_fs2.unlinkSync(fullPath);
608
+ }
609
+ }
610
+ import_fs2.rmdirSync(dir);
611
+ }
612
+ // src/settings.ts
613
+ var import_fs4 = require("fs");
614
+ var path = __toESM(require("path"));
615
+
616
+ // src/utils.ts
617
+ var import_fs3 = require("fs");
618
+ function atomicWrite(filePath, content) {
619
+ const tmpPath = `${filePath}.tmp`;
620
+ try {
621
+ import_fs3.writeFileSync(tmpPath, content, "utf-8");
622
+ if (import_fs3.existsSync(filePath)) {
623
+ import_fs3.renameSync(filePath, `${filePath}.bak`);
624
+ }
625
+ import_fs3.renameSync(tmpPath, filePath);
626
+ try {
627
+ if (import_fs3.existsSync(`${filePath}.bak`)) {
628
+ import_fs3.unlinkSync(`${filePath}.bak`);
629
+ }
630
+ } catch {}
631
+ return {
632
+ success: true,
633
+ file_path: filePath,
634
+ bytes_written: Buffer.byteLength(content, "utf-8")
635
+ };
636
+ } catch (error) {
637
+ if (import_fs3.existsSync(`${filePath}.bak`)) {
638
+ try {
639
+ import_fs3.renameSync(`${filePath}.bak`, filePath);
640
+ } catch (restoreError) {
641
+ console.error("Failed to restore backup:", restoreError);
642
+ }
643
+ }
644
+ return {
645
+ success: false,
646
+ file_path: filePath,
647
+ error: error instanceof Error ? error.message : String(error)
648
+ };
649
+ }
650
+ }
651
+ function glob_match(pattern, text) {
652
+ if (!pattern.includes("*") && !pattern.includes("?")) {
653
+ return pattern.toLowerCase() === text.toLowerCase();
654
+ }
655
+ const escaped = pattern.replace(/[.+^${}()|[\]\\]/g, "\\$&");
656
+ const regex_str = escaped.replace(/\*/g, ".*").replace(/\?/g, ".");
657
+ return new RegExp(`^${regex_str}$`, "i").test(text);
658
+ }
659
+ function validate_name(name, label) {
660
+ if (name.includes("/")) {
661
+ return `${label} cannot contain forward slashes (/) \u2014 Unity uses them as hierarchy path separators`;
662
+ }
663
+ if (name.includes("\\")) {
664
+ return `${label} cannot contain backslashes (\\)`;
665
+ }
666
+ if (name.includes(`
667
+ `) || name.includes("\r")) {
668
+ return `${label} cannot contain newlines \u2014 they corrupt YAML structure`;
669
+ }
670
+ if (name.includes("\t")) {
671
+ return `${label} cannot contain tab characters \u2014 they break YAML indentation`;
672
+ }
673
+ if (name.includes("\x00")) {
674
+ return `${label} cannot contain null bytes`;
675
+ }
676
+ return null;
677
+ }
678
+ function generateGuid() {
679
+ const hex = "0123456789abcdef";
680
+ let guid = "";
681
+ for (let i = 0;i < 32; i++) {
682
+ guid += hex[Math.floor(Math.random() * 16)];
683
+ }
684
+ return guid;
685
+ }
686
+ function validate_file_path(file_path, operation) {
687
+ if (file_path.startsWith("file://")) {
688
+ return "file:// URIs are not supported. Use file paths directly.";
689
+ }
690
+ const normalized = file_path.replace(/\\/g, "/");
691
+ const isAbsolute = file_path.startsWith("/") || /^[A-Z]:[/\\]/i.test(file_path) || file_path.startsWith("\\\\") || file_path.startsWith("//");
692
+ if (!isAbsolute && (normalized.includes("/../") || normalized.startsWith("../"))) {
693
+ return "Path traversal (..) is not allowed in relative paths for security reasons.";
694
+ }
695
+ if (operation === "write" && !isAbsolute && normalized.startsWith("Packages/")) {
696
+ return "Cannot write to Packages/ directory (read-only in Unity).";
697
+ }
698
+ return null;
699
+ }
700
+
701
+ // src/settings.ts
702
+ function read_setting_file(file_path) {
703
+ return import_fs4.readFileSync(file_path, "utf-8").replace(/\r\n/g, `
704
+ `);
705
+ }
706
+ var SETTING_ALIASES = {
707
+ tags: "TagManager",
708
+ tagmanager: "TagManager",
709
+ physics: "DynamicsManager",
710
+ dynamics: "DynamicsManager",
711
+ dynamicsmanager: "DynamicsManager",
712
+ quality: "QualitySettings",
713
+ qualitysettings: "QualitySettings",
714
+ time: "TimeManager",
715
+ timemanager: "TimeManager",
716
+ input: "InputManager",
717
+ inputmanager: "InputManager",
718
+ audio: "AudioManager",
719
+ audiomanager: "AudioManager",
720
+ editor: "EditorSettings",
721
+ editorsettings: "EditorSettings",
722
+ graphics: "GraphicsSettings",
723
+ graphicssettings: "GraphicsSettings",
724
+ physics2d: "Physics2DSettings",
725
+ physics2dsettings: "Physics2DSettings",
726
+ player: "ProjectSettings",
727
+ project: "ProjectSettings",
728
+ projectsettings: "ProjectSettings",
729
+ navmesh: "NavMeshAreas",
730
+ navmeshareas: "NavMeshAreas"
731
+ };
732
+ function resolve_setting_name(setting) {
733
+ const lower = setting.toLowerCase();
734
+ const resolved = SETTING_ALIASES[lower];
735
+ if (resolved)
736
+ return resolved;
737
+ const canonical = Object.values(SETTING_ALIASES);
738
+ if (canonical.includes(setting))
739
+ return setting;
740
+ return setting;
741
+ }
742
+ function resolve_setting_path(project_path, setting) {
743
+ const canonical = resolve_setting_name(setting);
744
+ return path.join(project_path, "ProjectSettings", `${canonical}.asset`);
745
+ }
746
+ function parse_tag_manager(content) {
747
+ const tags = [];
748
+ const layers = [];
749
+ const sorting_layers = [];
750
+ const tagsMatch = content.match(/tags:\s*\n((?:\s*-\s*.+\n)*)/);
751
+ if (tagsMatch) {
752
+ const tagLines = tagsMatch[1].matchAll(/^\s*-\s*(.+)$/gm);
753
+ for (const m of tagLines) {
754
+ tags.push(m[1].trim());
755
+ }
756
+ }
757
+ const layersMatch = content.match(/layers:\s*\n([\s\S]*?)(?=\s*m_SortingLayers:)/);
758
+ if (layersMatch) {
759
+ const layerLines = layersMatch[1].split(`
760
+ `).filter((l) => l.match(/^\s*-/));
761
+ for (let i = 0;i < layerLines.length; i++) {
762
+ const nameMatch = layerLines[i].match(/^\s*-\s*(.*)$/);
763
+ const name = nameMatch ? nameMatch[1].trim() : "";
764
+ if (name) {
765
+ layers.push({ index: i, name });
766
+ }
767
+ }
768
+ }
769
+ const sortingMatch = content.match(/m_SortingLayers:\s*\n([\s\S]*?)(?=\n[^\s]|\n*$)/);
770
+ if (sortingMatch) {
771
+ const entryPattern = /- name:\s*(.+)\n\s*uniqueID:\s*(\d+)\n\s*locked:\s*(\d+)/g;
772
+ let m;
773
+ while ((m = entryPattern.exec(sortingMatch[1])) !== null) {
774
+ sorting_layers.push({
775
+ name: m[1].trim(),
776
+ unique_id: parseInt(m[2], 10),
777
+ locked: parseInt(m[3], 10)
778
+ });
779
+ }
780
+ }
781
+ return { tags, layers, sorting_layers };
782
+ }
783
+ function parse_dynamics_manager(content) {
784
+ const parse_vector = (str) => {
785
+ const m = str.match(/\{x:\s*([-\d.]+),\s*y:\s*([-\d.]+),\s*z:\s*([-\d.]+)\}/);
786
+ return m ? { x: parseFloat(m[1]), y: parseFloat(m[2]), z: parseFloat(m[3]) } : { x: 0, y: 0, z: 0 };
787
+ };
788
+ const get_float = (key) => {
789
+ const m = content.match(new RegExp(`${key}:\\s*([-\\d.]+)`));
790
+ return m ? parseFloat(m[1]) : 0;
791
+ };
792
+ const get_int = (key) => {
793
+ const m = content.match(new RegExp(`${key}:\\s*(\\d+)`));
794
+ return m ? parseInt(m[1], 10) : 0;
795
+ };
796
+ const gravity_match = content.match(/m_Gravity:\s*(\{[^}]+\})/);
797
+ const gravity = gravity_match ? parse_vector(gravity_match[1]) : { x: 0, y: -9.81, z: 0 };
798
+ return {
799
+ gravity,
800
+ default_contact_offset: get_float("m_DefaultContactOffset"),
801
+ default_solver_iterations: get_int("m_DefaultSolverIterations"),
802
+ default_solver_velocity_iterations: get_int("m_DefaultSolverVelocityIterations"),
803
+ bounce_threshold: get_float("m_BounceThreshold"),
804
+ sleep_threshold: get_float("m_SleepThreshold"),
805
+ queries_hit_triggers: get_int("m_QueriesHitTriggers") === 1,
806
+ auto_simulation: get_int("m_AutoSimulation") === 1
807
+ };
808
+ }
809
+ function parse_quality_settings(content) {
810
+ const current_match = content.match(/m_CurrentQuality:\s*(\d+)/);
811
+ const current_quality = current_match ? parseInt(current_match[1], 10) : 0;
812
+ const quality_levels = [];
813
+ const levels_section = content.match(/m_QualitySettings:\s*\n([\s\S]*?)(?=\n\s*m_PerPlatformDefaultQuality:|\n*$)/);
814
+ if (levels_section) {
815
+ const entries = levels_section[1].split(/\n\s*-\s*serializedVersion:\s*\d+\n/).filter((s) => s.trim());
816
+ for (const entry of entries) {
817
+ const get = (key) => {
818
+ const m = entry.match(new RegExp(`${key}:\\s*(.+)`));
819
+ return m ? m[1].trim() : "";
820
+ };
821
+ const name = get("name");
822
+ if (!name)
823
+ continue;
824
+ quality_levels.push({
825
+ name,
826
+ pixel_light_count: parseInt(get("pixelLightCount") || "0", 10),
827
+ shadows: parseInt(get("shadows") || "0", 10),
828
+ shadow_resolution: parseInt(get("shadowResolution") || "0", 10),
829
+ shadow_distance: parseFloat(get("shadowDistance") || "0"),
830
+ anti_aliasing: parseInt(get("antiAliasing") || "0", 10),
831
+ vsync_count: parseInt(get("vSyncCount") || "0", 10),
832
+ lod_bias: parseFloat(get("lodBias") || "0")
833
+ });
834
+ }
835
+ }
836
+ return { current_quality, quality_levels };
837
+ }
838
+ function parse_time_manager(content) {
839
+ const get_float = (key) => {
840
+ const m = content.match(new RegExp(`${key}:\\s*([-\\d.]+)`));
841
+ return m ? parseFloat(m[1]) : 0;
842
+ };
843
+ return {
844
+ fixed_timestep: get_float("Fixed Timestep"),
845
+ max_timestep: get_float("Maximum Allowed Timestep"),
846
+ time_scale: get_float("m_TimeScale"),
847
+ max_particle_timestep: get_float("Maximum Particle Timestep")
848
+ };
849
+ }
850
+ function parse_generic_asset(content) {
851
+ const result = {};
852
+ const lines = content.split(`
853
+ `);
854
+ for (const line of lines) {
855
+ const match = line.match(/^\s{2}(\w[\w\s]*\w|\w+):\s*(.+)$/);
856
+ if (match) {
857
+ const key = match[1];
858
+ let value = match[2].trim();
859
+ if (/^-?\d+(\.\d+)?$/.test(value)) {
860
+ value = parseFloat(value);
861
+ } else if (value === "0" || value === "1") {
862
+ value = parseInt(value, 10);
863
+ }
864
+ result[key] = value;
865
+ }
866
+ }
867
+ return result;
868
+ }
869
+ function read_settings(options) {
870
+ const { project_path, setting } = options;
871
+ const file_path = resolve_setting_path(project_path, setting);
872
+ if (!import_fs4.existsSync(file_path)) {
873
+ return {
874
+ success: false,
875
+ project_path,
876
+ setting,
877
+ error: `Settings file not found: ${file_path}`
878
+ };
879
+ }
880
+ let content;
881
+ try {
882
+ content = read_setting_file(file_path);
883
+ } catch (err) {
884
+ return {
885
+ success: false,
886
+ project_path,
887
+ setting,
888
+ error: `Failed to read settings file: ${err instanceof Error ? err.message : String(err)}`
889
+ };
890
+ }
891
+ const canonical = resolve_setting_name(setting);
892
+ let data;
893
+ switch (canonical) {
894
+ case "TagManager":
895
+ data = parse_tag_manager(content);
896
+ break;
897
+ case "DynamicsManager":
898
+ data = parse_dynamics_manager(content);
899
+ break;
900
+ case "QualitySettings":
901
+ data = parse_quality_settings(content);
902
+ break;
903
+ case "TimeManager":
904
+ data = parse_time_manager(content);
905
+ break;
906
+ default:
907
+ data = parse_generic_asset(content);
908
+ break;
909
+ }
910
+ return {
911
+ success: true,
912
+ project_path,
913
+ setting: canonical,
914
+ file_path,
915
+ data
916
+ };
917
+ }
918
+ function edit_settings(options) {
919
+ const { project_path, setting, property, value } = options;
920
+ const file_path = resolve_setting_path(project_path, setting);
921
+ if (!import_fs4.existsSync(file_path)) {
922
+ return {
923
+ success: false,
924
+ project_path,
925
+ setting,
926
+ error: `Settings file not found: ${file_path}`
927
+ };
928
+ }
929
+ let content;
930
+ try {
931
+ content = read_setting_file(file_path);
932
+ } catch (err) {
933
+ return {
934
+ success: false,
935
+ project_path,
936
+ setting,
937
+ error: `Failed to read settings file: ${err instanceof Error ? err.message : String(err)}`
938
+ };
939
+ }
940
+ const propPattern = new RegExp(`(^\\s*${property}:\\s*)(.*)$`, "m");
941
+ if (propPattern.test(content)) {
942
+ content = content.replace(propPattern, `$1${value}`);
943
+ } else {
944
+ const prefixedPattern = new RegExp(`(^\\s*m_${property}:\\s*)(.*)$`, "m");
945
+ if (prefixedPattern.test(content)) {
946
+ content = content.replace(prefixedPattern, `$1${value}`);
947
+ } else {
948
+ const pascal = property.replace(/(^|_)([a-z])/g, (_, __, c) => c.toUpperCase());
949
+ const pascalPattern = new RegExp(`(^\\s*m_${pascal}:\\s*)(.*)$`, "m");
950
+ if (pascalPattern.test(content)) {
951
+ content = content.replace(pascalPattern, `$1${value}`);
952
+ } else {
953
+ const spacedName = property.replace(/_/g, " ").replace(/(^| )([a-z])/g, (_, sp, c) => sp + c.toUpperCase());
954
+ const spacedPattern = new RegExp(`(^\\s*${spacedName}:\\s*)(.*)$`, "m");
955
+ if (spacedPattern.test(content)) {
956
+ content = content.replace(spacedPattern, `$1${value}`);
957
+ } else {
958
+ return {
959
+ success: false,
960
+ project_path,
961
+ setting,
962
+ error: `Property "${property}" not found in ${setting}`
963
+ };
964
+ }
965
+ }
966
+ }
967
+ }
968
+ const result = atomicWrite(file_path, content);
969
+ if (!result.success) {
970
+ return {
971
+ success: false,
972
+ project_path,
973
+ setting,
974
+ error: result.error
975
+ };
976
+ }
977
+ return {
978
+ success: true,
979
+ project_path,
980
+ setting: resolve_setting_name(setting),
981
+ file_path,
982
+ bytes_written: result.bytes_written
983
+ };
984
+ }
985
+ function edit_tag(options) {
986
+ const { project_path, action, tag } = options;
987
+ if (!tag || !tag.trim()) {
988
+ return {
989
+ success: false,
990
+ project_path,
991
+ setting: "TagManager",
992
+ error: "Tag name cannot be empty"
993
+ };
994
+ }
995
+ const nameError = validate_name(tag, "Tag name");
996
+ if (nameError) {
997
+ return {
998
+ success: false,
999
+ project_path,
1000
+ setting: "TagManager",
1001
+ error: nameError
1002
+ };
1003
+ }
1004
+ const file_path = resolve_setting_path(project_path, "TagManager");
1005
+ if (!import_fs4.existsSync(file_path)) {
1006
+ return {
1007
+ success: false,
1008
+ project_path,
1009
+ setting: "TagManager",
1010
+ error: `TagManager not found: ${file_path}`
1011
+ };
1012
+ }
1013
+ let content;
1014
+ try {
1015
+ content = read_setting_file(file_path);
1016
+ } catch (err) {
1017
+ return {
1018
+ success: false,
1019
+ project_path,
1020
+ setting: "TagManager",
1021
+ error: `Failed to read TagManager: ${err instanceof Error ? err.message : String(err)}`
1022
+ };
1023
+ }
1024
+ if (action === "add") {
1025
+ const existing = parse_tag_manager(content);
1026
+ if (existing.tags.includes(tag)) {
1027
+ return {
1028
+ success: false,
1029
+ project_path,
1030
+ setting: "TagManager",
1031
+ error: `Tag "${tag}" already exists`
1032
+ };
1033
+ }
1034
+ content = content.replace(/(tags:\s*\n(?:\s*-\s*.+\n)*)/, `$1 - ${tag}
1035
+ `);
1036
+ } else {
1037
+ const tagPattern = new RegExp(`^\\s*-\\s*${tag.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}\\s*$\\n?`, "m");
1038
+ if (!tagPattern.test(content)) {
1039
+ return {
1040
+ success: false,
1041
+ project_path,
1042
+ setting: "TagManager",
1043
+ error: `Tag "${tag}" not found`
1044
+ };
1045
+ }
1046
+ content = content.replace(tagPattern, "");
1047
+ }
1048
+ const result = atomicWrite(file_path, content);
1049
+ if (!result.success) {
1050
+ return {
1051
+ success: false,
1052
+ project_path,
1053
+ setting: "TagManager",
1054
+ error: result.error
1055
+ };
1056
+ }
1057
+ return {
1058
+ success: true,
1059
+ project_path,
1060
+ setting: "TagManager",
1061
+ file_path,
1062
+ bytes_written: result.bytes_written
1063
+ };
1064
+ }
1065
+ function edit_layer(options) {
1066
+ const { project_path, index, name } = options;
1067
+ const file_path = resolve_setting_path(project_path, "TagManager");
1068
+ if (!import_fs4.existsSync(file_path)) {
1069
+ return {
1070
+ success: false,
1071
+ project_path,
1072
+ setting: "TagManager",
1073
+ error: `TagManager not found: ${file_path}`
1074
+ };
1075
+ }
1076
+ const RESERVED_LAYERS = {
1077
+ 0: "Default",
1078
+ 1: "TransparentFX",
1079
+ 2: "Ignore Raycast",
1080
+ 4: "Water",
1081
+ 5: "UI"
1082
+ };
1083
+ if (index < 0 || index > 31) {
1084
+ return {
1085
+ success: false,
1086
+ project_path,
1087
+ setting: "TagManager",
1088
+ error: `Layer index must be between 0 and 31`
1089
+ };
1090
+ }
1091
+ if (RESERVED_LAYERS[index]) {
1092
+ return {
1093
+ success: false,
1094
+ project_path,
1095
+ setting: "TagManager",
1096
+ error: `Cannot modify reserved layer "${RESERVED_LAYERS[index]}" at index ${index}`
1097
+ };
1098
+ }
1099
+ const nameError = validate_name(name, "Layer name");
1100
+ if (nameError) {
1101
+ return {
1102
+ success: false,
1103
+ project_path,
1104
+ setting: "TagManager",
1105
+ error: nameError
1106
+ };
1107
+ }
1108
+ let content;
1109
+ try {
1110
+ content = read_setting_file(file_path);
1111
+ } catch (err) {
1112
+ return {
1113
+ success: false,
1114
+ project_path,
1115
+ setting: "TagManager",
1116
+ error: `Failed to read TagManager: ${err instanceof Error ? err.message : String(err)}`
1117
+ };
1118
+ }
1119
+ const layersMatch = content.match(/(layers:\s*\n)([\s\S]*?)(?=\s*m_SortingLayers:)/);
1120
+ if (!layersMatch) {
1121
+ return {
1122
+ success: false,
1123
+ project_path,
1124
+ setting: "TagManager",
1125
+ error: "Could not find layers section in TagManager"
1126
+ };
1127
+ }
1128
+ const layerLines = layersMatch[2].split(`
1129
+ `).filter((l) => l.match(/^\s*-/));
1130
+ if (index >= layerLines.length) {
1131
+ return {
1132
+ success: false,
1133
+ project_path,
1134
+ setting: "TagManager",
1135
+ error: `Layer index ${index} is out of range (file has ${layerLines.length} layers)`
1136
+ };
1137
+ }
1138
+ layerLines[index] = ` - ${name}`;
1139
+ const newLayersSection = layerLines.join(`
1140
+ `) + `
1141
+ `;
1142
+ content = content.replace(layersMatch[2], newLayersSection);
1143
+ const result = atomicWrite(file_path, content);
1144
+ if (!result.success) {
1145
+ return {
1146
+ success: false,
1147
+ project_path,
1148
+ setting: "TagManager",
1149
+ error: result.error
1150
+ };
1151
+ }
1152
+ return {
1153
+ success: true,
1154
+ project_path,
1155
+ setting: "TagManager",
1156
+ file_path,
1157
+ bytes_written: result.bytes_written
1158
+ };
1159
+ }
1160
+ function edit_sorting_layer(options) {
1161
+ const { project_path, action, name } = options;
1162
+ if (!name || !name.trim()) {
1163
+ return {
1164
+ success: false,
1165
+ project_path,
1166
+ setting: "TagManager",
1167
+ error: "Sorting layer name cannot be empty"
1168
+ };
1169
+ }
1170
+ const file_path = resolve_setting_path(project_path, "TagManager");
1171
+ if (!import_fs4.existsSync(file_path)) {
1172
+ return {
1173
+ success: false,
1174
+ project_path,
1175
+ setting: "TagManager",
1176
+ error: `TagManager not found: ${file_path}`
1177
+ };
1178
+ }
1179
+ let content;
1180
+ try {
1181
+ content = read_setting_file(file_path);
1182
+ } catch (err) {
1183
+ return {
1184
+ success: false,
1185
+ project_path,
1186
+ setting: "TagManager",
1187
+ error: `Failed to read TagManager: ${err instanceof Error ? err.message : String(err)}`
1188
+ };
1189
+ }
1190
+ if (action === "remove" && name === "Default") {
1191
+ return {
1192
+ success: false,
1193
+ project_path,
1194
+ setting: "TagManager",
1195
+ error: "Cannot remove the Default sorting layer \u2014 it is required by Unity"
1196
+ };
1197
+ }
1198
+ if (action === "add") {
1199
+ const existing = parse_tag_manager(content);
1200
+ if (existing.sorting_layers.some((sl) => sl.name === name)) {
1201
+ return {
1202
+ success: false,
1203
+ project_path,
1204
+ setting: "TagManager",
1205
+ error: `Sorting layer "${name}" already exists`
1206
+ };
1207
+ }
1208
+ const unique_id = Math.floor(Math.random() * 4294967295);
1209
+ const newEntry = ` - name: ${name}
1210
+ uniqueID: ${unique_id}
1211
+ locked: 0
1212
+ `;
1213
+ const sortingEnd = content.match(/(m_SortingLayers:\s*\n(?:\s+-\s+name:[\s\S]*?(?=\n[^\s]|\n*$)))/);
1214
+ if (sortingEnd) {
1215
+ content = content.replace(sortingEnd[1], sortingEnd[1] + newEntry);
1216
+ } else {
1217
+ content = content.trimEnd() + `
1218
+ ` + newEntry;
1219
+ }
1220
+ } else {
1221
+ const escapedName = name.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
1222
+ const slPattern = new RegExp(`\\s*-\\s*name:\\s*${escapedName}\\n\\s*uniqueID:\\s*\\d+\\n\\s*locked:\\s*\\d+\\n?`, "m");
1223
+ if (!slPattern.test(content)) {
1224
+ return {
1225
+ success: false,
1226
+ project_path,
1227
+ setting: "TagManager",
1228
+ error: `Sorting layer "${name}" not found`
1229
+ };
1230
+ }
1231
+ content = content.replace(slPattern, `
1232
+ `);
1233
+ }
1234
+ const result = atomicWrite(file_path, content);
1235
+ if (!result.success) {
1236
+ return {
1237
+ success: false,
1238
+ project_path,
1239
+ setting: "TagManager",
1240
+ error: result.error
1241
+ };
1242
+ }
1243
+ return {
1244
+ success: true,
1245
+ project_path,
1246
+ setting: "TagManager",
1247
+ file_path,
1248
+ bytes_written: result.bytes_written
1249
+ };
1250
+ }
1251
+ // src/project-search.ts
1252
+ var import_fs5 = require("fs");
1253
+ var path2 = __toESM(require("path"));
1254
+ var BINARY_EXTENSIONS = new Set([
1255
+ ".png",
1256
+ ".jpg",
1257
+ ".jpeg",
1258
+ ".gif",
1259
+ ".bmp",
1260
+ ".tga",
1261
+ ".psd",
1262
+ ".tif",
1263
+ ".tiff",
1264
+ ".fbx",
1265
+ ".obj",
1266
+ ".dae",
1267
+ ".blend",
1268
+ ".3ds",
1269
+ ".max",
1270
+ ".dll",
1271
+ ".so",
1272
+ ".dylib",
1273
+ ".exe",
1274
+ ".a",
1275
+ ".lib",
1276
+ ".mp3",
1277
+ ".wav",
1278
+ ".ogg",
1279
+ ".aif",
1280
+ ".aiff",
1281
+ ".mp4",
1282
+ ".mov",
1283
+ ".avi",
1284
+ ".wmv",
1285
+ ".zip",
1286
+ ".gz",
1287
+ ".tar",
1288
+ ".rar",
1289
+ ".7z",
1290
+ ".ttf",
1291
+ ".otf",
1292
+ ".woff",
1293
+ ".woff2",
1294
+ ".bank",
1295
+ ".bytes",
1296
+ ".db"
1297
+ ]);
1298
+ var SKIP_DIRS = new Set(["Library", "Temp", "obj", "Logs", ".git", ".unity-agentic", "node_modules"]);
1299
+ function walk_project_files(project_path, extensions, exclude_dirs) {
1300
+ const nativeWalk = getNativeWalkProjectFiles();
1301
+ if (nativeWalk) {
1302
+ try {
1303
+ return nativeWalk(project_path, extensions, exclude_dirs ?? null);
1304
+ } catch {}
1305
+ }
1306
+ return walk_project_files_js(project_path, extensions, exclude_dirs);
1307
+ }
1308
+ function walk_project_files_js(project_path, extensions, exclude_dirs) {
1309
+ const result = [];
1310
+ const skipSet = new Set([...SKIP_DIRS, ...exclude_dirs || []]);
1311
+ const extSet = new Set(extensions.map((e) => e.startsWith(".") ? e : `.${e}`));
1312
+ function walk(dir) {
1313
+ let entries;
1314
+ try {
1315
+ entries = import_fs5.readdirSync(dir);
1316
+ } catch {
1317
+ return;
1318
+ }
1319
+ for (const entry of entries) {
1320
+ const full = path2.join(dir, entry);
1321
+ let stat;
1322
+ try {
1323
+ stat = import_fs5.statSync(full);
1324
+ } catch {
1325
+ continue;
1326
+ }
1327
+ if (stat.isDirectory()) {
1328
+ if (!skipSet.has(entry)) {
1329
+ walk(full);
1330
+ }
1331
+ } else if (stat.isFile()) {
1332
+ const ext = path2.extname(entry).toLowerCase();
1333
+ if (extSet.has(ext)) {
1334
+ result.push(full);
1335
+ }
1336
+ }
1337
+ }
1338
+ }
1339
+ const assetsDir = path2.join(project_path, "Assets");
1340
+ if (import_fs5.existsSync(assetsDir)) {
1341
+ walk(assetsDir);
1342
+ }
1343
+ if (extSet.has(".asset")) {
1344
+ const settingsDir = path2.join(project_path, "ProjectSettings");
1345
+ if (import_fs5.existsSync(settingsDir)) {
1346
+ walk(settingsDir);
1347
+ }
1348
+ }
1349
+ return result;
1350
+ }
1351
+ function search_project(options) {
1352
+ const {
1353
+ project_path,
1354
+ name,
1355
+ exact = false,
1356
+ component,
1357
+ tag,
1358
+ layer,
1359
+ file_type = "all",
1360
+ max_matches
1361
+ } = options;
1362
+ if (max_matches !== undefined && max_matches < 1) {
1363
+ return {
1364
+ success: false,
1365
+ project_path,
1366
+ total_files_scanned: 0,
1367
+ total_matches: 0,
1368
+ cursor: 0,
1369
+ truncated: false,
1370
+ matches: [],
1371
+ error: "--max-matches must be a positive integer (>= 1)"
1372
+ };
1373
+ }
1374
+ if (name !== undefined && name.trim() === "") {
1375
+ return {
1376
+ success: false,
1377
+ project_path,
1378
+ total_files_scanned: 0,
1379
+ total_matches: 0,
1380
+ cursor: 0,
1381
+ truncated: false,
1382
+ matches: [],
1383
+ error: "Name pattern must not be empty"
1384
+ };
1385
+ }
1386
+ if (!import_fs5.existsSync(project_path)) {
1387
+ return {
1388
+ success: false,
1389
+ project_path,
1390
+ total_files_scanned: 0,
1391
+ total_matches: 0,
1392
+ cursor: 0,
1393
+ truncated: false,
1394
+ matches: [],
1395
+ error: `Project path not found: ${project_path}`
1396
+ };
1397
+ }
1398
+ if (!isNativeModuleAvailable()) {
1399
+ return {
1400
+ success: false,
1401
+ project_path,
1402
+ total_files_scanned: 0,
1403
+ total_matches: 0,
1404
+ cursor: 0,
1405
+ truncated: false,
1406
+ matches: [],
1407
+ error: "Native scanner module not available. Run bun install in the project root."
1408
+ };
1409
+ }
1410
+ const extensions = [];
1411
+ if (file_type === "scene" || file_type === "all")
1412
+ extensions.push(".unity");
1413
+ if (file_type === "prefab" || file_type === "all")
1414
+ extensions.push(".prefab");
1415
+ const files = walk_project_files(project_path, extensions);
1416
+ const scanner = new UnityScanner;
1417
+ const matches = [];
1418
+ for (const file of files) {
1419
+ try {
1420
+ let gameObjects;
1421
+ const needFullData = !!(component || tag || layer !== undefined);
1422
+ if (name && !needFullData) {
1423
+ gameObjects = scanner.find_by_name(file, name, !exact);
1424
+ } else if (needFullData) {
1425
+ gameObjects = scanner.scan_scene_with_components(file);
1426
+ if (name) {
1427
+ const nameLower = name.toLowerCase();
1428
+ const hasWildcard = name.includes("*") || name.includes("?");
1429
+ gameObjects = gameObjects.filter((go) => {
1430
+ if (!go.name)
1431
+ return false;
1432
+ if (hasWildcard) {
1433
+ return glob_match(name, go.name);
1434
+ }
1435
+ if (exact) {
1436
+ return go.name === name;
1437
+ }
1438
+ return go.name.toLowerCase().includes(nameLower);
1439
+ });
1440
+ }
1441
+ } else {
1442
+ gameObjects = scanner.scan_scene_minimal(file);
1443
+ }
1444
+ for (const go of gameObjects) {
1445
+ const isFindResult = "resultType" in go;
1446
+ const isPrefab = isFindResult && go.resultType === "PrefabInstance";
1447
+ if (isPrefab && (component || tag || layer !== undefined)) {
1448
+ continue;
1449
+ }
1450
+ if (component) {
1451
+ if ("components" in go && go.components) {
1452
+ const hasComponent = go.components.some((c) => glob_match(component, c.type));
1453
+ if (!hasComponent)
1454
+ continue;
1455
+ } else {
1456
+ continue;
1457
+ }
1458
+ }
1459
+ if (tag) {
1460
+ if (!("tag" in go) || go.tag !== tag)
1461
+ continue;
1462
+ }
1463
+ if (layer !== undefined) {
1464
+ if (!("layer" in go) || go.layer !== layer)
1465
+ continue;
1466
+ }
1467
+ const relPath = path2.relative(project_path, file);
1468
+ const fileId = isFindResult ? go.fileId : go.file_id;
1469
+ const match = {
1470
+ file: relPath,
1471
+ game_object: go.name,
1472
+ file_id: fileId,
1473
+ tag: "tag" in go ? go.tag : undefined,
1474
+ layer: "layer" in go ? go.layer : undefined
1475
+ };
1476
+ if ("components" in go && go.components) {
1477
+ match.components = go.components.map((c) => c.type);
1478
+ }
1479
+ matches.push(match);
1480
+ if (max_matches !== undefined && matches.length >= max_matches)
1481
+ break;
1482
+ }
1483
+ if (max_matches !== undefined && matches.length >= max_matches)
1484
+ break;
1485
+ } catch {
1486
+ continue;
1487
+ }
1488
+ }
1489
+ return {
1490
+ success: true,
1491
+ project_path,
1492
+ total_files_scanned: files.length,
1493
+ total_matches: matches.length,
1494
+ cursor: 0,
1495
+ truncated: max_matches !== undefined && matches.length >= max_matches,
1496
+ matches
1497
+ };
1498
+ }
1499
+ function grep_project(options) {
1500
+ const nativeGrep = getNativeGrepProject();
1501
+ if (nativeGrep) {
1502
+ try {
1503
+ const nativeResult = nativeGrep({
1504
+ projectPath: options.project_path,
1505
+ pattern: options.pattern,
1506
+ fileType: options.file_type,
1507
+ maxResults: options.max_results,
1508
+ contextLines: options.context_lines
1509
+ });
1510
+ return {
1511
+ success: nativeResult.success,
1512
+ project_path: nativeResult.projectPath,
1513
+ pattern: nativeResult.pattern,
1514
+ total_files_scanned: nativeResult.totalFilesScanned,
1515
+ total_matches: nativeResult.totalMatches,
1516
+ truncated: nativeResult.truncated,
1517
+ error: nativeResult.error,
1518
+ matches: nativeResult.matches.map((m) => ({
1519
+ file: m.file,
1520
+ line_number: m.lineNumber,
1521
+ line: m.line,
1522
+ context_before: m.contextBefore,
1523
+ context_after: m.contextAfter
1524
+ }))
1525
+ };
1526
+ } catch {}
1527
+ }
1528
+ return grep_project_js(options);
1529
+ }
1530
+ function grep_project_js(options) {
1531
+ const {
1532
+ project_path,
1533
+ pattern,
1534
+ file_type = "all",
1535
+ max_results = 100,
1536
+ context_lines = 0
1537
+ } = options;
1538
+ if (!import_fs5.existsSync(project_path)) {
1539
+ return {
1540
+ success: false,
1541
+ project_path,
1542
+ pattern,
1543
+ total_files_scanned: 0,
1544
+ total_matches: 0,
1545
+ truncated: false,
1546
+ matches: [],
1547
+ error: `Project path not found: ${project_path}`
1548
+ };
1549
+ }
1550
+ let regex;
1551
+ try {
1552
+ regex = new RegExp(pattern, "i");
1553
+ } catch (err) {
1554
+ return {
1555
+ success: false,
1556
+ project_path,
1557
+ pattern,
1558
+ total_files_scanned: 0,
1559
+ total_matches: 0,
1560
+ truncated: false,
1561
+ matches: [],
1562
+ error: `Invalid regex pattern: ${err instanceof Error ? err.message : String(err)}`
1563
+ };
1564
+ }
1565
+ const EXTENSION_MAP = {
1566
+ cs: [".cs"],
1567
+ yaml: [".yaml", ".yml", ".unity", ".prefab", ".asset"],
1568
+ unity: [".unity"],
1569
+ prefab: [".prefab"],
1570
+ asset: [".asset"],
1571
+ all: [".cs", ".unity", ".prefab", ".asset", ".yaml", ".yml", ".txt", ".json", ".xml", ".shader", ".cginc", ".hlsl", ".compute", ".asmdef", ".asmref"]
1572
+ };
1573
+ const extensions = EXTENSION_MAP[file_type] || EXTENSION_MAP.all;
1574
+ const files = walk_project_files(project_path, extensions);
1575
+ const matches = [];
1576
+ let totalFilesScanned = 0;
1577
+ let truncated = false;
1578
+ for (const file of files) {
1579
+ const ext = path2.extname(file).toLowerCase();
1580
+ if (BINARY_EXTENSIONS.has(ext))
1581
+ continue;
1582
+ totalFilesScanned++;
1583
+ let content;
1584
+ try {
1585
+ content = import_fs5.readFileSync(file, "utf-8");
1586
+ } catch {
1587
+ continue;
1588
+ }
1589
+ const lines = content.split(`
1590
+ `);
1591
+ const relPath = path2.relative(project_path, file);
1592
+ for (let i = 0;i < lines.length; i++) {
1593
+ if (regex.test(lines[i])) {
1594
+ let line = lines[i];
1595
+ if (line.length > 200) {
1596
+ line = line.substring(0, 200) + "...";
1597
+ }
1598
+ const match = {
1599
+ file: relPath,
1600
+ line_number: i + 1,
1601
+ line
1602
+ };
1603
+ if (context_lines > 0) {
1604
+ match.context_before = [];
1605
+ match.context_after = [];
1606
+ for (let j = Math.max(0, i - context_lines);j < i; j++) {
1607
+ let ctxLine = lines[j];
1608
+ if (ctxLine.length > 200)
1609
+ ctxLine = ctxLine.substring(0, 200) + "...";
1610
+ match.context_before.push(ctxLine);
1611
+ }
1612
+ for (let j = i + 1;j <= Math.min(lines.length - 1, i + context_lines); j++) {
1613
+ let ctxLine = lines[j];
1614
+ if (ctxLine.length > 200)
1615
+ ctxLine = ctxLine.substring(0, 200) + "...";
1616
+ match.context_after.push(ctxLine);
1617
+ }
1618
+ }
1619
+ matches.push(match);
1620
+ if (matches.length >= max_results) {
1621
+ truncated = true;
1622
+ break;
1623
+ }
1624
+ }
1625
+ }
1626
+ if (truncated)
1627
+ break;
1628
+ }
1629
+ return {
1630
+ success: true,
1631
+ project_path,
1632
+ pattern,
1633
+ total_files_scanned: totalFilesScanned,
1634
+ total_matches: matches.length,
1635
+ truncated,
1636
+ matches
1637
+ };
1638
+ }
1639
+ // src/editor/create.ts
1640
+ var import_fs6 = require("fs");
1641
+
1642
+ // src/class-ids.ts
1643
+ var UNITY_CLASS_IDS = {
1644
+ 1: "GameObject",
1645
+ 2: "Component",
1646
+ 3: "LevelGameManager",
1647
+ 4: "Transform",
1648
+ 5: "TimeManager",
1649
+ 6: "GlobalGameManager",
1650
+ 8: "Behaviour",
1651
+ 9: "GameManager",
1652
+ 11: "AudioManager",
1653
+ 13: "InputManager",
1654
+ 18: "EditorExtension",
1655
+ 19: "Physics2DSettings",
1656
+ 20: "Camera",
1657
+ 21: "Material",
1658
+ 23: "MeshRenderer",
1659
+ 25: "Renderer",
1660
+ 27: "Texture",
1661
+ 28: "Texture2D",
1662
+ 29: "OcclusionCullingSettings",
1663
+ 30: "GraphicsSettings",
1664
+ 33: "MeshFilter",
1665
+ 41: "OcclusionPortal",
1666
+ 43: "Mesh",
1667
+ 45: "Skybox",
1668
+ 47: "QualitySettings",
1669
+ 48: "Shader",
1670
+ 49: "TextAsset",
1671
+ 50: "Rigidbody2D",
1672
+ 53: "Collider2D",
1673
+ 54: "Rigidbody",
1674
+ 55: "PhysicsManager",
1675
+ 56: "Collider",
1676
+ 57: "Joint",
1677
+ 58: "CircleCollider2D",
1678
+ 59: "HingeJoint",
1679
+ 60: "PolygonCollider2D",
1680
+ 61: "BoxCollider2D",
1681
+ 62: "PhysicsMaterial2D",
1682
+ 64: "MeshCollider",
1683
+ 65: "BoxCollider",
1684
+ 66: "CompositeCollider2D",
1685
+ 68: "EdgeCollider2D",
1686
+ 70: "CapsuleCollider2D",
1687
+ 72: "ComputeShader",
1688
+ 74: "AnimationClip",
1689
+ 75: "ConstantForce",
1690
+ 78: "TagManager",
1691
+ 81: "AudioListener",
1692
+ 82: "AudioSource",
1693
+ 83: "AudioClip",
1694
+ 84: "RenderTexture",
1695
+ 86: "CustomRenderTexture",
1696
+ 89: "Cubemap",
1697
+ 90: "Avatar",
1698
+ 91: "AnimatorController",
1699
+ 93: "RuntimeAnimatorController",
1700
+ 94: "ScriptMapper",
1701
+ 95: "Animator",
1702
+ 96: "TrailRenderer",
1703
+ 98: "DelayedCallManager",
1704
+ 102: "TextMesh",
1705
+ 104: "RenderSettings",
1706
+ 108: "Light",
1707
+ 109: "CGProgram",
1708
+ 110: "BaseAnimationTrack",
1709
+ 111: "Animation",
1710
+ 114: "MonoBehaviour",
1711
+ 115: "MonoScript",
1712
+ 117: "Texture3D",
1713
+ 119: "NewAnimationTrack",
1714
+ 120: "Projector",
1715
+ 121: "LineRenderer",
1716
+ 122: "Flare",
1717
+ 123: "Halo",
1718
+ 124: "LensFlare",
1719
+ 125: "FlareLayer",
1720
+ 126: "HaloLayer",
1721
+ 127: "NavMeshProjectSettings",
1722
+ 128: "Font",
1723
+ 129: "PlayerSettings",
1724
+ 130: "NamedObject",
1725
+ 134: "PhysicMaterial",
1726
+ 135: "SphereCollider",
1727
+ 136: "CapsuleCollider",
1728
+ 137: "SkinnedMeshRenderer",
1729
+ 138: "FixedJoint",
1730
+ 141: "BuildSettings",
1731
+ 142: "AssetBundle",
1732
+ 143: "CharacterController",
1733
+ 144: "CharacterJoint",
1734
+ 145: "SpringJoint",
1735
+ 146: "WheelCollider",
1736
+ 147: "ResourceManager",
1737
+ 150: "PreloadData",
1738
+ 153: "ConfigurableJoint",
1739
+ 154: "TerrainCollider",
1740
+ 156: "TerrainData",
1741
+ 157: "LightmapSettings",
1742
+ 158: "WebCamTexture",
1743
+ 159: "EditorSettings",
1744
+ 162: "EditorUserSettings",
1745
+ 164: "AudioReverbFilter",
1746
+ 165: "AudioHighPassFilter",
1747
+ 166: "AudioChorusFilter",
1748
+ 167: "AudioReverbZone",
1749
+ 168: "AudioEchoFilter",
1750
+ 169: "AudioLowPassFilter",
1751
+ 170: "AudioDistortionFilter",
1752
+ 171: "SparseTexture",
1753
+ 180: "AudioBehaviour",
1754
+ 181: "AudioFilter",
1755
+ 182: "WindZone",
1756
+ 183: "Cloth",
1757
+ 184: "SubstanceArchive",
1758
+ 185: "ProceduralMaterial",
1759
+ 186: "ProceduralTexture",
1760
+ 187: "Texture2DArray",
1761
+ 188: "CubemapArray",
1762
+ 191: "OffMeshLink",
1763
+ 192: "OcclusionArea",
1764
+ 193: "Tree",
1765
+ 195: "NavMeshAgent",
1766
+ 196: "NavMeshSettings",
1767
+ 198: "ParticleSystem",
1768
+ 199: "ParticleSystemRenderer",
1769
+ 200: "ShaderVariantCollection",
1770
+ 205: "LODGroup",
1771
+ 206: "BlendTree",
1772
+ 207: "Motion",
1773
+ 208: "NavMeshObstacle",
1774
+ 210: "SortingGroup",
1775
+ 212: "SpriteRenderer",
1776
+ 213: "Sprite",
1777
+ 214: "CachedSpriteAtlas",
1778
+ 215: "ReflectionProbe",
1779
+ 218: "Terrain",
1780
+ 220: "LightProbeGroup",
1781
+ 221: "AnimatorOverrideController",
1782
+ 222: "CanvasRenderer",
1783
+ 223: "Canvas",
1784
+ 224: "RectTransform",
1785
+ 225: "CanvasGroup",
1786
+ 226: "BillboardAsset",
1787
+ 227: "BillboardRenderer",
1788
+ 228: "SpeedTreeWindAsset",
1789
+ 229: "AnchoredJoint2D",
1790
+ 230: "Joint2D",
1791
+ 231: "SpringJoint2D",
1792
+ 232: "DistanceJoint2D",
1793
+ 233: "HingeJoint2D",
1794
+ 234: "SliderJoint2D",
1795
+ 235: "WheelJoint2D",
1796
+ 236: "ClusterInputManager",
1797
+ 237: "BaseVideoTexture",
1798
+ 238: "NavMeshData",
1799
+ 240: "AudioMixer",
1800
+ 241: "AudioMixerController",
1801
+ 243: "AudioMixerGroupController",
1802
+ 244: "AudioMixerEffectController",
1803
+ 245: "AudioMixerSnapshotController",
1804
+ 246: "PhysicsUpdateBehaviour2D",
1805
+ 247: "ConstantForce2D",
1806
+ 248: "Effector2D",
1807
+ 249: "AreaEffector2D",
1808
+ 250: "PointEffector2D",
1809
+ 251: "PlatformEffector2D",
1810
+ 252: "SurfaceEffector2D",
1811
+ 253: "BuoyancyEffector2D",
1812
+ 254: "RelativeJoint2D",
1813
+ 255: "FixedJoint2D",
1814
+ 256: "FrictionJoint2D",
1815
+ 257: "TargetJoint2D",
1816
+ 258: "LightProbes",
1817
+ 259: "LightProbeProxyVolume",
1818
+ 260: "SampleClip",
1819
+ 261: "AudioMixerSnapshot",
1820
+ 262: "AudioMixerGroup",
1821
+ 265: "NScreenBridge",
1822
+ 271: "AssetBundleManifest",
1823
+ 272: "UnityAdsManager",
1824
+ 273: "RuntimeInitializeOnLoadManager",
1825
+ 280: "UnityConnectSettings",
1826
+ 281: "AvatarMask",
1827
+ 290: "PlayableDirector",
1828
+ 292: "VideoPlayer",
1829
+ 293: "VideoClip",
1830
+ 294: "ParticleSystemForceField",
1831
+ 298: "SpriteMask",
1832
+ 300: "WorldAnchor",
1833
+ 301: "OcclusionCullingData",
1834
+ 310: "PrefabInstance",
1835
+ 319: "TextureImporter",
1836
+ 363: "Preset",
1837
+ 687078895: "SpriteAtlas",
1838
+ 1839735485: "Tilemap",
1839
+ 1839735486: "TilemapCollider2D",
1840
+ 1839735487: "TilemapRenderer"
1841
+ };
1842
+ var UNITY_CLASS_NAMES = Object.fromEntries(Object.entries(UNITY_CLASS_IDS).map(([id, name]) => [name, parseInt(id, 10)]));
1843
+ function get_class_id_name(class_id) {
1844
+ return UNITY_CLASS_IDS[class_id] || `Unknown_${class_id}`;
1845
+ }
1846
+
1847
+ // src/editor/unity-block.ts
1848
+ var HEADER_PATTERN = /^--- !u!(\d+) &(\d+)(\s+stripped)?/;
1849
+ function parse_header(raw) {
1850
+ const first_newline = raw.indexOf(`
1851
+ `);
1852
+ const first_line = first_newline === -1 ? raw : raw.slice(0, first_newline);
1853
+ const match = first_line.match(HEADER_PATTERN);
1854
+ if (!match)
1855
+ return null;
1856
+ return {
1857
+ class_id: parseInt(match[1], 10),
1858
+ file_id: match[2],
1859
+ is_stripped: match[3] !== undefined
1860
+ };
1861
+ }
1862
+ function escape_regex(str) {
1863
+ return str.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
1864
+ }
1865
+
1866
+ class UnityBlock {
1867
+ _raw;
1868
+ _header;
1869
+ _dirty = false;
1870
+ _format_cache = new Map;
1871
+ constructor(raw) {
1872
+ const normalized = raw.replace(/\r\n/g, `
1873
+ `);
1874
+ const header = parse_header(normalized);
1875
+ if (!header) {
1876
+ throw new Error(`Invalid Unity YAML block header: "${normalized.slice(0, 80)}"`);
1877
+ }
1878
+ this._raw = normalized;
1879
+ this._header = header;
1880
+ }
1881
+ get file_id() {
1882
+ return this._header.file_id;
1883
+ }
1884
+ get class_id() {
1885
+ return this._header.class_id;
1886
+ }
1887
+ get is_stripped() {
1888
+ return this._header.is_stripped;
1889
+ }
1890
+ get type_name() {
1891
+ return get_class_id_name(this._header.class_id);
1892
+ }
1893
+ get raw() {
1894
+ return this._raw;
1895
+ }
1896
+ get dirty() {
1897
+ return this._dirty;
1898
+ }
1899
+ get_property(path3) {
1900
+ if (path3.includes("Array.data[")) {
1901
+ return this._get_array_element(path3);
1902
+ }
1903
+ if (path3.includes(".")) {
1904
+ const parts = path3.split(".");
1905
+ const root_prop = parts[0];
1906
+ const root_pattern = new RegExp(`^\\s*${escape_regex(root_prop)}:\\s*(.*)$`, "m");
1907
+ const root_match = this._raw.match(root_pattern);
1908
+ if (root_match) {
1909
+ const obj_str = root_match[1].trim();
1910
+ const sub_field = parts.slice(1).join(".");
1911
+ const sub_pattern = new RegExp(`${escape_regex(sub_field)}:\\s*([^,}]+)`);
1912
+ const sub_match = obj_str.match(sub_pattern);
1913
+ if (sub_match)
1914
+ return sub_match[1].trim();
1915
+ }
1916
+ const block_value = this._extract_block_style_value(parts);
1917
+ if (block_value !== null)
1918
+ return block_value;
1919
+ return null;
1920
+ }
1921
+ const prop_pattern = new RegExp(`^\\s*${escape_regex(path3)}:\\s*(.*)$`, "m");
1922
+ const match = this._raw.match(prop_pattern);
1923
+ return match ? match[1].trim() : null;
1924
+ }
1925
+ set_property(path3, value, object_reference) {
1926
+ const old_raw = this._raw;
1927
+ const effective_ref = object_reference && object_reference !== "{fileID: 0}" ? object_reference : undefined;
1928
+ if (!path3.includes(".") && !path3.includes("Array")) {
1929
+ const prop_pattern = new RegExp(`(^\\s*${escape_regex(path3)}:\\s*)(.*)$`, "m");
1930
+ if (prop_pattern.test(this._raw)) {
1931
+ const replacement_value = effective_ref ?? value;
1932
+ this._raw = this._raw.replace(prop_pattern, `$1${replacement_value}`);
1933
+ }
1934
+ return this._check_dirty(old_raw);
1935
+ }
1936
+ if (path3.includes(".") && !path3.includes("Array")) {
1937
+ const parts = path3.split(".");
1938
+ const parent_prop = parts[0];
1939
+ const sub_field = parts[1];
1940
+ const inline_pattern = new RegExp(`(${escape_regex(parent_prop)}:\\s*\\{)([^}]*)(\\})`, "m");
1941
+ const inline_match = this._raw.match(inline_pattern);
1942
+ let inline_applied = false;
1943
+ if (inline_match) {
1944
+ const fields = inline_match[2];
1945
+ const field_pattern = new RegExp(`(${escape_regex(sub_field)}:\\s*)([^,}]+)`);
1946
+ if (field_pattern.test(fields)) {
1947
+ const updated_fields = fields.replace(field_pattern, `$1${value}`);
1948
+ this._raw = this._raw.replace(inline_pattern, `$1${updated_fields}$3`);
1949
+ inline_applied = true;
1950
+ }
1951
+ }
1952
+ if (!inline_applied) {
1953
+ const effective_value = effective_ref ?? value;
1954
+ const block_result = this._resolve_block_style_path(parts, effective_value);
1955
+ if (block_result !== null) {
1956
+ this._raw = block_result;
1957
+ }
1958
+ }
1959
+ return this._check_dirty(old_raw);
1960
+ }
1961
+ if (path3.includes("Array.data[")) {
1962
+ const array_match = path3.match(/^(.+)\.Array\.data\[(\d+)\]$/);
1963
+ if (array_match) {
1964
+ const array_prop = array_match[1];
1965
+ const index = parseInt(array_match[2], 10);
1966
+ const ref_value = effective_ref ?? value;
1967
+ const array_pattern = new RegExp(`${escape_regex(array_prop)}:\\s*\\n((?:\\s*-\\s*[^\\n]+\\n)*)`, "m");
1968
+ const array_block_match = this._raw.match(array_pattern);
1969
+ if (array_block_match) {
1970
+ const lines = array_block_match[1].split(`
1971
+ `).filter((l) => l.trim().startsWith("-"));
1972
+ if (index < lines.length) {
1973
+ const old_line = lines[index];
1974
+ const new_line = old_line.replace(/-\s*.*/, `- ${ref_value}`);
1975
+ this._raw = this._raw.replace(old_line, new_line);
1976
+ }
1977
+ }
1978
+ }
1979
+ return this._check_dirty(old_raw);
1980
+ }
1981
+ return false;
1982
+ }
1983
+ has_property(path3) {
1984
+ return this.get_property(path3) !== null;
1985
+ }
1986
+ detect_format(property_name) {
1987
+ const cached = this._format_cache.get(property_name);
1988
+ if (cached)
1989
+ return cached;
1990
+ const inline_pattern = new RegExp(`^\\s*${escape_regex(property_name)}:\\s*\\{[^}]+\\}\\s*$`, "m");
1991
+ const result = inline_pattern.test(this._raw) ? "inline" : "block";
1992
+ this._format_cache.set(property_name, result);
1993
+ return result;
1994
+ }
1995
+ get_array_length(array_property) {
1996
+ const empty_pattern = new RegExp(`^\\s*${escape_regex(array_property)}:\\s*\\[\\]\\s*$`, "m");
1997
+ if (empty_pattern.test(this._raw))
1998
+ return 0;
1999
+ const lines = this._raw.split(`
2000
+ `);
2001
+ let in_array = false;
2002
+ let array_indent = -1;
2003
+ let count = 0;
2004
+ for (const line of lines) {
2005
+ if (!in_array) {
2006
+ const header_match = line.match(new RegExp(`^(\\s*)${escape_regex(array_property)}:\\s*$`));
2007
+ if (header_match) {
2008
+ in_array = true;
2009
+ array_indent = header_match[1].length;
2010
+ continue;
2011
+ }
2012
+ } else {
2013
+ const trimmed = line.trim();
2014
+ if (trimmed === "")
2015
+ continue;
2016
+ const leading_match = line.match(/^(\s*)/);
2017
+ const indent = leading_match ? leading_match[1].length : 0;
2018
+ if (indent < array_indent)
2019
+ break;
2020
+ if (indent === array_indent && !trimmed.startsWith("-"))
2021
+ break;
2022
+ if (trimmed.startsWith("-")) {
2023
+ count++;
2024
+ }
2025
+ }
2026
+ }
2027
+ return count;
2028
+ }
2029
+ insert_array_element(array_property, index, value) {
2030
+ const old_raw = this._raw;
2031
+ const empty_pattern = new RegExp(`(^(\\s*)${escape_regex(array_property)}:\\s*)\\[\\]`, "m");
2032
+ const empty_match = this._raw.match(empty_pattern);
2033
+ if (empty_match) {
2034
+ const base_indent = empty_match[2];
2035
+ const element_indent2 = base_indent + " ";
2036
+ this._raw = this._raw.replace(empty_pattern, `$1
2037
+ ${element_indent2}- ${value}`);
2038
+ return this._check_dirty(old_raw);
2039
+ }
2040
+ const lines = this._raw.split(`
2041
+ `);
2042
+ let array_header_idx = -1;
2043
+ let array_indent = -1;
2044
+ const element_indices = [];
2045
+ for (let i = 0;i < lines.length; i++) {
2046
+ if (array_header_idx === -1) {
2047
+ const header_match = lines[i].match(new RegExp(`^(\\s*)${escape_regex(array_property)}:\\s*$`));
2048
+ if (header_match) {
2049
+ array_header_idx = i;
2050
+ array_indent = header_match[1].length;
2051
+ continue;
2052
+ }
2053
+ } else {
2054
+ const trimmed = lines[i].trim();
2055
+ if (trimmed === "")
2056
+ continue;
2057
+ const leading_match = lines[i].match(/^(\s*)/);
2058
+ const indent = leading_match ? leading_match[1].length : 0;
2059
+ if (indent < array_indent)
2060
+ break;
2061
+ if (indent === array_indent && !trimmed.startsWith("-"))
2062
+ break;
2063
+ if (trimmed.startsWith("-")) {
2064
+ element_indices.push(i);
2065
+ }
2066
+ }
2067
+ }
2068
+ if (array_header_idx === -1)
2069
+ return false;
2070
+ let element_indent;
2071
+ if (element_indices.length > 0) {
2072
+ const first_elem = lines[element_indices[0]];
2073
+ const indent_match = first_elem.match(/^(\s*)-/);
2074
+ element_indent = indent_match ? indent_match[1] : " ";
2075
+ } else {
2076
+ element_indent = " ".repeat(array_indent + 2);
2077
+ }
2078
+ const new_line = `${element_indent}- ${value}`;
2079
+ let insert_at;
2080
+ if (index === -1 || index >= element_indices.length) {
2081
+ insert_at = element_indices.length > 0 ? element_indices[element_indices.length - 1] + 1 : array_header_idx + 1;
2082
+ } else {
2083
+ insert_at = element_indices[index];
2084
+ }
2085
+ lines.splice(insert_at, 0, new_line);
2086
+ this._raw = lines.join(`
2087
+ `);
2088
+ return this._check_dirty(old_raw);
2089
+ }
2090
+ remove_array_element(array_property, index) {
2091
+ const old_raw = this._raw;
2092
+ const lines = this._raw.split(`
2093
+ `);
2094
+ let array_header_idx = -1;
2095
+ let array_indent = -1;
2096
+ const element_indices = [];
2097
+ for (let i = 0;i < lines.length; i++) {
2098
+ if (array_header_idx === -1) {
2099
+ const header_match = lines[i].match(new RegExp(`^(\\s*)${escape_regex(array_property)}:\\s*$`));
2100
+ if (header_match) {
2101
+ array_header_idx = i;
2102
+ array_indent = header_match[1].length;
2103
+ continue;
2104
+ }
2105
+ } else {
2106
+ const trimmed = lines[i].trim();
2107
+ if (trimmed === "")
2108
+ continue;
2109
+ const leading_match = lines[i].match(/^(\s*)/);
2110
+ const indent = leading_match ? leading_match[1].length : 0;
2111
+ if (indent < array_indent)
2112
+ break;
2113
+ if (indent === array_indent && !trimmed.startsWith("-"))
2114
+ break;
2115
+ if (trimmed.startsWith("-")) {
2116
+ element_indices.push(i);
2117
+ }
2118
+ }
2119
+ }
2120
+ if (array_header_idx === -1 || index < 0 || index >= element_indices.length) {
2121
+ return false;
2122
+ }
2123
+ lines.splice(element_indices[index], 1);
2124
+ if (element_indices.length === 1) {
2125
+ const header_indent_match = lines[array_header_idx].match(/^(\s*)/);
2126
+ const header_indent = header_indent_match ? header_indent_match[1] : "";
2127
+ lines[array_header_idx] = `${header_indent}${array_property}: []`;
2128
+ }
2129
+ this._raw = lines.join(`
2130
+ `);
2131
+ return this._check_dirty(old_raw);
2132
+ }
2133
+ extract_file_id_refs() {
2134
+ const refs = [];
2135
+ const pattern = /\{fileID:\s*(\d+)/g;
2136
+ const first_newline = this._raw.indexOf(`
2137
+ `);
2138
+ const body = first_newline === -1 ? "" : this._raw.slice(first_newline);
2139
+ let match;
2140
+ while ((match = pattern.exec(body)) !== null) {
2141
+ if (match[1] !== "0") {
2142
+ refs.push(match[1]);
2143
+ }
2144
+ }
2145
+ return refs;
2146
+ }
2147
+ remap_file_id(old_id, new_id) {
2148
+ if (old_id === "0")
2149
+ return;
2150
+ const old_raw = this._raw;
2151
+ const escaped_old = escape_regex(old_id);
2152
+ this._raw = this._raw.replace(new RegExp(`^(--- !u!\\d+ &)${escaped_old}(\\s|$)`), `$1${new_id}$2`);
2153
+ this._raw = this._raw.replace(new RegExp(`(\\{fileID:\\s*)${escaped_old}(\\})`, "g"), `$1${new_id}$2`);
2154
+ if (this._raw !== old_raw) {
2155
+ this._dirty = true;
2156
+ if (this._header.file_id === old_id) {
2157
+ this._header = { ...this._header, file_id: new_id };
2158
+ }
2159
+ }
2160
+ }
2161
+ replace_raw(new_text) {
2162
+ const header = parse_header(new_text);
2163
+ if (!header) {
2164
+ throw new Error(`Invalid Unity YAML block header in replacement text: "${new_text.slice(0, 80)}"`);
2165
+ }
2166
+ this._raw = new_text;
2167
+ this._header = header;
2168
+ this._dirty = true;
2169
+ this._format_cache.clear();
2170
+ }
2171
+ clone() {
2172
+ return new UnityBlock(this._raw);
2173
+ }
2174
+ _check_dirty(old_raw) {
2175
+ if (this._raw !== old_raw) {
2176
+ this._dirty = true;
2177
+ return true;
2178
+ }
2179
+ return false;
2180
+ }
2181
+ _get_array_element(path3) {
2182
+ const array_match = path3.match(/^(.+)\.Array\.data\[(\d+)\]$/);
2183
+ if (!array_match)
2184
+ return null;
2185
+ const array_prop = array_match[1];
2186
+ const index = parseInt(array_match[2], 10);
2187
+ const array_pattern = new RegExp(`${escape_regex(array_prop)}:\\s*\\n((?:\\s*-\\s*[^\\n]+\\n?)*)`, "m");
2188
+ const array_block_match = this._raw.match(array_pattern);
2189
+ if (!array_block_match)
2190
+ return null;
2191
+ const lines = array_block_match[1].split(`
2192
+ `).filter((l) => l.trim().startsWith("-"));
2193
+ if (index >= lines.length)
2194
+ return null;
2195
+ const element_match = lines[index].match(/^\s*-\s*(.+)$/);
2196
+ return element_match ? element_match[1].trim() : null;
2197
+ }
2198
+ _extract_block_style_value(parts) {
2199
+ const lines = this._raw.split(`
2200
+ `);
2201
+ let search_start = 0;
2202
+ let search_end = lines.length;
2203
+ for (let seg = 0;seg < parts.length - 1; seg++) {
2204
+ const segment = parts[seg];
2205
+ let parent_idx = -1;
2206
+ let parent_indent = -1;
2207
+ for (let i = search_start;i < search_end; i++) {
2208
+ const match = lines[i].match(new RegExp(`^(\\s*)${escape_regex(segment)}:\\s*(.*)$`));
2209
+ if (match) {
2210
+ const trailing = match[2].trim();
2211
+ if (trailing === "") {
2212
+ parent_idx = i;
2213
+ parent_indent = match[1].length;
2214
+ break;
2215
+ }
2216
+ for (let j = i + 1;j < search_end; j++) {
2217
+ if (lines[j].trim() === "")
2218
+ continue;
2219
+ const nextLeading = lines[j].match(/^(\s*)/);
2220
+ if (nextLeading && nextLeading[1].length > match[1].length) {
2221
+ parent_idx = i;
2222
+ parent_indent = match[1].length;
2223
+ }
2224
+ break;
2225
+ }
2226
+ if (parent_idx !== -1)
2227
+ break;
2228
+ }
2229
+ }
2230
+ if (parent_idx === -1)
2231
+ return null;
2232
+ let child_indent = -1;
2233
+ for (let i = parent_idx + 1;i < search_end; i++) {
2234
+ if (lines[i].trim() === "")
2235
+ continue;
2236
+ const leading_spaces = lines[i].match(/^(\s*)/);
2237
+ if (leading_spaces) {
2238
+ const indent = leading_spaces[1].length;
2239
+ if (indent > parent_indent) {
2240
+ child_indent = indent;
2241
+ break;
2242
+ }
2243
+ }
2244
+ break;
2245
+ }
2246
+ if (child_indent === -1)
2247
+ return null;
2248
+ search_start = parent_idx + 1;
2249
+ for (let i = parent_idx + 1;i < search_end; i++) {
2250
+ if (lines[i].trim() === "")
2251
+ continue;
2252
+ const leading_spaces = lines[i].match(/^(\s*)/);
2253
+ if (leading_spaces && leading_spaces[1].length < child_indent) {
2254
+ search_end = i;
2255
+ break;
2256
+ }
2257
+ }
2258
+ }
2259
+ const final_prop = parts[parts.length - 1];
2260
+ for (let i = search_start;i < search_end; i++) {
2261
+ const match = lines[i].match(new RegExp(`^\\s*${escape_regex(final_prop)}:\\s*(.+)$`));
2262
+ if (match) {
2263
+ return match[1].trim();
2264
+ }
2265
+ }
2266
+ return null;
2267
+ }
2268
+ _resolve_block_style_path(segments, value) {
2269
+ const lines = this._raw.split(`
2270
+ `);
2271
+ let search_start = 0;
2272
+ let search_end = lines.length;
2273
+ for (let seg = 0;seg < segments.length - 1; seg++) {
2274
+ const segment = segments[seg];
2275
+ let parent_idx = -1;
2276
+ let parent_indent = -1;
2277
+ for (let i = search_start;i < search_end; i++) {
2278
+ const match = lines[i].match(new RegExp(`^(\\s*)${escape_regex(segment)}:\\s*(.*)$`));
2279
+ if (match) {
2280
+ const trailing = match[2].trim();
2281
+ if (trailing === "") {
2282
+ parent_idx = i;
2283
+ parent_indent = match[1].length;
2284
+ break;
2285
+ }
2286
+ for (let j = i + 1;j < search_end; j++) {
2287
+ if (lines[j].trim() === "")
2288
+ continue;
2289
+ const nextLeading = lines[j].match(/^(\s*)/);
2290
+ if (nextLeading && nextLeading[1].length > match[1].length) {
2291
+ parent_idx = i;
2292
+ parent_indent = match[1].length;
2293
+ }
2294
+ break;
2295
+ }
2296
+ if (parent_idx !== -1)
2297
+ break;
2298
+ }
2299
+ }
2300
+ if (parent_idx === -1)
2301
+ return null;
2302
+ let child_indent = -1;
2303
+ for (let i = parent_idx + 1;i < search_end; i++) {
2304
+ if (lines[i].trim() === "")
2305
+ continue;
2306
+ const leading_spaces = lines[i].match(/^(\s*)/);
2307
+ if (leading_spaces) {
2308
+ const indent = leading_spaces[1].length;
2309
+ if (indent > parent_indent) {
2310
+ child_indent = indent;
2311
+ break;
2312
+ }
2313
+ }
2314
+ break;
2315
+ }
2316
+ if (child_indent === -1)
2317
+ return null;
2318
+ search_start = parent_idx + 1;
2319
+ for (let i = parent_idx + 1;i < search_end; i++) {
2320
+ if (lines[i].trim() === "")
2321
+ continue;
2322
+ const leading_spaces = lines[i].match(/^(\s*)/);
2323
+ if (leading_spaces && leading_spaces[1].length < child_indent) {
2324
+ search_end = i;
2325
+ break;
2326
+ }
2327
+ }
2328
+ }
2329
+ const final_prop = segments[segments.length - 1];
2330
+ for (let i = search_start;i < search_end; i++) {
2331
+ const match = lines[i].match(new RegExp(`^(\\s*${escape_regex(final_prop)}:\\s*).+$`));
2332
+ if (match) {
2333
+ lines[i] = match[1] + value;
2334
+ return lines.join(`
2335
+ `);
2336
+ }
2337
+ }
2338
+ return null;
2339
+ }
2340
+ }
2341
+
2342
+ // src/editor/create.ts
2343
+ function createScene(options) {
2344
+ const { output_path, include_defaults, scene_guid } = options;
2345
+ const pathError = validate_file_path(output_path, "write");
2346
+ if (pathError) {
2347
+ return { success: false, output_path, error: pathError };
2348
+ }
2349
+ if (!output_path.endsWith(".unity")) {
2350
+ return {
2351
+ success: false,
2352
+ output_path,
2353
+ error: "Output path must have .unity extension"
2354
+ };
2355
+ }
2356
+ if (import_fs6.existsSync(output_path)) {
2357
+ return {
2358
+ success: false,
2359
+ output_path,
2360
+ error: `File already exists: ${output_path}. Delete it first or choose a different path.`
2361
+ };
2362
+ }
2363
+ const guid = scene_guid || generateGuid();
2364
+ let yaml = `%YAML 1.1
2365
+ %TAG !u! tag:unity3d.com,2011:
2366
+ --- !u!29 &1
2367
+ OcclusionCullingSettings:
2368
+ m_ObjectHideFlags: 0
2369
+ serializedVersion: 2
2370
+ m_OcclusionBakeSettings:
2371
+ smallestOccluder: 5
2372
+ smallestHole: 0.25
2373
+ backfaceThreshold: 100
2374
+ m_SceneGUID: 00000000000000000000000000000000
2375
+ m_OcclusionCullingData: {fileID: 0}
2376
+ --- !u!104 &2
2377
+ RenderSettings:
2378
+ m_ObjectHideFlags: 0
2379
+ serializedVersion: 9
2380
+ m_Fog: 0
2381
+ m_FogColor: {r: 0.5, g: 0.5, b: 0.5, a: 1}
2382
+ m_FogMode: 3
2383
+ m_FogDensity: 0.01
2384
+ m_LinearFogStart: 0
2385
+ m_LinearFogEnd: 300
2386
+ m_AmbientSkyColor: {r: 0.212, g: 0.227, b: 0.259, a: 1}
2387
+ m_AmbientEquatorColor: {r: 0.114, g: 0.125, b: 0.133, a: 1}
2388
+ m_AmbientGroundColor: {r: 0.047, g: 0.043, b: 0.035, a: 1}
2389
+ m_AmbientIntensity: 1
2390
+ m_AmbientMode: 0
2391
+ m_SubtractiveShadowColor: {r: 0.42, g: 0.478, b: 0.627, a: 1}
2392
+ m_SkyboxMaterial: {fileID: 10304, guid: 0000000000000000f000000000000000, type: 0}
2393
+ m_HaloStrength: 0.5
2394
+ m_FlareStrength: 1
2395
+ m_FlareFadeSpeed: 3
2396
+ m_HaloTexture: {fileID: 0}
2397
+ m_SpotCookie: {fileID: 10001, guid: 0000000000000000e000000000000000, type: 0}
2398
+ m_DefaultReflectionMode: 0
2399
+ m_DefaultReflectionResolution: 128
2400
+ m_ReflectionBounces: 1
2401
+ m_ReflectionIntensity: 1
2402
+ m_CustomReflection: {fileID: 0}
2403
+ m_Sun: {fileID: 0}
2404
+ m_IndirectSpecularColor: {r: 0.44657898, g: 0.4964133, b: 0.5748178, a: 1}
2405
+ m_UseRadianceAmbientProbe: 0
2406
+ --- !u!157 &3
2407
+ LightmapSettings:
2408
+ m_ObjectHideFlags: 0
2409
+ serializedVersion: 12
2410
+ m_GIWorkflowMode: 1
2411
+ m_GISettings:
2412
+ serializedVersion: 2
2413
+ m_BounceScale: 1
2414
+ m_IndirectOutputScale: 1
2415
+ m_AlbedoBoost: 1
2416
+ m_EnvironmentLightingMode: 0
2417
+ m_EnableBakedLightmaps: 1
2418
+ m_EnableRealtimeLightmaps: 0
2419
+ m_LightmapEditorSettings:
2420
+ serializedVersion: 12
2421
+ m_Resolution: 2
2422
+ m_BakeResolution: 40
2423
+ m_AtlasSize: 1024
2424
+ m_AO: 0
2425
+ m_AOMaxDistance: 1
2426
+ m_CompAOExponent: 1
2427
+ m_CompAOExponentDirect: 0
2428
+ m_ExtractAmbientOcclusion: 0
2429
+ m_Padding: 2
2430
+ m_LightmapParameters: {fileID: 0}
2431
+ m_LightmapsBakeMode: 1
2432
+ m_TextureCompression: 1
2433
+ m_FinalGather: 0
2434
+ m_FinalGatherFiltering: 1
2435
+ m_FinalGatherRayCount: 256
2436
+ m_ReflectionCompression: 2
2437
+ m_MixedBakeMode: 2
2438
+ m_BakeBackend: 1
2439
+ m_PVRSampling: 1
2440
+ m_PVRDirectSampleCount: 32
2441
+ m_PVRSampleCount: 512
2442
+ m_PVRBounces: 2
2443
+ m_PVREnvironmentSampleCount: 256
2444
+ m_PVREnvironmentReferencePointCount: 2048
2445
+ m_PVRFilteringMode: 1
2446
+ m_PVRDenoiserTypeDirect: 1
2447
+ m_PVRDenoiserTypeIndirect: 1
2448
+ m_PVRDenoiserTypeAO: 1
2449
+ m_PVRFilterTypeDirect: 0
2450
+ m_PVRFilterTypeIndirect: 0
2451
+ m_PVRFilterTypeAO: 0
2452
+ m_PVREnvironmentMIS: 1
2453
+ m_PVRCulling: 1
2454
+ m_PVRFilteringGaussRadiusDirect: 1
2455
+ m_PVRFilteringGaussRadiusIndirect: 5
2456
+ m_PVRFilteringGaussRadiusAO: 2
2457
+ m_PVRFilteringAtrousPositionSigmaDirect: 0.5
2458
+ m_PVRFilteringAtrousPositionSigmaIndirect: 2
2459
+ m_PVRFilteringAtrousPositionSigmaAO: 1
2460
+ m_ExportTrainingData: 0
2461
+ m_TrainingDataDestination: TrainingData
2462
+ m_LightProbeSampleCountMultiplier: 4
2463
+ m_LightingDataAsset: {fileID: 0}
2464
+ m_LightingSettings: {fileID: 0}
2465
+ --- !u!196 &4
2466
+ NavMeshSettings:
2467
+ serializedVersion: 2
2468
+ m_ObjectHideFlags: 0
2469
+ m_BuildSettings:
2470
+ serializedVersion: 3
2471
+ agentTypeID: 0
2472
+ agentRadius: 0.5
2473
+ agentHeight: 2
2474
+ agentSlope: 45
2475
+ agentClimb: 0.4
2476
+ ledgeDropHeight: 0
2477
+ maxJumpAcrossDistance: 0
2478
+ minRegionArea: 2
2479
+ manualCellSize: 0
2480
+ cellSize: 0.16666667
2481
+ manualTileSize: 0
2482
+ tileSize: 256
2483
+ buildHeightMesh: 0
2484
+ maxJobWorkers: 0
2485
+ preserveTilesOutsideBounds: 0
2486
+ debug:
2487
+ m_Flags: 0
2488
+ m_NavMeshData: {fileID: 0}
2489
+ `;
2490
+ if (include_defaults) {
2491
+ yaml += `--- !u!1 &519420028
2492
+ GameObject:
2493
+ m_ObjectHideFlags: 0
2494
+ m_CorrespondingSourceObject: {fileID: 0}
2495
+ m_PrefabInstance: {fileID: 0}
2496
+ m_PrefabAsset: {fileID: 0}
2497
+ serializedVersion: 6
2498
+ m_Component:
2499
+ - component: {fileID: 519420032}
2500
+ - component: {fileID: 519420031}
2501
+ - component: {fileID: 519420029}
2502
+ m_Layer: 0
2503
+ m_Name: Main Camera
2504
+ m_TagString: MainCamera
2505
+ m_Icon: {fileID: 0}
2506
+ m_NavMeshLayer: 0
2507
+ m_StaticEditorFlags: 0
2508
+ m_IsActive: 1
2509
+ --- !u!4 &519420032
2510
+ Transform:
2511
+ m_ObjectHideFlags: 0
2512
+ m_CorrespondingSourceObject: {fileID: 0}
2513
+ m_PrefabInstance: {fileID: 0}
2514
+ m_PrefabAsset: {fileID: 0}
2515
+ m_GameObject: {fileID: 519420028}
2516
+ serializedVersion: 2
2517
+ m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
2518
+ m_LocalPosition: {x: 0, y: 1, z: -10}
2519
+ m_LocalScale: {x: 1, y: 1, z: 1}
2520
+ m_ConstrainProportionsScale: 0
2521
+ m_Children: []
2522
+ m_Father: {fileID: 0}
2523
+ m_RootOrder: 0
2524
+ m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
2525
+ --- !u!20 &519420031
2526
+ Camera:
2527
+ m_ObjectHideFlags: 0
2528
+ m_CorrespondingSourceObject: {fileID: 0}
2529
+ m_PrefabInstance: {fileID: 0}
2530
+ m_PrefabAsset: {fileID: 0}
2531
+ m_GameObject: {fileID: 519420028}
2532
+ m_Enabled: 1
2533
+ serializedVersion: 2
2534
+ m_ClearFlags: 1
2535
+ m_BackGroundColor: {r: 0.19215687, g: 0.3019608, b: 0.4745098, a: 0}
2536
+ m_projectionMatrixMode: 1
2537
+ m_GateFitMode: 2
2538
+ m_FOVAxisMode: 0
2539
+ m_Iso: 200
2540
+ m_ShutterSpeed: 0.005
2541
+ m_Aperture: 16
2542
+ m_FocusDistance: 10
2543
+ m_FocalLength: 50
2544
+ m_BladeCount: 5
2545
+ m_Curvature: {x: 2, y: 11}
2546
+ m_BarrelClipping: 0.25
2547
+ m_Anamorphism: 0
2548
+ m_SensorSize: {x: 36, y: 24}
2549
+ m_LensShift: {x: 0, y: 0}
2550
+ m_NormalizedViewPortRect:
2551
+ serializedVersion: 2
2552
+ x: 0
2553
+ y: 0
2554
+ width: 1
2555
+ height: 1
2556
+ near clip plane: 0.3
2557
+ far clip plane: 1000
2558
+ field of view: 60
2559
+ orthographic: 0
2560
+ orthographic size: 5
2561
+ m_Depth: -1
2562
+ m_CullingMask:
2563
+ serializedVersion: 2
2564
+ m_Bits: 4294967295
2565
+ m_RenderingPath: -1
2566
+ m_TargetTexture: {fileID: 0}
2567
+ m_TargetDisplay: 0
2568
+ m_TargetEye: 3
2569
+ m_HDR: 1
2570
+ m_AllowMSAA: 1
2571
+ m_AllowDynamicResolution: 0
2572
+ m_ForceIntoRT: 0
2573
+ m_OcclusionCulling: 1
2574
+ m_StereoConvergence: 10
2575
+ m_StereoSeparation: 0.022
2576
+ --- !u!81 &519420029
2577
+ AudioListener:
2578
+ m_ObjectHideFlags: 0
2579
+ m_CorrespondingSourceObject: {fileID: 0}
2580
+ m_PrefabInstance: {fileID: 0}
2581
+ m_PrefabAsset: {fileID: 0}
2582
+ m_GameObject: {fileID: 519420028}
2583
+ m_Enabled: 1
2584
+ --- !u!1 &705507993
2585
+ GameObject:
2586
+ m_ObjectHideFlags: 0
2587
+ m_CorrespondingSourceObject: {fileID: 0}
2588
+ m_PrefabInstance: {fileID: 0}
2589
+ m_PrefabAsset: {fileID: 0}
2590
+ serializedVersion: 6
2591
+ m_Component:
2592
+ - component: {fileID: 705507995}
2593
+ - component: {fileID: 705507994}
2594
+ m_Layer: 0
2595
+ m_Name: Directional Light
2596
+ m_TagString: Untagged
2597
+ m_Icon: {fileID: 0}
2598
+ m_NavMeshLayer: 0
2599
+ m_StaticEditorFlags: 0
2600
+ m_IsActive: 1
2601
+ --- !u!4 &705507995
2602
+ Transform:
2603
+ m_ObjectHideFlags: 0
2604
+ m_CorrespondingSourceObject: {fileID: 0}
2605
+ m_PrefabInstance: {fileID: 0}
2606
+ m_PrefabAsset: {fileID: 0}
2607
+ m_GameObject: {fileID: 705507993}
2608
+ serializedVersion: 2
2609
+ m_LocalRotation: {x: 0.40821788, y: -0.23456968, z: 0.10938163, w: 0.8754261}
2610
+ m_LocalPosition: {x: 0, y: 3, z: 0}
2611
+ m_LocalScale: {x: 1, y: 1, z: 1}
2612
+ m_ConstrainProportionsScale: 0
2613
+ m_Children: []
2614
+ m_Father: {fileID: 0}
2615
+ m_RootOrder: 1
2616
+ m_LocalEulerAnglesHint: {x: 50, y: -30, z: 0}
2617
+ --- !u!108 &705507994
2618
+ Light:
2619
+ m_ObjectHideFlags: 0
2620
+ m_CorrespondingSourceObject: {fileID: 0}
2621
+ m_PrefabInstance: {fileID: 0}
2622
+ m_PrefabAsset: {fileID: 0}
2623
+ m_GameObject: {fileID: 705507993}
2624
+ m_Enabled: 1
2625
+ serializedVersion: 10
2626
+ m_Type: 1
2627
+ m_Shape: 0
2628
+ m_Color: {r: 1, g: 0.95686275, b: 0.8392157, a: 1}
2629
+ m_Intensity: 1
2630
+ m_Range: 10
2631
+ m_SpotAngle: 30
2632
+ m_InnerSpotAngle: 21.80208
2633
+ m_CookieSize: 10
2634
+ m_Shadows:
2635
+ m_Type: 2
2636
+ m_Resolution: -1
2637
+ m_CustomResolution: -1
2638
+ m_Strength: 1
2639
+ m_Bias: 0.05
2640
+ m_NormalBias: 0.4
2641
+ m_NearPlane: 0.2
2642
+ m_CullingMatrixOverride:
2643
+ e00: 1
2644
+ e01: 0
2645
+ e02: 0
2646
+ e03: 0
2647
+ e10: 0
2648
+ e11: 1
2649
+ e12: 0
2650
+ e13: 0
2651
+ e20: 0
2652
+ e21: 0
2653
+ e22: 1
2654
+ e23: 0
2655
+ e30: 0
2656
+ e31: 0
2657
+ e32: 0
2658
+ e33: 1
2659
+ m_UseCullingMatrixOverride: 0
2660
+ m_Cookie: {fileID: 0}
2661
+ m_DrawHalo: 0
2662
+ m_Flare: {fileID: 0}
2663
+ m_RenderMode: 0
2664
+ m_CullingMask:
2665
+ serializedVersion: 2
2666
+ m_Bits: 4294967295
2667
+ m_RenderingLayerMask: 1
2668
+ m_Lightmapping: 4
2669
+ m_LightShadowCasterMode: 0
2670
+ m_AreaSize: {x: 1, y: 1}
2671
+ m_BounceIntensity: 1
2672
+ m_ColorTemperature: 6570
2673
+ m_UseColorTemperature: 0
2674
+ m_BoundingSphereOverride: {x: 0, y: 0, z: 0, w: 0}
2675
+ m_UseBoundingSphereOverride: 0
2676
+ m_UseViewFrustumForShadowCasterCull: 1
2677
+ m_ShadowRadius: 0
2678
+ m_ShadowAngle: 0
2679
+ `;
2680
+ }
2681
+ try {
2682
+ import_fs6.writeFileSync(output_path, yaml, "utf-8");
2683
+ } catch (err) {
2684
+ return {
2685
+ success: false,
2686
+ output_path,
2687
+ error: `Failed to write scene file: ${err instanceof Error ? err.message : String(err)}`
2688
+ };
2689
+ }
2690
+ const metaContent = `fileFormatVersion: 2
2691
+ guid: ${guid}
2692
+ DefaultImporter:
2693
+ externalObjects: {}
2694
+ userData:
2695
+ assetBundleName:
2696
+ assetBundleVariant:
2697
+ `;
2698
+ const metaPath = output_path + ".meta";
2699
+ try {
2700
+ import_fs6.writeFileSync(metaPath, metaContent, "utf-8");
2701
+ } catch (err) {
2702
+ try {
2703
+ const fs = require("fs");
2704
+ fs.unlinkSync(output_path);
2705
+ } catch {}
2706
+ return {
2707
+ success: false,
2708
+ output_path,
2709
+ error: `Failed to write .meta file: ${err instanceof Error ? err.message : String(err)}`
2710
+ };
2711
+ }
2712
+ return {
2713
+ success: true,
2714
+ output_path,
2715
+ scene_guid: guid,
2716
+ meta_path: metaPath
2717
+ };
2718
+ }
2719
+ })