@mflrevan/ucp 0.4.0 → 0.4.2

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.
Files changed (70) hide show
  1. package/README.md +1 -11
  2. package/package.json +8 -2
  3. package/bridge/com.ucp.bridge/CHANGELOG.md +0 -128
  4. package/bridge/com.ucp.bridge/CHANGELOG.md.meta +0 -7
  5. package/bridge/com.ucp.bridge/Editor/Bridge/BridgeServer.cs +0 -576
  6. package/bridge/com.ucp.bridge/Editor/Bridge/BridgeServer.cs.meta +0 -2
  7. package/bridge/com.ucp.bridge/Editor/Bridge.meta +0 -8
  8. package/bridge/com.ucp.bridge/Editor/Controllers/AssetController.cs +0 -530
  9. package/bridge/com.ucp.bridge/Editor/Controllers/AssetController.cs.meta +0 -2
  10. package/bridge/com.ucp.bridge/Editor/Controllers/BuildController.cs +0 -230
  11. package/bridge/com.ucp.bridge/Editor/Controllers/BuildController.cs.meta +0 -2
  12. package/bridge/com.ucp.bridge/Editor/Controllers/CompilationController.cs +0 -26
  13. package/bridge/com.ucp.bridge/Editor/Controllers/CompilationController.cs.meta +0 -2
  14. package/bridge/com.ucp.bridge/Editor/Controllers/EditorController.cs +0 -18
  15. package/bridge/com.ucp.bridge/Editor/Controllers/EditorController.cs.meta +0 -2
  16. package/bridge/com.ucp.bridge/Editor/Controllers/EditorSettingsController.cs +0 -438
  17. package/bridge/com.ucp.bridge/Editor/Controllers/EditorSettingsController.cs.meta +0 -2
  18. package/bridge/com.ucp.bridge/Editor/Controllers/FileController.cs +0 -145
  19. package/bridge/com.ucp.bridge/Editor/Controllers/FileController.cs.meta +0 -2
  20. package/bridge/com.ucp.bridge/Editor/Controllers/HierarchyController.cs +0 -319
  21. package/bridge/com.ucp.bridge/Editor/Controllers/HierarchyController.cs.meta +0 -2
  22. package/bridge/com.ucp.bridge/Editor/Controllers/LogsController.cs +0 -288
  23. package/bridge/com.ucp.bridge/Editor/Controllers/LogsController.cs.meta +0 -2
  24. package/bridge/com.ucp.bridge/Editor/Controllers/MaterialController.cs +0 -295
  25. package/bridge/com.ucp.bridge/Editor/Controllers/MaterialController.cs.meta +0 -2
  26. package/bridge/com.ucp.bridge/Editor/Controllers/ObjectReferenceResolver.cs +0 -93
  27. package/bridge/com.ucp.bridge/Editor/Controllers/ObjectReferenceResolver.cs.meta +0 -2
  28. package/bridge/com.ucp.bridge/Editor/Controllers/PlayModeController.cs +0 -84
  29. package/bridge/com.ucp.bridge/Editor/Controllers/PlayModeController.cs.meta +0 -2
  30. package/bridge/com.ucp.bridge/Editor/Controllers/PrefabController.cs +0 -242
  31. package/bridge/com.ucp.bridge/Editor/Controllers/PrefabController.cs.meta +0 -2
  32. package/bridge/com.ucp.bridge/Editor/Controllers/PropertyController.cs +0 -533
  33. package/bridge/com.ucp.bridge/Editor/Controllers/PropertyController.cs.meta +0 -2
  34. package/bridge/com.ucp.bridge/Editor/Controllers/SceneController.cs +0 -269
  35. package/bridge/com.ucp.bridge/Editor/Controllers/SceneController.cs.meta +0 -2
  36. package/bridge/com.ucp.bridge/Editor/Controllers/ScreenshotController.cs +0 -125
  37. package/bridge/com.ucp.bridge/Editor/Controllers/ScreenshotController.cs.meta +0 -2
  38. package/bridge/com.ucp.bridge/Editor/Controllers/ScriptController.cs +0 -104
  39. package/bridge/com.ucp.bridge/Editor/Controllers/ScriptController.cs.meta +0 -2
  40. package/bridge/com.ucp.bridge/Editor/Controllers/SnapshotController.cs +0 -227
  41. package/bridge/com.ucp.bridge/Editor/Controllers/SnapshotController.cs.meta +0 -2
  42. package/bridge/com.ucp.bridge/Editor/Controllers/TestRunnerController.cs +0 -240
  43. package/bridge/com.ucp.bridge/Editor/Controllers/TestRunnerController.cs.meta +0 -2
  44. package/bridge/com.ucp.bridge/Editor/Controllers/VcsController.cs +0 -611
  45. package/bridge/com.ucp.bridge/Editor/Controllers/VcsController.cs.meta +0 -2
  46. package/bridge/com.ucp.bridge/Editor/Controllers.meta +0 -8
  47. package/bridge/com.ucp.bridge/Editor/Protocol/CommandRouter.cs +0 -53
  48. package/bridge/com.ucp.bridge/Editor/Protocol/CommandRouter.cs.meta +0 -2
  49. package/bridge/com.ucp.bridge/Editor/Protocol/MessageTypes.cs +0 -80
  50. package/bridge/com.ucp.bridge/Editor/Protocol/MessageTypes.cs.meta +0 -2
  51. package/bridge/com.ucp.bridge/Editor/Protocol/MiniJson.cs +0 -358
  52. package/bridge/com.ucp.bridge/Editor/Protocol/MiniJson.cs.meta +0 -2
  53. package/bridge/com.ucp.bridge/Editor/Protocol.meta +0 -8
  54. package/bridge/com.ucp.bridge/Editor/Scripts/IUCPScript.cs +0 -37
  55. package/bridge/com.ucp.bridge/Editor/Scripts/IUCPScript.cs.meta +0 -2
  56. package/bridge/com.ucp.bridge/Editor/Scripts.meta +0 -8
  57. package/bridge/com.ucp.bridge/Editor/UCP.Bridge.Editor.asmdef +0 -16
  58. package/bridge/com.ucp.bridge/Editor/UCP.Bridge.Editor.asmdef.meta +0 -7
  59. package/bridge/com.ucp.bridge/Editor.meta +0 -8
  60. package/bridge/com.ucp.bridge/Runtime/UCP.Bridge.Runtime.asmdef +0 -14
  61. package/bridge/com.ucp.bridge/Runtime/UCP.Bridge.Runtime.asmdef.meta +0 -7
  62. package/bridge/com.ucp.bridge/Runtime.meta +0 -8
  63. package/bridge/com.ucp.bridge/Tests/Editor/ControllerSmokeTests.cs +0 -670
  64. package/bridge/com.ucp.bridge/Tests/Editor/ControllerSmokeTests.cs.meta +0 -2
  65. package/bridge/com.ucp.bridge/Tests/Editor/UCP.Bridge.Editor.Tests.asmdef +0 -12
  66. package/bridge/com.ucp.bridge/Tests/Editor/UCP.Bridge.Editor.Tests.asmdef.meta +0 -7
  67. package/bridge/com.ucp.bridge/Tests/Editor.meta +0 -8
  68. package/bridge/com.ucp.bridge/Tests.meta +0 -8
  69. package/bridge/com.ucp.bridge/package.json +0 -27
  70. package/bridge/com.ucp.bridge/package.json.meta +0 -7
@@ -1,533 +0,0 @@
1
- using System;
2
- using System.Collections.Generic;
3
- using System.Reflection;
4
- using UnityEditor;
5
- using UnityEngine;
6
- using UnityEngine.SceneManagement;
7
-
8
- namespace UCP.Bridge
9
- {
10
- public static class PropertyController
11
- {
12
- public static void Register(CommandRouter router)
13
- {
14
- router.Register("object/get-fields", HandleGetFields);
15
- router.Register("object/get-property", HandleGetProperty);
16
- router.Register("object/set-property", HandleSetProperty);
17
- router.Register("object/set-active", HandleSetActive);
18
- router.Register("object/set-name", HandleSetName);
19
- }
20
-
21
- private static object HandleGetFields(string paramsJson)
22
- {
23
- var p = MiniJson.Deserialize(paramsJson) as Dictionary<string, object>;
24
- if (p == null || !p.TryGetValue("instanceId", out var idObj))
25
- throw new ArgumentException("Missing 'instanceId' parameter");
26
-
27
- var componentType = p.TryGetValue("component", out var cObj) ? cObj?.ToString() : null;
28
- int instanceId = Convert.ToInt32(idObj);
29
- var go = FindGameObject(instanceId);
30
-
31
- if (componentType != null)
32
- {
33
- var comp = FindComponent(go, componentType);
34
- return new Dictionary<string, object>
35
- {
36
- ["instanceId"] = instanceId,
37
- ["name"] = go.name,
38
- ["component"] = componentType,
39
- ["fields"] = SerializeComponentFields(comp)
40
- };
41
- }
42
-
43
- // Return fields for all components
44
- var allComponents = new List<object>();
45
- foreach (var c in go.GetComponents<Component>())
46
- {
47
- if (c == null) continue;
48
- allComponents.Add(new Dictionary<string, object>
49
- {
50
- ["type"] = c.GetType().Name,
51
- ["fields"] = SerializeComponentFields(c)
52
- });
53
- }
54
-
55
- return new Dictionary<string, object>
56
- {
57
- ["instanceId"] = instanceId,
58
- ["name"] = go.name,
59
- ["components"] = allComponents
60
- };
61
- }
62
-
63
- private static object HandleGetProperty(string paramsJson)
64
- {
65
- var p = MiniJson.Deserialize(paramsJson) as Dictionary<string, object>;
66
- if (p == null || !p.TryGetValue("instanceId", out var idObj))
67
- throw new ArgumentException("Missing 'instanceId' parameter");
68
- if (!p.TryGetValue("component", out var cObj) || cObj == null)
69
- throw new ArgumentException("Missing 'component' parameter");
70
- if (!p.TryGetValue("property", out var propObj) || propObj == null)
71
- throw new ArgumentException("Missing 'property' parameter");
72
-
73
- int instanceId = Convert.ToInt32(idObj);
74
- var go = FindGameObject(instanceId);
75
- var comp = FindComponent(go, cObj.ToString());
76
- string propName = propObj.ToString();
77
-
78
- var value = GetPropertyValue(comp, propName);
79
- return new Dictionary<string, object>
80
- {
81
- ["instanceId"] = instanceId,
82
- ["component"] = cObj.ToString(),
83
- ["property"] = propName,
84
- ["value"] = ConvertToJson(value),
85
- ["type"] = value != null ? value.GetType().Name : "null"
86
- };
87
- }
88
-
89
- private static object HandleSetProperty(string paramsJson)
90
- {
91
- var p = MiniJson.Deserialize(paramsJson) as Dictionary<string, object>;
92
- if (p == null || !p.TryGetValue("instanceId", out var idObj))
93
- throw new ArgumentException("Missing 'instanceId' parameter");
94
- if (!p.TryGetValue("component", out var cObj) || cObj == null)
95
- throw new ArgumentException("Missing 'component' parameter");
96
- if (!p.TryGetValue("property", out var propObj) || propObj == null)
97
- throw new ArgumentException("Missing 'property' parameter");
98
- if (!p.ContainsKey("value"))
99
- throw new ArgumentException("Missing 'value' parameter");
100
-
101
- int instanceId = Convert.ToInt32(idObj);
102
- var go = FindGameObject(instanceId);
103
- var comp = FindComponent(go, cObj.ToString());
104
- string propName = propObj.ToString();
105
-
106
- Undo.RecordObject(comp, $"UCP Set {propName}");
107
- SetPropertyValue(comp, propName, p["value"]);
108
- EditorUtility.SetDirty(comp);
109
-
110
- return new Dictionary<string, object>
111
- {
112
- ["status"] = "ok",
113
- ["instanceId"] = instanceId,
114
- ["component"] = cObj.ToString(),
115
- ["property"] = propName
116
- };
117
- }
118
-
119
- private static object HandleSetActive(string paramsJson)
120
- {
121
- var p = MiniJson.Deserialize(paramsJson) as Dictionary<string, object>;
122
- if (p == null || !p.TryGetValue("instanceId", out var idObj))
123
- throw new ArgumentException("Missing 'instanceId' parameter");
124
- if (!p.TryGetValue("active", out var activeObj))
125
- throw new ArgumentException("Missing 'active' parameter");
126
-
127
- int instanceId = Convert.ToInt32(idObj);
128
- var go = FindGameObject(instanceId);
129
-
130
- Undo.RecordObject(go, "UCP Set Active");
131
- go.SetActive(Convert.ToBoolean(activeObj));
132
- EditorUtility.SetDirty(go);
133
-
134
- return new Dictionary<string, object>
135
- {
136
- ["status"] = "ok",
137
- ["instanceId"] = instanceId,
138
- ["active"] = go.activeSelf
139
- };
140
- }
141
-
142
- private static object HandleSetName(string paramsJson)
143
- {
144
- var p = MiniJson.Deserialize(paramsJson) as Dictionary<string, object>;
145
- if (p == null || !p.TryGetValue("instanceId", out var idObj))
146
- throw new ArgumentException("Missing 'instanceId' parameter");
147
- if (!p.TryGetValue("name", out var nameObj) || nameObj == null)
148
- throw new ArgumentException("Missing 'name' parameter");
149
-
150
- int instanceId = Convert.ToInt32(idObj);
151
- var go = FindGameObject(instanceId);
152
-
153
- Undo.RecordObject(go, "UCP Rename");
154
- go.name = nameObj.ToString();
155
- EditorUtility.SetDirty(go);
156
-
157
- return new Dictionary<string, object>
158
- {
159
- ["status"] = "ok",
160
- ["instanceId"] = instanceId,
161
- ["name"] = go.name
162
- };
163
- }
164
-
165
- // ---- Reflection helpers ----
166
-
167
- private static List<object> SerializeComponentFields(Component comp)
168
- {
169
- var fields = new List<object>();
170
- var type = comp.GetType();
171
-
172
- // Use SerializedObject for reliable Unity property enumeration
173
- var so = new SerializedObject(comp);
174
- var prop = so.GetIterator();
175
- if (prop.NextVisible(true))
176
- {
177
- do
178
- {
179
- var fieldDict = new Dictionary<string, object>
180
- {
181
- ["name"] = prop.name,
182
- ["displayName"] = prop.displayName,
183
- ["type"] = prop.propertyType.ToString(),
184
- ["editable"] = !prop.isReadOnly(true)
185
- };
186
-
187
- try
188
- {
189
- fieldDict["value"] = SerializedPropertyToValue(prop);
190
- }
191
- catch
192
- {
193
- fieldDict["value"] = "<unreadable>";
194
- }
195
-
196
- fields.Add(fieldDict);
197
- }
198
- while (prop.NextVisible(false));
199
- }
200
- so.Dispose();
201
-
202
- return fields;
203
- }
204
-
205
- private static object SerializedPropertyToValue(SerializedProperty prop)
206
- {
207
- switch (prop.propertyType)
208
- {
209
- case SerializedPropertyType.Integer:
210
- return prop.intValue;
211
- case SerializedPropertyType.Boolean:
212
- return prop.boolValue;
213
- case SerializedPropertyType.Float:
214
- return (double)prop.floatValue;
215
- case SerializedPropertyType.String:
216
- return prop.stringValue;
217
- case SerializedPropertyType.Color:
218
- var c = prop.colorValue;
219
- return new List<object> { (double)c.r, (double)c.g, (double)c.b, (double)c.a };
220
- case SerializedPropertyType.ObjectReference:
221
- return ObjectReferenceResolver.Serialize(prop.objectReferenceValue);
222
- case SerializedPropertyType.LayerMask:
223
- return prop.intValue;
224
- case SerializedPropertyType.Enum:
225
- return prop.enumValueIndex < prop.enumDisplayNames.Length
226
- ? prop.enumDisplayNames[prop.enumValueIndex]
227
- : prop.enumValueIndex.ToString();
228
- case SerializedPropertyType.Vector2:
229
- var v2 = prop.vector2Value;
230
- return new List<object> { (double)v2.x, (double)v2.y };
231
- case SerializedPropertyType.Vector3:
232
- var v3 = prop.vector3Value;
233
- return new List<object> { (double)v3.x, (double)v3.y, (double)v3.z };
234
- case SerializedPropertyType.Vector4:
235
- var v4 = prop.vector4Value;
236
- return new List<object> { (double)v4.x, (double)v4.y, (double)v4.z, (double)v4.w };
237
- case SerializedPropertyType.Rect:
238
- var r = prop.rectValue;
239
- return new Dictionary<string, object>
240
- {
241
- ["x"] = (double)r.x,
242
- ["y"] = (double)r.y,
243
- ["width"] = (double)r.width,
244
- ["height"] = (double)r.height
245
- };
246
- case SerializedPropertyType.Bounds:
247
- var b = prop.boundsValue;
248
- return new Dictionary<string, object>
249
- {
250
- ["center"] = new List<object> { (double)b.center.x, (double)b.center.y, (double)b.center.z },
251
- ["size"] = new List<object> { (double)b.size.x, (double)b.size.y, (double)b.size.z }
252
- };
253
- case SerializedPropertyType.Quaternion:
254
- var q = prop.quaternionValue;
255
- return new List<object> { (double)q.x, (double)q.y, (double)q.z, (double)q.w };
256
- case SerializedPropertyType.AnimationCurve:
257
- return "<AnimationCurve>";
258
- case SerializedPropertyType.Gradient:
259
- return "<Gradient>";
260
- default:
261
- return $"<{prop.propertyType}>";
262
- }
263
- }
264
-
265
- private static object GetPropertyValue(Component comp, string propertyName)
266
- {
267
- var so = new SerializedObject(comp);
268
- var prop = so.FindProperty(propertyName);
269
- if (prop != null)
270
- {
271
- var val = SerializedPropertyToValue(prop);
272
- so.Dispose();
273
- return val;
274
- }
275
- so.Dispose();
276
-
277
- // Fallback to reflection
278
- var type = comp.GetType();
279
- var fi = type.GetField(propertyName, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);
280
- if (fi != null)
281
- return fi.GetValue(comp);
282
-
283
- var pi = type.GetProperty(propertyName, BindingFlags.Public | BindingFlags.Instance);
284
- if (pi != null && pi.CanRead)
285
- return pi.GetValue(comp);
286
-
287
- throw new ArgumentException($"Property '{propertyName}' not found on {type.Name}");
288
- }
289
-
290
- private static void SetPropertyValue(Component comp, string propertyName, object jsonValue)
291
- {
292
- var so = new SerializedObject(comp);
293
- var prop = so.FindProperty(propertyName);
294
- if (prop != null)
295
- {
296
- SetSerializedPropertyValue(prop, jsonValue);
297
- so.ApplyModifiedProperties();
298
- so.Dispose();
299
- return;
300
- }
301
- so.Dispose();
302
-
303
- // Fallback to reflection
304
- var type = comp.GetType();
305
- var fi = type.GetField(propertyName, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);
306
- if (fi != null)
307
- {
308
- fi.SetValue(comp, ConvertFromJson(jsonValue, fi.FieldType));
309
- return;
310
- }
311
-
312
- var pi = type.GetProperty(propertyName, BindingFlags.Public | BindingFlags.Instance);
313
- if (pi != null && pi.CanWrite)
314
- {
315
- pi.SetValue(comp, ConvertFromJson(jsonValue, pi.PropertyType));
316
- return;
317
- }
318
-
319
- throw new ArgumentException($"Property '{propertyName}' not found or not writable on {type.Name}");
320
- }
321
-
322
- private static void SetSerializedPropertyValue(SerializedProperty prop, object value)
323
- {
324
- switch (prop.propertyType)
325
- {
326
- case SerializedPropertyType.Integer:
327
- prop.intValue = Convert.ToInt32(value);
328
- break;
329
- case SerializedPropertyType.Boolean:
330
- prop.boolValue = Convert.ToBoolean(value);
331
- break;
332
- case SerializedPropertyType.Float:
333
- prop.floatValue = Convert.ToSingle(value);
334
- break;
335
- case SerializedPropertyType.String:
336
- prop.stringValue = value?.ToString() ?? "";
337
- break;
338
- case SerializedPropertyType.Color:
339
- var cArr = value as List<object>;
340
- if (cArr != null && cArr.Count >= 3)
341
- prop.colorValue = new Color(
342
- Convert.ToSingle(cArr[0]),
343
- Convert.ToSingle(cArr[1]),
344
- Convert.ToSingle(cArr[2]),
345
- cArr.Count >= 4 ? Convert.ToSingle(cArr[3]) : 1f);
346
- break;
347
- case SerializedPropertyType.Enum:
348
- if (value is string enumStr)
349
- {
350
- int idx = Array.IndexOf(prop.enumDisplayNames, enumStr);
351
- if (idx >= 0)
352
- prop.enumValueIndex = idx;
353
- else if (int.TryParse(enumStr, out int enumIdx))
354
- prop.enumValueIndex = enumIdx;
355
- else
356
- throw new ArgumentException($"Invalid enum value: {enumStr}");
357
- }
358
- else
359
- {
360
- prop.enumValueIndex = Convert.ToInt32(value);
361
- }
362
- break;
363
- case SerializedPropertyType.Vector2:
364
- var v2Arr = value as List<object>;
365
- if (v2Arr != null && v2Arr.Count >= 2)
366
- prop.vector2Value = new Vector2(
367
- Convert.ToSingle(v2Arr[0]),
368
- Convert.ToSingle(v2Arr[1]));
369
- break;
370
- case SerializedPropertyType.Vector3:
371
- var v3Arr = value as List<object>;
372
- if (v3Arr != null && v3Arr.Count >= 3)
373
- prop.vector3Value = new Vector3(
374
- Convert.ToSingle(v3Arr[0]),
375
- Convert.ToSingle(v3Arr[1]),
376
- Convert.ToSingle(v3Arr[2]));
377
- break;
378
- case SerializedPropertyType.Vector4:
379
- var v4Arr = value as List<object>;
380
- if (v4Arr != null && v4Arr.Count >= 4)
381
- prop.vector4Value = new Vector4(
382
- Convert.ToSingle(v4Arr[0]),
383
- Convert.ToSingle(v4Arr[1]),
384
- Convert.ToSingle(v4Arr[2]),
385
- Convert.ToSingle(v4Arr[3]));
386
- break;
387
- case SerializedPropertyType.Quaternion:
388
- var qArr = value as List<object>;
389
- if (qArr != null && qArr.Count >= 4)
390
- prop.quaternionValue = new Quaternion(
391
- Convert.ToSingle(qArr[0]),
392
- Convert.ToSingle(qArr[1]),
393
- Convert.ToSingle(qArr[2]),
394
- Convert.ToSingle(qArr[3]));
395
- break;
396
- case SerializedPropertyType.Rect:
397
- var rDict = value as Dictionary<string, object>;
398
- if (rDict != null)
399
- prop.rectValue = new Rect(
400
- Convert.ToSingle(rDict["x"]),
401
- Convert.ToSingle(rDict["y"]),
402
- Convert.ToSingle(rDict["width"]),
403
- Convert.ToSingle(rDict["height"]));
404
- break;
405
- case SerializedPropertyType.Bounds:
406
- var bDict = value as Dictionary<string, object>;
407
- if (bDict != null)
408
- {
409
- var center = bDict["center"] as List<object>;
410
- var size = bDict["size"] as List<object>;
411
- if (center != null && size != null)
412
- prop.boundsValue = new Bounds(
413
- new Vector3(Convert.ToSingle(center[0]), Convert.ToSingle(center[1]), Convert.ToSingle(center[2])),
414
- new Vector3(Convert.ToSingle(size[0]), Convert.ToSingle(size[1]), Convert.ToSingle(size[2])));
415
- }
416
- break;
417
- case SerializedPropertyType.ObjectReference:
418
- prop.objectReferenceValue = ObjectReferenceResolver.Resolve(value, prop.displayName);
419
- if (value != null && prop.objectReferenceValue == null)
420
- throw new ArgumentException($"Unable to assign object reference to '{prop.displayName}'");
421
- break;
422
- case SerializedPropertyType.LayerMask:
423
- prop.intValue = Convert.ToInt32(value);
424
- break;
425
- default:
426
- throw new ArgumentException($"Cannot set property of type {prop.propertyType}");
427
- }
428
- }
429
-
430
- private static object ConvertToJson(object value)
431
- {
432
- if (value == null) return null;
433
- if (value is int || value is long || value is float || value is double ||
434
- value is bool || value is string)
435
- return value;
436
- if (value is Vector2 v2)
437
- return new List<object> { (double)v2.x, (double)v2.y };
438
- if (value is Vector3 v3)
439
- return new List<object> { (double)v3.x, (double)v3.y, (double)v3.z };
440
- if (value is Vector4 v4)
441
- return new List<object> { (double)v4.x, (double)v4.y, (double)v4.z, (double)v4.w };
442
- if (value is Quaternion q)
443
- return new List<object> { (double)q.x, (double)q.y, (double)q.z, (double)q.w };
444
- if (value is Color c)
445
- return new List<object> { (double)c.r, (double)c.g, (double)c.b, (double)c.a };
446
- if (value is UnityEngine.Object uObj)
447
- return ObjectReferenceResolver.Serialize(uObj);
448
- return value.ToString();
449
- }
450
-
451
- private static object ConvertFromJson(object jsonValue, Type targetType)
452
- {
453
- if (jsonValue == null) return null;
454
- if (targetType == typeof(int)) return Convert.ToInt32(jsonValue);
455
- if (targetType == typeof(float)) return Convert.ToSingle(jsonValue);
456
- if (targetType == typeof(double)) return Convert.ToDouble(jsonValue);
457
- if (targetType == typeof(bool)) return Convert.ToBoolean(jsonValue);
458
- if (targetType == typeof(string)) return jsonValue.ToString();
459
- if (targetType == typeof(long)) return Convert.ToInt64(jsonValue);
460
-
461
- if (targetType == typeof(Vector2) && jsonValue is List<object> v2)
462
- return new Vector2(Convert.ToSingle(v2[0]), Convert.ToSingle(v2[1]));
463
- if (targetType == typeof(Vector3) && jsonValue is List<object> v3)
464
- return new Vector3(Convert.ToSingle(v3[0]), Convert.ToSingle(v3[1]), Convert.ToSingle(v3[2]));
465
- if (targetType == typeof(Vector4) && jsonValue is List<object> v4)
466
- return new Vector4(Convert.ToSingle(v4[0]), Convert.ToSingle(v4[1]), Convert.ToSingle(v4[2]), Convert.ToSingle(v4[3]));
467
- if (targetType == typeof(Quaternion) && jsonValue is List<object> qv)
468
- return new Quaternion(Convert.ToSingle(qv[0]), Convert.ToSingle(qv[1]), Convert.ToSingle(qv[2]), Convert.ToSingle(qv[3]));
469
- if (targetType == typeof(Color) && jsonValue is List<object> cv)
470
- return new Color(Convert.ToSingle(cv[0]), Convert.ToSingle(cv[1]), Convert.ToSingle(cv[2]),
471
- cv.Count >= 4 ? Convert.ToSingle(cv[3]) : 1f);
472
-
473
- return Convert.ChangeType(jsonValue, targetType);
474
- }
475
-
476
- private static GameObject FindGameObject(int instanceId)
477
- {
478
- var obj = EditorUtility.InstanceIDToObject(instanceId) as GameObject;
479
- if (obj != null) return obj;
480
-
481
- // Search in loaded scenes
482
- for (int i = 0; i < SceneManager.sceneCount; i++)
483
- {
484
- var scene = SceneManager.GetSceneAt(i);
485
- if (!scene.isLoaded) continue;
486
- foreach (var root in scene.GetRootGameObjects())
487
- {
488
- var found = FindInHierarchy(root, instanceId);
489
- if (found != null) return found;
490
- }
491
- }
492
-
493
- throw new ArgumentException($"GameObject not found: {instanceId}");
494
- }
495
-
496
- private static GameObject FindInHierarchy(GameObject go, int instanceId)
497
- {
498
- if (go.GetInstanceID() == instanceId) return go;
499
- for (int i = 0; i < go.transform.childCount; i++)
500
- {
501
- var found = FindInHierarchy(go.transform.GetChild(i).gameObject, instanceId);
502
- if (found != null) return found;
503
- }
504
- return null;
505
- }
506
-
507
- private static Component FindComponent(GameObject go, string typeName)
508
- {
509
- foreach (var c in go.GetComponents<Component>())
510
- {
511
- if (c == null) continue;
512
- if (c.GetType().Name == typeName || c.GetType().FullName == typeName)
513
- return c;
514
- }
515
- throw new ArgumentException($"Component '{typeName}' not found on '{go.name}'");
516
- }
517
-
518
- // Extension-like helper for SerializedProperty.isReadOnly
519
- // which doesn't exist as a public API in older Unity
520
- }
521
-
522
- internal static class SerializedPropertyExtensions
523
- {
524
- internal static bool isReadOnly(this SerializedProperty prop, bool includeChildren)
525
- {
526
- // Check if the property path suggests it's a built-in non-editable field
527
- string path = prop.propertyPath;
528
- if (path == "m_Script") return true;
529
- if (path == "m_ObjectHideFlags") return true;
530
- return false;
531
- }
532
- }
533
- }
@@ -1,2 +0,0 @@
1
- fileFormatVersion: 2
2
- guid: 8d9194b68ed2905498f060fb468875c4