@mflrevan/ucp 0.3.3 → 0.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -3
- package/package.json +8 -2
- package/bridge/com.ucp.bridge/CHANGELOG.md +0 -112
- package/bridge/com.ucp.bridge/CHANGELOG.md.meta +0 -7
- package/bridge/com.ucp.bridge/Editor/Bridge/BridgeServer.cs +0 -576
- package/bridge/com.ucp.bridge/Editor/Bridge/BridgeServer.cs.meta +0 -2
- package/bridge/com.ucp.bridge/Editor/Bridge.meta +0 -8
- package/bridge/com.ucp.bridge/Editor/Controllers/AssetController.cs +0 -530
- package/bridge/com.ucp.bridge/Editor/Controllers/AssetController.cs.meta +0 -2
- package/bridge/com.ucp.bridge/Editor/Controllers/BuildController.cs +0 -230
- package/bridge/com.ucp.bridge/Editor/Controllers/BuildController.cs.meta +0 -2
- package/bridge/com.ucp.bridge/Editor/Controllers/CompilationController.cs +0 -26
- package/bridge/com.ucp.bridge/Editor/Controllers/CompilationController.cs.meta +0 -2
- package/bridge/com.ucp.bridge/Editor/Controllers/EditorController.cs +0 -18
- package/bridge/com.ucp.bridge/Editor/Controllers/EditorController.cs.meta +0 -2
- package/bridge/com.ucp.bridge/Editor/Controllers/EditorSettingsController.cs +0 -438
- package/bridge/com.ucp.bridge/Editor/Controllers/EditorSettingsController.cs.meta +0 -2
- package/bridge/com.ucp.bridge/Editor/Controllers/FileController.cs +0 -130
- package/bridge/com.ucp.bridge/Editor/Controllers/FileController.cs.meta +0 -2
- package/bridge/com.ucp.bridge/Editor/Controllers/HierarchyController.cs +0 -319
- package/bridge/com.ucp.bridge/Editor/Controllers/HierarchyController.cs.meta +0 -2
- package/bridge/com.ucp.bridge/Editor/Controllers/LogsController.cs +0 -288
- package/bridge/com.ucp.bridge/Editor/Controllers/LogsController.cs.meta +0 -2
- package/bridge/com.ucp.bridge/Editor/Controllers/MaterialController.cs +0 -295
- package/bridge/com.ucp.bridge/Editor/Controllers/MaterialController.cs.meta +0 -2
- package/bridge/com.ucp.bridge/Editor/Controllers/ObjectReferenceResolver.cs +0 -93
- package/bridge/com.ucp.bridge/Editor/Controllers/ObjectReferenceResolver.cs.meta +0 -2
- package/bridge/com.ucp.bridge/Editor/Controllers/PlayModeController.cs +0 -84
- package/bridge/com.ucp.bridge/Editor/Controllers/PlayModeController.cs.meta +0 -2
- package/bridge/com.ucp.bridge/Editor/Controllers/PrefabController.cs +0 -242
- package/bridge/com.ucp.bridge/Editor/Controllers/PrefabController.cs.meta +0 -2
- package/bridge/com.ucp.bridge/Editor/Controllers/PropertyController.cs +0 -533
- package/bridge/com.ucp.bridge/Editor/Controllers/PropertyController.cs.meta +0 -2
- package/bridge/com.ucp.bridge/Editor/Controllers/SceneController.cs +0 -111
- package/bridge/com.ucp.bridge/Editor/Controllers/SceneController.cs.meta +0 -2
- package/bridge/com.ucp.bridge/Editor/Controllers/ScreenshotController.cs +0 -125
- package/bridge/com.ucp.bridge/Editor/Controllers/ScreenshotController.cs.meta +0 -2
- package/bridge/com.ucp.bridge/Editor/Controllers/ScriptController.cs +0 -104
- package/bridge/com.ucp.bridge/Editor/Controllers/ScriptController.cs.meta +0 -2
- package/bridge/com.ucp.bridge/Editor/Controllers/SnapshotController.cs +0 -227
- package/bridge/com.ucp.bridge/Editor/Controllers/SnapshotController.cs.meta +0 -2
- package/bridge/com.ucp.bridge/Editor/Controllers/TestRunnerController.cs +0 -240
- package/bridge/com.ucp.bridge/Editor/Controllers/TestRunnerController.cs.meta +0 -2
- package/bridge/com.ucp.bridge/Editor/Controllers/VcsController.cs +0 -611
- package/bridge/com.ucp.bridge/Editor/Controllers/VcsController.cs.meta +0 -2
- package/bridge/com.ucp.bridge/Editor/Controllers.meta +0 -8
- package/bridge/com.ucp.bridge/Editor/Protocol/CommandRouter.cs +0 -53
- package/bridge/com.ucp.bridge/Editor/Protocol/CommandRouter.cs.meta +0 -2
- package/bridge/com.ucp.bridge/Editor/Protocol/MessageTypes.cs +0 -80
- package/bridge/com.ucp.bridge/Editor/Protocol/MessageTypes.cs.meta +0 -2
- package/bridge/com.ucp.bridge/Editor/Protocol/MiniJson.cs +0 -358
- package/bridge/com.ucp.bridge/Editor/Protocol/MiniJson.cs.meta +0 -2
- package/bridge/com.ucp.bridge/Editor/Protocol.meta +0 -8
- package/bridge/com.ucp.bridge/Editor/Scripts/IUCPScript.cs +0 -37
- package/bridge/com.ucp.bridge/Editor/Scripts/IUCPScript.cs.meta +0 -2
- package/bridge/com.ucp.bridge/Editor/Scripts.meta +0 -8
- package/bridge/com.ucp.bridge/Editor/UCP.Bridge.Editor.asmdef +0 -16
- package/bridge/com.ucp.bridge/Editor/UCP.Bridge.Editor.asmdef.meta +0 -7
- package/bridge/com.ucp.bridge/Editor.meta +0 -8
- package/bridge/com.ucp.bridge/Runtime/UCP.Bridge.Runtime.asmdef +0 -14
- package/bridge/com.ucp.bridge/Runtime/UCP.Bridge.Runtime.asmdef.meta +0 -7
- package/bridge/com.ucp.bridge/Runtime.meta +0 -8
- package/bridge/com.ucp.bridge/Tests/Editor/ControllerSmokeTests.cs +0 -591
- package/bridge/com.ucp.bridge/Tests/Editor/ControllerSmokeTests.cs.meta +0 -2
- package/bridge/com.ucp.bridge/Tests/Editor/UCP.Bridge.Editor.Tests.asmdef +0 -12
- package/bridge/com.ucp.bridge/Tests/Editor/UCP.Bridge.Editor.Tests.asmdef.meta +0 -7
- package/bridge/com.ucp.bridge/Tests/Editor.meta +0 -8
- package/bridge/com.ucp.bridge/Tests.meta +0 -8
- package/bridge/com.ucp.bridge/package.json +0 -27
- package/bridge/com.ucp.bridge/package.json.meta +0 -7
|
@@ -1,530 +0,0 @@
|
|
|
1
|
-
using System;
|
|
2
|
-
using System.Collections.Generic;
|
|
3
|
-
using System.Reflection;
|
|
4
|
-
using UnityEditor;
|
|
5
|
-
using UnityEngine;
|
|
6
|
-
|
|
7
|
-
namespace UCP.Bridge
|
|
8
|
-
{
|
|
9
|
-
public static class AssetController
|
|
10
|
-
{
|
|
11
|
-
public static void Register(CommandRouter router)
|
|
12
|
-
{
|
|
13
|
-
router.Register("asset/search", HandleSearch);
|
|
14
|
-
router.Register("asset/info", HandleInfo);
|
|
15
|
-
router.Register("asset/read", HandleReadScriptableObject);
|
|
16
|
-
router.Register("asset/write", HandleWriteScriptableObject);
|
|
17
|
-
router.Register("asset/write-batch", HandleWriteScriptableObjectBatch);
|
|
18
|
-
router.Register("asset/create-so", HandleCreateScriptableObject);
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
private static object HandleSearch(string paramsJson)
|
|
22
|
-
{
|
|
23
|
-
var p = MiniJson.Deserialize(paramsJson) as Dictionary<string, object>;
|
|
24
|
-
string typeFilter = null;
|
|
25
|
-
string nameFilter = null;
|
|
26
|
-
string pathFilter = null;
|
|
27
|
-
int maxResults = 100;
|
|
28
|
-
|
|
29
|
-
if (p != null)
|
|
30
|
-
{
|
|
31
|
-
if (p.TryGetValue("type", out var tObj) && tObj != null)
|
|
32
|
-
typeFilter = tObj.ToString();
|
|
33
|
-
if (p.TryGetValue("name", out var nObj) && nObj != null)
|
|
34
|
-
nameFilter = nObj.ToString();
|
|
35
|
-
if (p.TryGetValue("path", out var pObj) && pObj != null)
|
|
36
|
-
pathFilter = pObj.ToString();
|
|
37
|
-
if (p.TryGetValue("maxResults", out var mObj))
|
|
38
|
-
maxResults = Convert.ToInt32(mObj);
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
// Build search filter
|
|
42
|
-
string filter = "";
|
|
43
|
-
if (!string.IsNullOrEmpty(nameFilter))
|
|
44
|
-
filter += nameFilter + " ";
|
|
45
|
-
if (!string.IsNullOrEmpty(typeFilter))
|
|
46
|
-
filter += $"t:{GetSearchTypeFilter(typeFilter)}";
|
|
47
|
-
|
|
48
|
-
string[] searchFolders = null;
|
|
49
|
-
if (!string.IsNullOrEmpty(pathFilter))
|
|
50
|
-
searchFolders = new[] { pathFilter };
|
|
51
|
-
|
|
52
|
-
string[] guids;
|
|
53
|
-
if (searchFolders != null)
|
|
54
|
-
guids = AssetDatabase.FindAssets(filter.Trim(), searchFolders);
|
|
55
|
-
else
|
|
56
|
-
guids = AssetDatabase.FindAssets(filter.Trim());
|
|
57
|
-
|
|
58
|
-
var results = new List<object>();
|
|
59
|
-
int totalMatches = 0;
|
|
60
|
-
for (int i = 0; i < guids.Length; i++)
|
|
61
|
-
{
|
|
62
|
-
string assetPath = AssetDatabase.GUIDToAssetPath(guids[i]);
|
|
63
|
-
foreach (var asset in GetMatchingAssets(assetPath, typeFilter, nameFilter))
|
|
64
|
-
{
|
|
65
|
-
totalMatches++;
|
|
66
|
-
if (results.Count >= maxResults)
|
|
67
|
-
continue;
|
|
68
|
-
|
|
69
|
-
results.Add(new Dictionary<string, object>
|
|
70
|
-
{
|
|
71
|
-
["guid"] = guids[i],
|
|
72
|
-
["path"] = assetPath,
|
|
73
|
-
["type"] = GetDisplayType(assetPath, asset),
|
|
74
|
-
["name"] = asset.name,
|
|
75
|
-
["isSubAsset"] = AssetDatabase.IsSubAsset(asset)
|
|
76
|
-
});
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
return new Dictionary<string, object>
|
|
81
|
-
{
|
|
82
|
-
["results"] = results,
|
|
83
|
-
["total"] = totalMatches,
|
|
84
|
-
["returned"] = results.Count
|
|
85
|
-
};
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
private static object HandleInfo(string paramsJson)
|
|
89
|
-
{
|
|
90
|
-
var p = MiniJson.Deserialize(paramsJson) as Dictionary<string, object>;
|
|
91
|
-
if (p == null || !p.TryGetValue("path", out var pathObj))
|
|
92
|
-
throw new ArgumentException("Missing 'path' parameter");
|
|
93
|
-
|
|
94
|
-
string assetPath = pathObj.ToString();
|
|
95
|
-
var asset = AssetDatabase.LoadAssetAtPath<UnityEngine.Object>(assetPath);
|
|
96
|
-
if (asset == null)
|
|
97
|
-
throw new ArgumentException($"Asset not found: {assetPath}");
|
|
98
|
-
|
|
99
|
-
var info = new Dictionary<string, object>
|
|
100
|
-
{
|
|
101
|
-
["path"] = assetPath,
|
|
102
|
-
["name"] = asset.name,
|
|
103
|
-
["type"] = asset.GetType().Name,
|
|
104
|
-
["fullType"] = asset.GetType().FullName,
|
|
105
|
-
["instanceId"] = asset.GetInstanceID(),
|
|
106
|
-
["guid"] = AssetDatabase.AssetPathToGUID(assetPath)
|
|
107
|
-
};
|
|
108
|
-
|
|
109
|
-
// Add additional info for specific types
|
|
110
|
-
if (asset is GameObject go)
|
|
111
|
-
{
|
|
112
|
-
info["isPrefab"] = true;
|
|
113
|
-
var components = new List<string>();
|
|
114
|
-
foreach (var c in go.GetComponents<Component>())
|
|
115
|
-
{
|
|
116
|
-
if (c != null)
|
|
117
|
-
components.Add(c.GetType().Name);
|
|
118
|
-
}
|
|
119
|
-
info["components"] = components;
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
if (asset is ScriptableObject)
|
|
123
|
-
{
|
|
124
|
-
info["isScriptableObject"] = true;
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
return info;
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
private static object HandleReadScriptableObject(string paramsJson)
|
|
131
|
-
{
|
|
132
|
-
var p = MiniJson.Deserialize(paramsJson) as Dictionary<string, object>;
|
|
133
|
-
if (p == null || !p.TryGetValue("path", out var pathObj))
|
|
134
|
-
throw new ArgumentException("Missing 'path' parameter");
|
|
135
|
-
|
|
136
|
-
string assetPath = pathObj.ToString();
|
|
137
|
-
var asset = AssetDatabase.LoadAssetAtPath<UnityEngine.Object>(assetPath);
|
|
138
|
-
if (asset == null)
|
|
139
|
-
throw new ArgumentException($"Asset not found: {assetPath}");
|
|
140
|
-
|
|
141
|
-
// Optional: read specific field only
|
|
142
|
-
string fieldName = null;
|
|
143
|
-
if (p.TryGetValue("field", out var fObj) && fObj != null)
|
|
144
|
-
fieldName = fObj.ToString();
|
|
145
|
-
|
|
146
|
-
var so = new SerializedObject(asset);
|
|
147
|
-
var fields = new List<object>();
|
|
148
|
-
|
|
149
|
-
if (fieldName != null)
|
|
150
|
-
{
|
|
151
|
-
var prop = so.FindProperty(fieldName);
|
|
152
|
-
if (prop == null)
|
|
153
|
-
throw new ArgumentException($"Field '{fieldName}' not found on {asset.GetType().Name}");
|
|
154
|
-
|
|
155
|
-
fields.Add(new Dictionary<string, object>
|
|
156
|
-
{
|
|
157
|
-
["name"] = prop.name,
|
|
158
|
-
["displayName"] = prop.displayName,
|
|
159
|
-
["type"] = prop.propertyType.ToString(),
|
|
160
|
-
["value"] = ReadSerializedValue(prop)
|
|
161
|
-
});
|
|
162
|
-
}
|
|
163
|
-
else
|
|
164
|
-
{
|
|
165
|
-
var iter = so.GetIterator();
|
|
166
|
-
if (iter.NextVisible(true))
|
|
167
|
-
{
|
|
168
|
-
do
|
|
169
|
-
{
|
|
170
|
-
if (iter.name == "m_Script") continue;
|
|
171
|
-
fields.Add(new Dictionary<string, object>
|
|
172
|
-
{
|
|
173
|
-
["name"] = iter.name,
|
|
174
|
-
["displayName"] = iter.displayName,
|
|
175
|
-
["type"] = iter.propertyType.ToString(),
|
|
176
|
-
["value"] = ReadSerializedValue(iter)
|
|
177
|
-
});
|
|
178
|
-
}
|
|
179
|
-
while (iter.NextVisible(false));
|
|
180
|
-
}
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
so.Dispose();
|
|
184
|
-
|
|
185
|
-
return new Dictionary<string, object>
|
|
186
|
-
{
|
|
187
|
-
["path"] = assetPath,
|
|
188
|
-
["name"] = asset.name,
|
|
189
|
-
["type"] = asset.GetType().Name,
|
|
190
|
-
["fields"] = fields
|
|
191
|
-
};
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
private static object HandleWriteScriptableObject(string paramsJson)
|
|
195
|
-
{
|
|
196
|
-
var p = MiniJson.Deserialize(paramsJson) as Dictionary<string, object>;
|
|
197
|
-
if (p == null || !p.TryGetValue("path", out var pathObj))
|
|
198
|
-
throw new ArgumentException("Missing 'path' parameter");
|
|
199
|
-
if (!p.TryGetValue("field", out var fieldObj) || fieldObj == null)
|
|
200
|
-
throw new ArgumentException("Missing 'field' parameter");
|
|
201
|
-
if (!p.ContainsKey("value"))
|
|
202
|
-
throw new ArgumentException("Missing 'value' parameter");
|
|
203
|
-
|
|
204
|
-
string assetPath = pathObj.ToString();
|
|
205
|
-
var asset = AssetDatabase.LoadAssetAtPath<UnityEngine.Object>(assetPath);
|
|
206
|
-
if (asset == null)
|
|
207
|
-
throw new ArgumentException($"Asset not found: {assetPath}");
|
|
208
|
-
|
|
209
|
-
string fieldName = fieldObj.ToString();
|
|
210
|
-
var so = new SerializedObject(asset);
|
|
211
|
-
Undo.RecordObject(asset, $"UCP Write {fieldName}");
|
|
212
|
-
WriteFieldValue(so, asset, fieldName, p["value"]);
|
|
213
|
-
so.ApplyModifiedProperties();
|
|
214
|
-
EditorUtility.SetDirty(asset);
|
|
215
|
-
AssetDatabase.SaveAssetIfDirty(asset);
|
|
216
|
-
so.Dispose();
|
|
217
|
-
|
|
218
|
-
return new Dictionary<string, object>
|
|
219
|
-
{
|
|
220
|
-
["status"] = "ok",
|
|
221
|
-
["path"] = assetPath,
|
|
222
|
-
["field"] = fieldName
|
|
223
|
-
};
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
private static object HandleWriteScriptableObjectBatch(string paramsJson)
|
|
227
|
-
{
|
|
228
|
-
var p = MiniJson.Deserialize(paramsJson) as Dictionary<string, object>;
|
|
229
|
-
if (p == null || !p.TryGetValue("path", out var pathObj))
|
|
230
|
-
throw new ArgumentException("Missing 'path' parameter");
|
|
231
|
-
if (!p.TryGetValue("values", out var valuesObj) || !(valuesObj is Dictionary<string, object> values))
|
|
232
|
-
throw new ArgumentException("Missing 'values' parameter");
|
|
233
|
-
|
|
234
|
-
string assetPath = pathObj.ToString();
|
|
235
|
-
var asset = AssetDatabase.LoadAssetAtPath<UnityEngine.Object>(assetPath);
|
|
236
|
-
if (asset == null)
|
|
237
|
-
throw new ArgumentException($"Asset not found: {assetPath}");
|
|
238
|
-
|
|
239
|
-
var so = new SerializedObject(asset);
|
|
240
|
-
Undo.RecordObject(asset, $"UCP Batch Write {asset.name}");
|
|
241
|
-
|
|
242
|
-
var fields = new List<object>();
|
|
243
|
-
foreach (var entry in values)
|
|
244
|
-
{
|
|
245
|
-
WriteFieldValue(so, asset, entry.Key, entry.Value);
|
|
246
|
-
fields.Add(entry.Key);
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
so.ApplyModifiedProperties();
|
|
250
|
-
EditorUtility.SetDirty(asset);
|
|
251
|
-
AssetDatabase.SaveAssetIfDirty(asset);
|
|
252
|
-
so.Dispose();
|
|
253
|
-
|
|
254
|
-
return new Dictionary<string, object>
|
|
255
|
-
{
|
|
256
|
-
["status"] = "ok",
|
|
257
|
-
["path"] = assetPath,
|
|
258
|
-
["fields"] = fields
|
|
259
|
-
};
|
|
260
|
-
}
|
|
261
|
-
|
|
262
|
-
private static object HandleCreateScriptableObject(string paramsJson)
|
|
263
|
-
{
|
|
264
|
-
var p = MiniJson.Deserialize(paramsJson) as Dictionary<string, object>;
|
|
265
|
-
if (p == null || !p.TryGetValue("type", out var typeObj) || typeObj == null)
|
|
266
|
-
throw new ArgumentException("Missing 'type' parameter");
|
|
267
|
-
if (!p.TryGetValue("path", out var pathObj) || pathObj == null)
|
|
268
|
-
throw new ArgumentException("Missing 'path' parameter");
|
|
269
|
-
|
|
270
|
-
string typeName = typeObj.ToString();
|
|
271
|
-
string assetPath = pathObj.ToString();
|
|
272
|
-
|
|
273
|
-
// Resolve ScriptableObject type
|
|
274
|
-
Type soType = null;
|
|
275
|
-
foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies())
|
|
276
|
-
{
|
|
277
|
-
foreach (var t in assembly.GetTypes())
|
|
278
|
-
{
|
|
279
|
-
if (!typeof(ScriptableObject).IsAssignableFrom(t)) continue;
|
|
280
|
-
if (t.Name == typeName || t.FullName == typeName)
|
|
281
|
-
{
|
|
282
|
-
soType = t;
|
|
283
|
-
break;
|
|
284
|
-
}
|
|
285
|
-
}
|
|
286
|
-
if (soType != null) break;
|
|
287
|
-
}
|
|
288
|
-
|
|
289
|
-
if (soType == null)
|
|
290
|
-
throw new ArgumentException($"ScriptableObject type not found: {typeName}");
|
|
291
|
-
|
|
292
|
-
var instance = ScriptableObject.CreateInstance(soType);
|
|
293
|
-
|
|
294
|
-
// Ensure directory exists
|
|
295
|
-
string dir = System.IO.Path.GetDirectoryName(assetPath);
|
|
296
|
-
if (!string.IsNullOrEmpty(dir) && !AssetDatabase.IsValidFolder(dir))
|
|
297
|
-
{
|
|
298
|
-
CreateFoldersRecursive(dir);
|
|
299
|
-
}
|
|
300
|
-
|
|
301
|
-
AssetDatabase.CreateAsset(instance, assetPath);
|
|
302
|
-
AssetDatabase.SaveAssets();
|
|
303
|
-
|
|
304
|
-
return new Dictionary<string, object>
|
|
305
|
-
{
|
|
306
|
-
["status"] = "ok",
|
|
307
|
-
["path"] = assetPath,
|
|
308
|
-
["type"] = soType.Name,
|
|
309
|
-
["instanceId"] = instance.GetInstanceID()
|
|
310
|
-
};
|
|
311
|
-
}
|
|
312
|
-
|
|
313
|
-
private static void CreateFoldersRecursive(string path)
|
|
314
|
-
{
|
|
315
|
-
var parts = path.Replace("\\", "/").Split('/');
|
|
316
|
-
string current = parts[0];
|
|
317
|
-
for (int i = 1; i < parts.Length; i++)
|
|
318
|
-
{
|
|
319
|
-
string next = current + "/" + parts[i];
|
|
320
|
-
if (!AssetDatabase.IsValidFolder(next))
|
|
321
|
-
AssetDatabase.CreateFolder(current, parts[i]);
|
|
322
|
-
current = next;
|
|
323
|
-
}
|
|
324
|
-
}
|
|
325
|
-
|
|
326
|
-
private static IEnumerable<UnityEngine.Object> GetMatchingAssets(string assetPath, string typeFilter, string nameFilter)
|
|
327
|
-
{
|
|
328
|
-
UnityEngine.Object[] candidates;
|
|
329
|
-
if (string.IsNullOrEmpty(typeFilter) && string.IsNullOrEmpty(nameFilter))
|
|
330
|
-
{
|
|
331
|
-
var mainAsset = AssetDatabase.LoadMainAssetAtPath(assetPath);
|
|
332
|
-
candidates = mainAsset != null ? new[] { mainAsset } : Array.Empty<UnityEngine.Object>();
|
|
333
|
-
}
|
|
334
|
-
else
|
|
335
|
-
{
|
|
336
|
-
candidates = AssetDatabase.LoadAllAssetsAtPath(assetPath);
|
|
337
|
-
}
|
|
338
|
-
|
|
339
|
-
foreach (var candidate in candidates)
|
|
340
|
-
{
|
|
341
|
-
if (candidate == null) continue;
|
|
342
|
-
if (!MatchesName(candidate, assetPath, nameFilter)) continue;
|
|
343
|
-
if (!MatchesType(candidate, assetPath, typeFilter)) continue;
|
|
344
|
-
yield return candidate;
|
|
345
|
-
}
|
|
346
|
-
}
|
|
347
|
-
|
|
348
|
-
private static bool MatchesName(UnityEngine.Object asset, string assetPath, string nameFilter)
|
|
349
|
-
{
|
|
350
|
-
if (string.IsNullOrEmpty(nameFilter))
|
|
351
|
-
return true;
|
|
352
|
-
|
|
353
|
-
return asset.name.Contains(nameFilter, StringComparison.OrdinalIgnoreCase)
|
|
354
|
-
|| System.IO.Path.GetFileNameWithoutExtension(assetPath).Contains(nameFilter, StringComparison.OrdinalIgnoreCase);
|
|
355
|
-
}
|
|
356
|
-
|
|
357
|
-
private static bool MatchesType(UnityEngine.Object asset, string assetPath, string typeFilter)
|
|
358
|
-
{
|
|
359
|
-
if (string.IsNullOrEmpty(typeFilter))
|
|
360
|
-
return true;
|
|
361
|
-
|
|
362
|
-
if (typeFilter.Equals("Prefab", StringComparison.OrdinalIgnoreCase))
|
|
363
|
-
{
|
|
364
|
-
return asset is GameObject
|
|
365
|
-
&& !AssetDatabase.IsSubAsset(asset)
|
|
366
|
-
&& assetPath.EndsWith(".prefab", StringComparison.OrdinalIgnoreCase);
|
|
367
|
-
}
|
|
368
|
-
|
|
369
|
-
var normalizedType = NormalizeTypeFilter(typeFilter);
|
|
370
|
-
var assetType = asset.GetType();
|
|
371
|
-
return assetType.Name.Equals(normalizedType, StringComparison.OrdinalIgnoreCase)
|
|
372
|
-
|| (assetType.FullName != null && assetType.FullName.Equals(normalizedType, StringComparison.OrdinalIgnoreCase));
|
|
373
|
-
}
|
|
374
|
-
|
|
375
|
-
private static string GetDisplayType(string assetPath, UnityEngine.Object asset)
|
|
376
|
-
{
|
|
377
|
-
if (asset is GameObject
|
|
378
|
-
&& !AssetDatabase.IsSubAsset(asset)
|
|
379
|
-
&& assetPath.EndsWith(".prefab", StringComparison.OrdinalIgnoreCase))
|
|
380
|
-
{
|
|
381
|
-
return "Prefab";
|
|
382
|
-
}
|
|
383
|
-
|
|
384
|
-
return asset.GetType().Name;
|
|
385
|
-
}
|
|
386
|
-
|
|
387
|
-
private static string GetSearchTypeFilter(string typeFilter)
|
|
388
|
-
{
|
|
389
|
-
if (typeFilter.Equals("Prefab", StringComparison.OrdinalIgnoreCase))
|
|
390
|
-
return "GameObject";
|
|
391
|
-
|
|
392
|
-
return NormalizeTypeFilter(typeFilter);
|
|
393
|
-
}
|
|
394
|
-
|
|
395
|
-
private static string NormalizeTypeFilter(string typeFilter)
|
|
396
|
-
{
|
|
397
|
-
return typeFilter?.Trim() ?? string.Empty;
|
|
398
|
-
}
|
|
399
|
-
|
|
400
|
-
// ---- Serialized property value reading/writing ----
|
|
401
|
-
|
|
402
|
-
private static object ReadSerializedValue(SerializedProperty prop)
|
|
403
|
-
{
|
|
404
|
-
switch (prop.propertyType)
|
|
405
|
-
{
|
|
406
|
-
case SerializedPropertyType.Integer: return prop.intValue;
|
|
407
|
-
case SerializedPropertyType.Boolean: return prop.boolValue;
|
|
408
|
-
case SerializedPropertyType.Float: return (double)prop.floatValue;
|
|
409
|
-
case SerializedPropertyType.String: return prop.stringValue;
|
|
410
|
-
case SerializedPropertyType.Color:
|
|
411
|
-
var c = prop.colorValue;
|
|
412
|
-
return new List<object> { (double)c.r, (double)c.g, (double)c.b, (double)c.a };
|
|
413
|
-
case SerializedPropertyType.ObjectReference:
|
|
414
|
-
return ObjectReferenceResolver.Serialize(prop.objectReferenceValue);
|
|
415
|
-
case SerializedPropertyType.Enum:
|
|
416
|
-
return prop.enumValueIndex < prop.enumDisplayNames.Length
|
|
417
|
-
? prop.enumDisplayNames[prop.enumValueIndex]
|
|
418
|
-
: prop.enumValueIndex.ToString();
|
|
419
|
-
case SerializedPropertyType.Vector2:
|
|
420
|
-
var v2 = prop.vector2Value;
|
|
421
|
-
return new List<object> { (double)v2.x, (double)v2.y };
|
|
422
|
-
case SerializedPropertyType.Vector3:
|
|
423
|
-
var v3 = prop.vector3Value;
|
|
424
|
-
return new List<object> { (double)v3.x, (double)v3.y, (double)v3.z };
|
|
425
|
-
case SerializedPropertyType.Vector4:
|
|
426
|
-
var v4 = prop.vector4Value;
|
|
427
|
-
return new List<object> { (double)v4.x, (double)v4.y, (double)v4.z, (double)v4.w };
|
|
428
|
-
case SerializedPropertyType.Quaternion:
|
|
429
|
-
var q = prop.quaternionValue;
|
|
430
|
-
return new List<object> { (double)q.x, (double)q.y, (double)q.z, (double)q.w };
|
|
431
|
-
case SerializedPropertyType.Rect:
|
|
432
|
-
var r = prop.rectValue;
|
|
433
|
-
return new Dictionary<string, object>
|
|
434
|
-
{
|
|
435
|
-
["x"] = (double)r.x,
|
|
436
|
-
["y"] = (double)r.y,
|
|
437
|
-
["width"] = (double)r.width,
|
|
438
|
-
["height"] = (double)r.height
|
|
439
|
-
};
|
|
440
|
-
case SerializedPropertyType.Bounds:
|
|
441
|
-
var b = prop.boundsValue;
|
|
442
|
-
return new Dictionary<string, object>
|
|
443
|
-
{
|
|
444
|
-
["center"] = new List<object> { (double)b.center.x, (double)b.center.y, (double)b.center.z },
|
|
445
|
-
["size"] = new List<object> { (double)b.size.x, (double)b.size.y, (double)b.size.z }
|
|
446
|
-
};
|
|
447
|
-
case SerializedPropertyType.ArraySize:
|
|
448
|
-
return prop.intValue;
|
|
449
|
-
case SerializedPropertyType.LayerMask:
|
|
450
|
-
return prop.intValue;
|
|
451
|
-
default:
|
|
452
|
-
return $"<{prop.propertyType}>";
|
|
453
|
-
}
|
|
454
|
-
}
|
|
455
|
-
|
|
456
|
-
private static void WriteSerializedValue(SerializedProperty prop, object value)
|
|
457
|
-
{
|
|
458
|
-
switch (prop.propertyType)
|
|
459
|
-
{
|
|
460
|
-
case SerializedPropertyType.Integer:
|
|
461
|
-
prop.intValue = Convert.ToInt32(value);
|
|
462
|
-
break;
|
|
463
|
-
case SerializedPropertyType.Boolean:
|
|
464
|
-
prop.boolValue = Convert.ToBoolean(value);
|
|
465
|
-
break;
|
|
466
|
-
case SerializedPropertyType.Float:
|
|
467
|
-
prop.floatValue = Convert.ToSingle(value);
|
|
468
|
-
break;
|
|
469
|
-
case SerializedPropertyType.String:
|
|
470
|
-
prop.stringValue = value?.ToString() ?? "";
|
|
471
|
-
break;
|
|
472
|
-
case SerializedPropertyType.Color:
|
|
473
|
-
if (value is List<object> cArr && cArr.Count >= 3)
|
|
474
|
-
prop.colorValue = new Color(
|
|
475
|
-
Convert.ToSingle(cArr[0]),
|
|
476
|
-
Convert.ToSingle(cArr[1]),
|
|
477
|
-
Convert.ToSingle(cArr[2]),
|
|
478
|
-
cArr.Count >= 4 ? Convert.ToSingle(cArr[3]) : 1f);
|
|
479
|
-
break;
|
|
480
|
-
case SerializedPropertyType.Enum:
|
|
481
|
-
if (value is string enumStr)
|
|
482
|
-
{
|
|
483
|
-
int idx = Array.IndexOf(prop.enumDisplayNames, enumStr);
|
|
484
|
-
if (idx >= 0) prop.enumValueIndex = idx;
|
|
485
|
-
else if (int.TryParse(enumStr, out int enumIdx)) prop.enumValueIndex = enumIdx;
|
|
486
|
-
}
|
|
487
|
-
else
|
|
488
|
-
{
|
|
489
|
-
prop.enumValueIndex = Convert.ToInt32(value);
|
|
490
|
-
}
|
|
491
|
-
break;
|
|
492
|
-
case SerializedPropertyType.Vector2:
|
|
493
|
-
if (value is List<object> v2 && v2.Count >= 2)
|
|
494
|
-
prop.vector2Value = new Vector2(Convert.ToSingle(v2[0]), Convert.ToSingle(v2[1]));
|
|
495
|
-
break;
|
|
496
|
-
case SerializedPropertyType.Vector3:
|
|
497
|
-
if (value is List<object> v3 && v3.Count >= 3)
|
|
498
|
-
prop.vector3Value = new Vector3(Convert.ToSingle(v3[0]), Convert.ToSingle(v3[1]), Convert.ToSingle(v3[2]));
|
|
499
|
-
break;
|
|
500
|
-
case SerializedPropertyType.Vector4:
|
|
501
|
-
if (value is List<object> v4 && v4.Count >= 4)
|
|
502
|
-
prop.vector4Value = new Vector4(Convert.ToSingle(v4[0]), Convert.ToSingle(v4[1]), Convert.ToSingle(v4[2]), Convert.ToSingle(v4[3]));
|
|
503
|
-
break;
|
|
504
|
-
case SerializedPropertyType.Quaternion:
|
|
505
|
-
if (value is List<object> qArr && qArr.Count >= 4)
|
|
506
|
-
prop.quaternionValue = new Quaternion(Convert.ToSingle(qArr[0]), Convert.ToSingle(qArr[1]), Convert.ToSingle(qArr[2]), Convert.ToSingle(qArr[3]));
|
|
507
|
-
break;
|
|
508
|
-
case SerializedPropertyType.ObjectReference:
|
|
509
|
-
prop.objectReferenceValue = ObjectReferenceResolver.Resolve(value, prop.displayName);
|
|
510
|
-
if (value != null && prop.objectReferenceValue == null)
|
|
511
|
-
throw new ArgumentException($"Unable to assign object reference to '{prop.displayName}'");
|
|
512
|
-
break;
|
|
513
|
-
case SerializedPropertyType.LayerMask:
|
|
514
|
-
prop.intValue = Convert.ToInt32(value);
|
|
515
|
-
break;
|
|
516
|
-
default:
|
|
517
|
-
throw new ArgumentException($"Cannot write property of type {prop.propertyType}");
|
|
518
|
-
}
|
|
519
|
-
}
|
|
520
|
-
|
|
521
|
-
private static void WriteFieldValue(SerializedObject serializedObject, UnityEngine.Object asset, string fieldName, object value)
|
|
522
|
-
{
|
|
523
|
-
var prop = serializedObject.FindProperty(fieldName);
|
|
524
|
-
if (prop == null)
|
|
525
|
-
throw new ArgumentException($"Field '{fieldName}' not found on {asset.GetType().Name}");
|
|
526
|
-
|
|
527
|
-
WriteSerializedValue(prop, value);
|
|
528
|
-
}
|
|
529
|
-
}
|
|
530
|
-
}
|