@mflrevan/ucp 0.4.0 → 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 +2 -2
- package/package.json +8 -2
- package/bridge/com.ucp.bridge/CHANGELOG.md +0 -128
- 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 -145
- 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 -269
- 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 -670
- 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,269 +0,0 @@
|
|
|
1
|
-
using System.Collections.Generic;
|
|
2
|
-
using UnityEditor;
|
|
3
|
-
using UnityEditor.SceneManagement;
|
|
4
|
-
using UnityEngine;
|
|
5
|
-
using UnityEngine.SceneManagement;
|
|
6
|
-
|
|
7
|
-
namespace UCP.Bridge
|
|
8
|
-
{
|
|
9
|
-
public static class SceneController
|
|
10
|
-
{
|
|
11
|
-
public static void Register(CommandRouter router)
|
|
12
|
-
{
|
|
13
|
-
router.Register("scene/list", HandleList);
|
|
14
|
-
router.Register("scene/load", HandleLoad);
|
|
15
|
-
router.Register("scene/active", HandleActive);
|
|
16
|
-
router.Register("scene/focus", HandleFocus);
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
private static object HandleList(string paramsJson)
|
|
20
|
-
{
|
|
21
|
-
var scenes = new List<object>();
|
|
22
|
-
|
|
23
|
-
for (int i = 0; i < EditorBuildSettings.scenes.Length; i++)
|
|
24
|
-
{
|
|
25
|
-
var s = EditorBuildSettings.scenes[i];
|
|
26
|
-
scenes.Add(new Dictionary<string, object>
|
|
27
|
-
{
|
|
28
|
-
["index"] = i,
|
|
29
|
-
["path"] = s.path,
|
|
30
|
-
["enabled"] = s.enabled,
|
|
31
|
-
["guid"] = s.guid.ToString()
|
|
32
|
-
});
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
return new Dictionary<string, object> { ["scenes"] = scenes };
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
private static object HandleLoad(string paramsJson)
|
|
39
|
-
{
|
|
40
|
-
var p = MiniJson.Deserialize(paramsJson) as Dictionary<string, object>;
|
|
41
|
-
if (p == null || !p.TryGetValue("path", out var pathObj))
|
|
42
|
-
throw new System.ArgumentException("Missing 'path' parameter");
|
|
43
|
-
|
|
44
|
-
var path = pathObj.ToString();
|
|
45
|
-
var saveDirtyScenes = GetBoolParam(p, "saveDirtyScenes", true);
|
|
46
|
-
var discardUntitled = GetBoolParam(p, "discardUntitled", true);
|
|
47
|
-
|
|
48
|
-
if (EditorApplication.isPlaying)
|
|
49
|
-
{
|
|
50
|
-
SceneManager.LoadScene(path);
|
|
51
|
-
}
|
|
52
|
-
else
|
|
53
|
-
{
|
|
54
|
-
SaveDirtyScenesIfRequested(saveDirtyScenes, discardUntitled);
|
|
55
|
-
EditorSceneManager.OpenScene(path, OpenSceneMode.Single);
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
return new { status = "ok", loaded = path };
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
private static bool GetBoolParam(Dictionary<string, object> parameters, string key, bool defaultValue)
|
|
62
|
-
{
|
|
63
|
-
if (parameters != null && parameters.TryGetValue(key, out var valueObj) && valueObj is bool value)
|
|
64
|
-
return value;
|
|
65
|
-
|
|
66
|
-
return defaultValue;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
private static void SaveDirtyScenesIfRequested(bool saveDirtyScenes, bool discardUntitled)
|
|
70
|
-
{
|
|
71
|
-
if (!saveDirtyScenes)
|
|
72
|
-
return;
|
|
73
|
-
|
|
74
|
-
var requiresUntitledDiscard = false;
|
|
75
|
-
|
|
76
|
-
for (var index = 0; index < SceneManager.sceneCount; index++)
|
|
77
|
-
{
|
|
78
|
-
var scene = SceneManager.GetSceneAt(index);
|
|
79
|
-
if (!scene.isLoaded || !scene.isDirty)
|
|
80
|
-
continue;
|
|
81
|
-
|
|
82
|
-
if (string.IsNullOrEmpty(scene.path))
|
|
83
|
-
{
|
|
84
|
-
if (!discardUntitled)
|
|
85
|
-
throw new System.InvalidOperationException("Dirty untitled scene cannot be auto-saved. Retry with discardUntitled=true.");
|
|
86
|
-
|
|
87
|
-
requiresUntitledDiscard = true;
|
|
88
|
-
continue;
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
if (!EditorSceneManager.SaveScene(scene))
|
|
92
|
-
throw new System.InvalidOperationException($"Failed to auto-save dirty scene: {scene.path}");
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
if (requiresUntitledDiscard)
|
|
96
|
-
EditorSceneManager.NewScene(NewSceneSetup.EmptyScene, NewSceneMode.Single);
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
private static object HandleActive(string paramsJson)
|
|
100
|
-
{
|
|
101
|
-
var scene = SceneManager.GetActiveScene();
|
|
102
|
-
return new Dictionary<string, object>
|
|
103
|
-
{
|
|
104
|
-
["name"] = scene.name,
|
|
105
|
-
["path"] = scene.path,
|
|
106
|
-
["buildIndex"] = scene.buildIndex,
|
|
107
|
-
["isDirty"] = scene.isDirty,
|
|
108
|
-
["isLoaded"] = scene.isLoaded,
|
|
109
|
-
["rootCount"] = scene.rootCount
|
|
110
|
-
};
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
private static object HandleFocus(string paramsJson)
|
|
114
|
-
{
|
|
115
|
-
var parameters = MiniJson.Deserialize(paramsJson) as Dictionary<string, object>;
|
|
116
|
-
if (parameters == null || !parameters.TryGetValue("instanceId", out var idObj))
|
|
117
|
-
throw new System.ArgumentException("Missing 'instanceId' parameter");
|
|
118
|
-
|
|
119
|
-
var instanceId = System.Convert.ToInt32(idObj);
|
|
120
|
-
var target = FindGameObject(instanceId);
|
|
121
|
-
var bounds = CalculateFocusBounds(target);
|
|
122
|
-
var sceneView = SceneView.lastActiveSceneView ?? EditorWindow.GetWindow<SceneView>();
|
|
123
|
-
|
|
124
|
-
if (sceneView == null)
|
|
125
|
-
throw new System.InvalidOperationException("Unable to open Scene view");
|
|
126
|
-
|
|
127
|
-
sceneView.Show();
|
|
128
|
-
sceneView.Focus();
|
|
129
|
-
Selection.activeGameObject = target;
|
|
130
|
-
|
|
131
|
-
var focusPoint = bounds.center;
|
|
132
|
-
var focusSize = Mathf.Max(bounds.extents.magnitude * 2f, 1f);
|
|
133
|
-
var axis = TryReadAxis(parameters);
|
|
134
|
-
|
|
135
|
-
if (axis.HasValue)
|
|
136
|
-
{
|
|
137
|
-
var normalizedAxis = axis.Value.normalized;
|
|
138
|
-
var rotation = Quaternion.LookRotation(-normalizedAxis, SelectUpVector(normalizedAxis));
|
|
139
|
-
sceneView.LookAtDirect(focusPoint, rotation, focusSize);
|
|
140
|
-
}
|
|
141
|
-
else
|
|
142
|
-
{
|
|
143
|
-
sceneView.LookAtDirect(focusPoint, sceneView.rotation, focusSize);
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
sceneView.Repaint();
|
|
147
|
-
SceneView.RepaintAll();
|
|
148
|
-
|
|
149
|
-
return new Dictionary<string, object>
|
|
150
|
-
{
|
|
151
|
-
["status"] = "ok",
|
|
152
|
-
["instanceId"] = instanceId,
|
|
153
|
-
["name"] = target.name,
|
|
154
|
-
["pivot"] = VectorToList(sceneView.pivot),
|
|
155
|
-
["cameraPosition"] = VectorToList(sceneView.camera.transform.position),
|
|
156
|
-
["cameraRotationEuler"] = VectorToList(sceneView.camera.transform.rotation.eulerAngles),
|
|
157
|
-
["size"] = sceneView.size,
|
|
158
|
-
["axis"] = axis.HasValue ? VectorToList(axis.Value.normalized) : null
|
|
159
|
-
};
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
private static Vector3? TryReadAxis(Dictionary<string, object> parameters)
|
|
163
|
-
{
|
|
164
|
-
if (parameters == null || !parameters.TryGetValue("axis", out var axisObj) || axisObj == null)
|
|
165
|
-
return null;
|
|
166
|
-
|
|
167
|
-
if (axisObj is not List<object> values || values.Count != 3)
|
|
168
|
-
throw new System.ArgumentException("axis must be an array of exactly three numeric values");
|
|
169
|
-
|
|
170
|
-
var axis = new Vector3(
|
|
171
|
-
System.Convert.ToSingle(values[0]),
|
|
172
|
-
System.Convert.ToSingle(values[1]),
|
|
173
|
-
System.Convert.ToSingle(values[2]));
|
|
174
|
-
|
|
175
|
-
if (axis.sqrMagnitude < 0.0001f)
|
|
176
|
-
throw new System.ArgumentException("axis must not be the zero vector");
|
|
177
|
-
|
|
178
|
-
return axis;
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
private static Vector3 SelectUpVector(Vector3 axis)
|
|
182
|
-
{
|
|
183
|
-
if (Mathf.Abs(Vector3.Dot(axis, Vector3.up)) > 0.98f)
|
|
184
|
-
return Vector3.forward;
|
|
185
|
-
|
|
186
|
-
return Vector3.up;
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
private static Bounds CalculateFocusBounds(GameObject target)
|
|
190
|
-
{
|
|
191
|
-
var hasBounds = false;
|
|
192
|
-
var bounds = new Bounds(target.transform.position, Vector3.one);
|
|
193
|
-
|
|
194
|
-
foreach (var renderer in target.GetComponentsInChildren<Renderer>())
|
|
195
|
-
{
|
|
196
|
-
if (!hasBounds)
|
|
197
|
-
{
|
|
198
|
-
bounds = renderer.bounds;
|
|
199
|
-
hasBounds = true;
|
|
200
|
-
}
|
|
201
|
-
else
|
|
202
|
-
{
|
|
203
|
-
bounds.Encapsulate(renderer.bounds);
|
|
204
|
-
}
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
foreach (var collider in target.GetComponentsInChildren<Collider>())
|
|
208
|
-
{
|
|
209
|
-
if (!hasBounds)
|
|
210
|
-
{
|
|
211
|
-
bounds = collider.bounds;
|
|
212
|
-
hasBounds = true;
|
|
213
|
-
}
|
|
214
|
-
else
|
|
215
|
-
{
|
|
216
|
-
bounds.Encapsulate(collider.bounds);
|
|
217
|
-
}
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
if (!hasBounds)
|
|
221
|
-
bounds = new Bounds(target.transform.position, Vector3.one);
|
|
222
|
-
|
|
223
|
-
return bounds;
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
private static GameObject FindGameObject(int instanceId)
|
|
227
|
-
{
|
|
228
|
-
var direct = EditorUtility.InstanceIDToObject(instanceId) as GameObject;
|
|
229
|
-
if (direct != null)
|
|
230
|
-
return direct;
|
|
231
|
-
|
|
232
|
-
for (var index = 0; index < SceneManager.sceneCount; index++)
|
|
233
|
-
{
|
|
234
|
-
var scene = SceneManager.GetSceneAt(index);
|
|
235
|
-
if (!scene.isLoaded)
|
|
236
|
-
continue;
|
|
237
|
-
|
|
238
|
-
foreach (var root in scene.GetRootGameObjects())
|
|
239
|
-
{
|
|
240
|
-
var found = FindInHierarchy(root, instanceId);
|
|
241
|
-
if (found != null)
|
|
242
|
-
return found;
|
|
243
|
-
}
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
throw new System.ArgumentException($"GameObject not found: {instanceId}");
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
private static GameObject FindInHierarchy(GameObject gameObject, int instanceId)
|
|
250
|
-
{
|
|
251
|
-
if (gameObject.GetInstanceID() == instanceId)
|
|
252
|
-
return gameObject;
|
|
253
|
-
|
|
254
|
-
foreach (Transform child in gameObject.transform)
|
|
255
|
-
{
|
|
256
|
-
var found = FindInHierarchy(child.gameObject, instanceId);
|
|
257
|
-
if (found != null)
|
|
258
|
-
return found;
|
|
259
|
-
}
|
|
260
|
-
|
|
261
|
-
return null;
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
private static List<object> VectorToList(Vector3 value)
|
|
265
|
-
{
|
|
266
|
-
return new List<object> { value.x, value.y, value.z };
|
|
267
|
-
}
|
|
268
|
-
}
|
|
269
|
-
}
|
|
@@ -1,125 +0,0 @@
|
|
|
1
|
-
using System;
|
|
2
|
-
using System.Collections.Generic;
|
|
3
|
-
using UnityEngine;
|
|
4
|
-
using UnityEditor;
|
|
5
|
-
|
|
6
|
-
namespace UCP.Bridge
|
|
7
|
-
{
|
|
8
|
-
public static class ScreenshotController
|
|
9
|
-
{
|
|
10
|
-
public static void Register(CommandRouter router)
|
|
11
|
-
{
|
|
12
|
-
router.Register("screenshot", HandleScreenshot);
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
private static object HandleScreenshot(string paramsJson)
|
|
16
|
-
{
|
|
17
|
-
var p = MiniJson.Deserialize(paramsJson) as Dictionary<string, object>;
|
|
18
|
-
int width = 1920, height = 1080;
|
|
19
|
-
string view = "game";
|
|
20
|
-
|
|
21
|
-
if (p != null)
|
|
22
|
-
{
|
|
23
|
-
if (p.TryGetValue("width", out var w)) width = Convert.ToInt32(w);
|
|
24
|
-
if (p.TryGetValue("height", out var h)) height = Convert.ToInt32(h);
|
|
25
|
-
if (p.TryGetValue("view", out var v)) view = v?.ToString() ?? "game";
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
// Clamp dimensions for safety
|
|
29
|
-
width = Mathf.Clamp(width, 64, 7680);
|
|
30
|
-
height = Mathf.Clamp(height, 64, 4320);
|
|
31
|
-
|
|
32
|
-
byte[] png;
|
|
33
|
-
|
|
34
|
-
if (view == "game")
|
|
35
|
-
{
|
|
36
|
-
png = CaptureGameView(width, height);
|
|
37
|
-
}
|
|
38
|
-
else
|
|
39
|
-
{
|
|
40
|
-
// Scene view capture
|
|
41
|
-
png = CaptureSceneView(width, height);
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
if (png == null || png.Length == 0)
|
|
45
|
-
{
|
|
46
|
-
throw new Exception("Screenshot capture failed — no camera available");
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
string base64 = Convert.ToBase64String(png);
|
|
50
|
-
|
|
51
|
-
return new Dictionary<string, object>
|
|
52
|
-
{
|
|
53
|
-
["width"] = width,
|
|
54
|
-
["height"] = height,
|
|
55
|
-
["format"] = "png",
|
|
56
|
-
["encoding"] = "base64",
|
|
57
|
-
["data"] = base64,
|
|
58
|
-
["size"] = png.Length
|
|
59
|
-
};
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
private static byte[] CaptureGameView(int width, int height)
|
|
63
|
-
{
|
|
64
|
-
var camera = Camera.main;
|
|
65
|
-
if (camera == null)
|
|
66
|
-
{
|
|
67
|
-
// Try to find any camera
|
|
68
|
-
camera = UnityEngine.Object.FindAnyObjectByType<Camera>();
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
if (camera == null)
|
|
72
|
-
throw new Exception("No camera found in scene");
|
|
73
|
-
|
|
74
|
-
var rt = new RenderTexture(width, height, 24);
|
|
75
|
-
var prevTarget = camera.targetTexture;
|
|
76
|
-
|
|
77
|
-
camera.targetTexture = rt;
|
|
78
|
-
camera.Render();
|
|
79
|
-
|
|
80
|
-
RenderTexture.active = rt;
|
|
81
|
-
var texture = new Texture2D(width, height, TextureFormat.RGB24, false);
|
|
82
|
-
texture.ReadPixels(new Rect(0, 0, width, height), 0, 0);
|
|
83
|
-
texture.Apply();
|
|
84
|
-
|
|
85
|
-
camera.targetTexture = prevTarget;
|
|
86
|
-
RenderTexture.active = null;
|
|
87
|
-
|
|
88
|
-
byte[] png = texture.EncodeToPNG();
|
|
89
|
-
|
|
90
|
-
UnityEngine.Object.DestroyImmediate(rt);
|
|
91
|
-
UnityEngine.Object.DestroyImmediate(texture);
|
|
92
|
-
|
|
93
|
-
return png;
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
private static byte[] CaptureSceneView(int width, int height)
|
|
97
|
-
{
|
|
98
|
-
var sceneView = SceneView.lastActiveSceneView;
|
|
99
|
-
if (sceneView == null || sceneView.camera == null)
|
|
100
|
-
throw new Exception("No active Scene view");
|
|
101
|
-
|
|
102
|
-
var camera = sceneView.camera;
|
|
103
|
-
var rt = new RenderTexture(width, height, 24);
|
|
104
|
-
var prevTarget = camera.targetTexture;
|
|
105
|
-
|
|
106
|
-
camera.targetTexture = rt;
|
|
107
|
-
camera.Render();
|
|
108
|
-
|
|
109
|
-
RenderTexture.active = rt;
|
|
110
|
-
var texture = new Texture2D(width, height, TextureFormat.RGB24, false);
|
|
111
|
-
texture.ReadPixels(new Rect(0, 0, width, height), 0, 0);
|
|
112
|
-
texture.Apply();
|
|
113
|
-
|
|
114
|
-
camera.targetTexture = prevTarget;
|
|
115
|
-
RenderTexture.active = null;
|
|
116
|
-
|
|
117
|
-
byte[] png = texture.EncodeToPNG();
|
|
118
|
-
|
|
119
|
-
UnityEngine.Object.DestroyImmediate(rt);
|
|
120
|
-
UnityEngine.Object.DestroyImmediate(texture);
|
|
121
|
-
|
|
122
|
-
return png;
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
}
|
|
@@ -1,104 +0,0 @@
|
|
|
1
|
-
using System;
|
|
2
|
-
using System.Collections.Generic;
|
|
3
|
-
using UnityEngine;
|
|
4
|
-
|
|
5
|
-
namespace UCP.Bridge
|
|
6
|
-
{
|
|
7
|
-
public static class ScriptController
|
|
8
|
-
{
|
|
9
|
-
public static void Register(CommandRouter router)
|
|
10
|
-
{
|
|
11
|
-
router.Register("exec/list", HandleList);
|
|
12
|
-
router.Register("exec/run", HandleRun);
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
private static List<IUCPScript> DiscoverScripts()
|
|
16
|
-
{
|
|
17
|
-
var scripts = new List<IUCPScript>();
|
|
18
|
-
var interfaceType = typeof(IUCPScript);
|
|
19
|
-
|
|
20
|
-
foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies())
|
|
21
|
-
{
|
|
22
|
-
try
|
|
23
|
-
{
|
|
24
|
-
foreach (var type in assembly.GetTypes())
|
|
25
|
-
{
|
|
26
|
-
if (interfaceType.IsAssignableFrom(type) && !type.IsAbstract && !type.IsInterface)
|
|
27
|
-
{
|
|
28
|
-
try
|
|
29
|
-
{
|
|
30
|
-
var instance = (IUCPScript)Activator.CreateInstance(type);
|
|
31
|
-
scripts.Add(instance);
|
|
32
|
-
}
|
|
33
|
-
catch (Exception ex)
|
|
34
|
-
{
|
|
35
|
-
Debug.LogWarning($"[UCP] Failed to instantiate script {type.Name}: {ex.Message}");
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
catch (System.Reflection.ReflectionTypeLoadException)
|
|
41
|
-
{
|
|
42
|
-
// Some assemblies can't be scanned — skip silently
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
return scripts;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
private static object HandleList(string paramsJson)
|
|
50
|
-
{
|
|
51
|
-
var scripts = DiscoverScripts();
|
|
52
|
-
var result = new List<object>();
|
|
53
|
-
|
|
54
|
-
foreach (var s in scripts)
|
|
55
|
-
{
|
|
56
|
-
result.Add(new Dictionary<string, object>
|
|
57
|
-
{
|
|
58
|
-
["name"] = s.Name,
|
|
59
|
-
["description"] = s.Description
|
|
60
|
-
});
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
return new Dictionary<string, object>
|
|
64
|
-
{
|
|
65
|
-
["scripts"] = result,
|
|
66
|
-
["count"] = result.Count
|
|
67
|
-
};
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
private static object HandleRun(string paramsJson)
|
|
71
|
-
{
|
|
72
|
-
var p = MiniJson.Deserialize(paramsJson) as Dictionary<string, object>;
|
|
73
|
-
if (p == null || !p.TryGetValue("name", out var nameObj))
|
|
74
|
-
throw new ArgumentException("Missing 'name' parameter");
|
|
75
|
-
|
|
76
|
-
var name = nameObj.ToString();
|
|
77
|
-
var scriptParams = "{}";
|
|
78
|
-
if (p.TryGetValue("params", out var paramsObj) && paramsObj != null)
|
|
79
|
-
scriptParams = MiniJson.Serialize(paramsObj);
|
|
80
|
-
|
|
81
|
-
var scripts = DiscoverScripts();
|
|
82
|
-
IUCPScript target = null;
|
|
83
|
-
foreach (var s in scripts)
|
|
84
|
-
{
|
|
85
|
-
if (string.Equals(s.Name, name, StringComparison.OrdinalIgnoreCase))
|
|
86
|
-
{
|
|
87
|
-
target = s;
|
|
88
|
-
break;
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
if (target == null)
|
|
93
|
-
throw new ArgumentException($"Script not found: {name}. Use exec/list to see available scripts.");
|
|
94
|
-
|
|
95
|
-
var result = target.Execute(scriptParams);
|
|
96
|
-
|
|
97
|
-
return new Dictionary<string, object>
|
|
98
|
-
{
|
|
99
|
-
["script"] = name,
|
|
100
|
-
["result"] = result
|
|
101
|
-
};
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
}
|