@scenoco-three/unity 0.9.8 → 1.0.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.
- package/README.md +21 -5
- package/dist/cli.js +9 -2
- package/dist/convert.d.ts +35 -5
- package/dist/convert.js +74 -17
- package/dist/export.d.ts +33 -4
- package/dist/export.js +122 -7
- package/dist/input.d.ts +14 -0
- package/dist/input.js +73 -0
- package/dist/page.d.ts +25 -0
- package/dist/page.js +347 -0
- package/dist/stub.d.ts +45 -0
- package/dist/stub.js +324 -0
- package/package.json +4 -3
- package/unity/Driver/SceNoCo.Driver.asmdef +32 -0
- package/unity/Driver/SceNoCoDriver.cs +697 -0
- package/unity/KeepAcrossScenes.cs +25 -0
- package/unity/PORTING.md +153 -0
- package/unity/SceNoCoImporter.cs +322 -13
|
@@ -0,0 +1,697 @@
|
|
|
1
|
+
// Drives the game in the Editor's Play mode the way window.__scenoco drives it on the web: a held
|
|
2
|
+
// clock that steps exact frames, input as the player's, and the game's state read by class and name.
|
|
3
|
+
// Commands for Unity's CLI (com.unity.pipeline): `unity command scenoco.help` says how to call them.
|
|
4
|
+
//
|
|
5
|
+
// Written into the project by scenoco-unity, and again by every export: edit it there, not here.
|
|
6
|
+
using System;
|
|
7
|
+
using System.Collections;
|
|
8
|
+
using System.Collections.Concurrent;
|
|
9
|
+
using System.Collections.Generic;
|
|
10
|
+
using System.Globalization;
|
|
11
|
+
using System.Linq;
|
|
12
|
+
using System.Reflection;
|
|
13
|
+
using System.Text;
|
|
14
|
+
using System.Threading;
|
|
15
|
+
using Unity.Pipeline.Commands;
|
|
16
|
+
using UnityEditor;
|
|
17
|
+
using UnityEngine;
|
|
18
|
+
using UnityEngine.LowLevel;
|
|
19
|
+
using UnityEngine.PlayerLoop;
|
|
20
|
+
using UnityEngine.SceneManagement;
|
|
21
|
+
#if SCENOCO_INPUT_SYSTEM
|
|
22
|
+
using UnityEngine.InputSystem;
|
|
23
|
+
using UnityEngine.InputSystem.LowLevel;
|
|
24
|
+
#endif
|
|
25
|
+
|
|
26
|
+
namespace SceNoCo.Driver
|
|
27
|
+
{
|
|
28
|
+
[InitializeOnLoad]
|
|
29
|
+
static class Driver
|
|
30
|
+
{
|
|
31
|
+
const string Group = "scenoco";
|
|
32
|
+
/// <summary>A frame of the held clock, as the web bridge steps it.</summary>
|
|
33
|
+
const float Frame = 1f / 60f;
|
|
34
|
+
/// <summary>Session state: set up for driving, so it outlives the reload Play mode starts with.</summary>
|
|
35
|
+
const string Driving = "SceNoCo.Driver.Driving";
|
|
36
|
+
|
|
37
|
+
static readonly int mainThread;
|
|
38
|
+
static readonly ConcurrentQueue<Action> onMain = new ConcurrentQueue<Action>();
|
|
39
|
+
static readonly System.Diagnostics.Stopwatch sinceTick = System.Diagnostics.Stopwatch.StartNew();
|
|
40
|
+
static Action signalTick;
|
|
41
|
+
|
|
42
|
+
static Driver()
|
|
43
|
+
{
|
|
44
|
+
mainThread = Thread.CurrentThread.ManagedThreadId;
|
|
45
|
+
EditorApplication.update += Update;
|
|
46
|
+
EditorApplication.playModeStateChanged += OnPlayMode;
|
|
47
|
+
#if SCENOCO_INPUT_SYSTEM
|
|
48
|
+
InputSystem.onBeforeUpdate += BeforeInput;
|
|
49
|
+
#endif
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
static void Update()
|
|
53
|
+
{
|
|
54
|
+
while (onMain.TryDequeue(out var action)) action();
|
|
55
|
+
// An unfocused Editor ticks rarely, and its game with it: while driving, keep it ticking, as
|
|
56
|
+
// the Pipeline's `editor set_auto_tick` does.
|
|
57
|
+
// Frames a command is waiting for tick at once: they are game time, not the Editor's.
|
|
58
|
+
if (SessionState.GetBool(Driving, false) && (toRun > 0 || sinceTick.ElapsedMilliseconds >= 16))
|
|
59
|
+
{
|
|
60
|
+
sinceTick.Restart();
|
|
61
|
+
signalTick ??= (Action)Delegate.CreateDelegate(typeof(Action), typeof(EditorApplication).GetMethod("SignalTick", BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic));
|
|
62
|
+
signalTick();
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/// <summary>Run on the main thread and wait for it: commands that let frames pass run on a worker thread.</summary>
|
|
67
|
+
static T Run<T>(Func<T> work, double seconds = 10)
|
|
68
|
+
{
|
|
69
|
+
if (Thread.CurrentThread.ManagedThreadId == mainThread) return work();
|
|
70
|
+
T result = default;
|
|
71
|
+
Exception error = null;
|
|
72
|
+
using var done = new ManualResetEventSlim();
|
|
73
|
+
onMain.Enqueue(() =>
|
|
74
|
+
{
|
|
75
|
+
try { result = work(); }
|
|
76
|
+
catch (Exception e) { error = e; }
|
|
77
|
+
finally { done.Set(); }
|
|
78
|
+
});
|
|
79
|
+
if (!done.Wait(TimeSpan.FromSeconds(seconds)))
|
|
80
|
+
throw new TimeoutException("The Editor did not run a frame for " + seconds + " s: a modal dialog may be open in it, or it is not set up for driving — run `unity command scenoco.setup`.");
|
|
81
|
+
if (error != null) throw error;
|
|
82
|
+
return result;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
static void Run(Action work) => Run(() => { work(); return 0; });
|
|
86
|
+
|
|
87
|
+
// --- Setting up ---------------------------------------------------------------------------
|
|
88
|
+
|
|
89
|
+
[CliCommand(Group, "help", "How to drive the game: every scenoco command, and the order to call them in.", MainThreadRequired = false)]
|
|
90
|
+
static string Help() => HelpText;
|
|
91
|
+
|
|
92
|
+
[CliCommand(Group, "setup", "Make the Editor drivable: keep it ticking while unfocused, run the game in the background, and route input to it. Optionally set the Game view's resolution.")]
|
|
93
|
+
static object Setup(
|
|
94
|
+
[CliArg("width", "Game view width in pixels; 0 keeps the current one")] int width = 0,
|
|
95
|
+
[CliArg("height", "Game view height in pixels; 0 keeps the current one")] int height = 0)
|
|
96
|
+
{
|
|
97
|
+
SessionState.SetBool(Driving, true);
|
|
98
|
+
if (width > 0 && height > 0)
|
|
99
|
+
{
|
|
100
|
+
PlayModeWindow.SetViewType(PlayModeWindow.PlayModeViewTypes.GameView);
|
|
101
|
+
PlayModeWindow.SetCustomRenderingResolution((uint)width, (uint)height, "SceNoCo " + width + "x" + height);
|
|
102
|
+
}
|
|
103
|
+
// A Game view to draw into: capture.game_view has nothing to capture without one.
|
|
104
|
+
if (Resources.FindObjectsOfTypeAll(typeof(EditorWindow)).All(w => w.GetType().Name != "GameView"))
|
|
105
|
+
EditorApplication.ExecuteMenuItem("Window/General/Game");
|
|
106
|
+
if (EditorApplication.isPlaying) EnterPlay();
|
|
107
|
+
var clock = Clock();
|
|
108
|
+
clock["next"] = EditorApplication.isPlaying ? "unity command scenoco.ready" : "unity command scenoco.play";
|
|
109
|
+
return clock;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
[CliCommand(Group, "import", "Build what the last scenoco-unity export wrote — prefabs, scenes, materials, the UI — and say what did not come across.")]
|
|
113
|
+
static object Import()
|
|
114
|
+
{
|
|
115
|
+
if (EditorApplication.isPlaying) throw new InvalidOperationException("import: leave Play mode first — `unity command scenoco.stop`.");
|
|
116
|
+
// The importer is in the project's Editor assembly, which this one cannot reference by name.
|
|
117
|
+
var importer = Type.GetType("SceNoCo.Importer, Assembly-CSharp-Editor") ?? throw new InvalidOperationException("No SceNoCo importer in the project: run scenoco-unity first.");
|
|
118
|
+
importer.GetMethod("Import").Invoke(null, null);
|
|
119
|
+
var warnings = (IEnumerable<string>)importer.GetProperty("Warnings").GetValue(null);
|
|
120
|
+
return new Dictionary<string, object> { ["warnings"] = warnings.ToList() };
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
static void OnPlayMode(PlayModeStateChange change)
|
|
124
|
+
{
|
|
125
|
+
if (!SessionState.GetBool(Driving, false)) return;
|
|
126
|
+
if (change == PlayModeStateChange.EnteredPlayMode) EnterPlay();
|
|
127
|
+
if (change == PlayModeStateChange.ExitingPlayMode) ExitPlay();
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/// <summary>What a driven game needs once it plays. None of it is saved: it lasts until Play mode ends.</summary>
|
|
131
|
+
static void EnterPlay()
|
|
132
|
+
{
|
|
133
|
+
Application.runInBackground = true;
|
|
134
|
+
CountFrames();
|
|
135
|
+
#if SCENOCO_INPUT_SYSTEM
|
|
136
|
+
// A copy of the project's settings, so the asset itself is never changed.
|
|
137
|
+
if (savedSettings == null)
|
|
138
|
+
{
|
|
139
|
+
savedSettings = InputSystem.settings;
|
|
140
|
+
var settings = UnityEngine.Object.Instantiate(savedSettings);
|
|
141
|
+
settings.backgroundBehavior = InputSettings.BackgroundBehavior.IgnoreFocus;
|
|
142
|
+
settings.editorInputBehaviorInPlayMode = InputSettings.EditorInputBehaviorInPlayMode.AllDeviceInputAlwaysGoesToGameView;
|
|
143
|
+
InputSystem.settings = settings;
|
|
144
|
+
}
|
|
145
|
+
#endif
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
static void ExitPlay()
|
|
149
|
+
{
|
|
150
|
+
Time.captureDeltaTime = 0;
|
|
151
|
+
#if SCENOCO_INPUT_SYSTEM
|
|
152
|
+
foreach (var device in new InputDevice[] { mouse, touch, keyboard })
|
|
153
|
+
if (device != null && device.added) InputSystem.RemoveDevice(device);
|
|
154
|
+
mouse = null;
|
|
155
|
+
touch = null;
|
|
156
|
+
keyboard = null;
|
|
157
|
+
pressed.Clear();
|
|
158
|
+
script.Clear();
|
|
159
|
+
buttonDown = false;
|
|
160
|
+
if (savedSettings != null) InputSystem.settings = savedSettings;
|
|
161
|
+
savedSettings = null;
|
|
162
|
+
#endif
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
// --- The clock ----------------------------------------------------------------------------
|
|
166
|
+
|
|
167
|
+
[CliCommand(Group, "play", "Enter Play mode, or let a held clock run in real time again.")]
|
|
168
|
+
static object Play()
|
|
169
|
+
{
|
|
170
|
+
if (!SessionState.GetBool(Driving, false)) Setup();
|
|
171
|
+
if (!EditorApplication.isPlaying)
|
|
172
|
+
{
|
|
173
|
+
EditorApplication.isPlaying = true;
|
|
174
|
+
return new Dictionary<string, object>
|
|
175
|
+
{
|
|
176
|
+
["entering"] = true,
|
|
177
|
+
["next"] = "Play mode reloads the scripts, and the command server with them: call `unity command scenoco.ready` until it answers.",
|
|
178
|
+
};
|
|
179
|
+
}
|
|
180
|
+
EditorApplication.isPaused = false;
|
|
181
|
+
Time.captureDeltaTime = 0;
|
|
182
|
+
return Clock();
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
[CliCommand(Group, "ready", "Wait until the game has run its first frames: input sent sooner reaches nothing. Call it after play.", MainThreadRequired = false)]
|
|
186
|
+
static object Ready([CliArg("frames", "Frames the game must have run")] int frames = 3)
|
|
187
|
+
{
|
|
188
|
+
var deadline = DateTime.UtcNow.AddSeconds(60);
|
|
189
|
+
while (!Run(() => EditorApplication.isPlaying && !EditorApplication.isCompiling && Time.frameCount >= frames))
|
|
190
|
+
{
|
|
191
|
+
if (DateTime.UtcNow > deadline) throw new TimeoutException("The game did not reach frame " + frames + " in 60 s. Is the Editor in Play mode? `unity command scenoco.play` enters it.");
|
|
192
|
+
if (Held()) Pass(1);
|
|
193
|
+
Thread.Sleep(20);
|
|
194
|
+
}
|
|
195
|
+
return Run(Clock);
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
[CliCommand(Group, "pause", "Hold the clock: the game moves only when stepped, 1/60 s a frame.")]
|
|
199
|
+
static object Pause()
|
|
200
|
+
{
|
|
201
|
+
RequirePlaying("pause");
|
|
202
|
+
Hold();
|
|
203
|
+
return Clock();
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
[CliCommand(Group, "step", "Hold the clock and advance exactly this many frames of 1/60 s.", MainThreadRequired = false)]
|
|
207
|
+
static object Step([CliArg("frames", "Frames to advance")] int frames = 1)
|
|
208
|
+
{
|
|
209
|
+
Run(() => { RequirePlaying("step"); Hold(); });
|
|
210
|
+
Pass(frames);
|
|
211
|
+
return Run(Clock);
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
[CliCommand(Group, "clock", "Whether the game plays, whether its clock is held, its time, frame and time scale, and the Game view's size.")]
|
|
215
|
+
static Dictionary<string, object> Clock()
|
|
216
|
+
{
|
|
217
|
+
PlayModeWindow.GetRenderingResolution(out var width, out var height);
|
|
218
|
+
return new Dictionary<string, object>
|
|
219
|
+
{
|
|
220
|
+
["playing"] = EditorApplication.isPlaying,
|
|
221
|
+
["held"] = EditorApplication.isPaused,
|
|
222
|
+
["time"] = Round(Time.time),
|
|
223
|
+
["frame"] = Time.frameCount,
|
|
224
|
+
["timeScale"] = Time.timeScale,
|
|
225
|
+
["width"] = width,
|
|
226
|
+
["height"] = height,
|
|
227
|
+
};
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
[CliCommand(Group, "stop", "Leave Play mode.")]
|
|
231
|
+
static string Stop()
|
|
232
|
+
{
|
|
233
|
+
EditorApplication.isPlaying = false;
|
|
234
|
+
return "Leaving Play mode.";
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
static void RequirePlaying(string verb)
|
|
238
|
+
{
|
|
239
|
+
if (!EditorApplication.isPlaying) throw new InvalidOperationException(verb + ": the game is not playing. `unity command scenoco.play`, then `unity command scenoco.ready`.");
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
static void Hold()
|
|
243
|
+
{
|
|
244
|
+
EditorApplication.isPaused = true;
|
|
245
|
+
// Every frame the same length, as the web bridge steps them: the game's time moves 1/60 s a step.
|
|
246
|
+
Time.captureDeltaTime = Frame;
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
static bool Held() => Run(() => EditorApplication.isPlaying && EditorApplication.isPaused);
|
|
250
|
+
|
|
251
|
+
/// <summary>Frames left to run before the clock is held again, and what holds it sooner.</summary>
|
|
252
|
+
static int toRun;
|
|
253
|
+
static Func<bool> stopWhen;
|
|
254
|
+
|
|
255
|
+
struct SceNoCoFrameEnd { }
|
|
256
|
+
|
|
257
|
+
/// <summary>
|
|
258
|
+
/// Hold the clock again at the end of the frame that uses up `toRun`. A held clock steps by
|
|
259
|
+
/// letting whole frames run, not with EditorApplication.Step: a stepped frame takes the fixed
|
|
260
|
+
/// time step instead of Time.captureDeltaTime, and the Input System does not update the game in it.
|
|
261
|
+
/// </summary>
|
|
262
|
+
static void CountFrames()
|
|
263
|
+
{
|
|
264
|
+
var loop = PlayerLoop.GetCurrentPlayerLoop();
|
|
265
|
+
for (var i = 0; i < loop.subSystemList.Length; i++)
|
|
266
|
+
{
|
|
267
|
+
if (loop.subSystemList[i].type != typeof(PostLateUpdate)) continue;
|
|
268
|
+
var systems = loop.subSystemList[i].subSystemList.ToList();
|
|
269
|
+
if (systems.Any(s => s.type == typeof(SceNoCoFrameEnd))) return;
|
|
270
|
+
systems.Add(new PlayerLoopSystem
|
|
271
|
+
{
|
|
272
|
+
type = typeof(SceNoCoFrameEnd),
|
|
273
|
+
updateDelegate = FrameEnd,
|
|
274
|
+
});
|
|
275
|
+
loop.subSystemList[i].subSystemList = systems.ToArray();
|
|
276
|
+
PlayerLoop.SetPlayerLoop(loop);
|
|
277
|
+
return;
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
/// <summary>The end of a game frame: hold the clock once the frames asked for have run, or `stopWhen` holds.</summary>
|
|
282
|
+
static void FrameEnd()
|
|
283
|
+
{
|
|
284
|
+
if (toRun <= 0) return;
|
|
285
|
+
toRun--;
|
|
286
|
+
if (toRun > 0 && (stopWhen == null || !stopWhen())) return;
|
|
287
|
+
toRun = 0;
|
|
288
|
+
EditorApplication.isPaused = true;
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
/// <summary>
|
|
292
|
+
/// Let `frames` frames go by — exactly that many while the clock is held, fewer when `stop` holds at
|
|
293
|
+
/// the end of one; in real time when it is not held.
|
|
294
|
+
/// </summary>
|
|
295
|
+
static void Pass(int frames, Func<bool> stop = null)
|
|
296
|
+
{
|
|
297
|
+
if (frames <= 0) return;
|
|
298
|
+
var held = Held();
|
|
299
|
+
var target = Run(() => Time.frameCount) + frames;
|
|
300
|
+
if (held) Run(() => { CountFrames(); stopWhen = stop; toRun = frames; EditorApplication.isPaused = false; });
|
|
301
|
+
var deadline = DateTime.UtcNow.AddSeconds(10 + frames / 10.0);
|
|
302
|
+
while (!Run(() => held ? toRun == 0 && EditorApplication.isPaused : Time.frameCount >= target))
|
|
303
|
+
{
|
|
304
|
+
if (DateTime.UtcNow > deadline) throw new TimeoutException("The game stopped advancing at frame " + Run(() => Time.frameCount) + ".");
|
|
305
|
+
Thread.Sleep(held ? 2 : 10);
|
|
306
|
+
}
|
|
307
|
+
stopWhen = null;
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
// --- Reading ------------------------------------------------------------------------------
|
|
311
|
+
|
|
312
|
+
[CliCommand(Group, "read", "The game's state: `Player` — every live Player's fields; `Player.lane` — that member of each (a static member is read once); `#runner` — the GameObject named runner.")]
|
|
313
|
+
static object Read([CliArg("target", "Player | Player.lane | #runner")] string target)
|
|
314
|
+
{
|
|
315
|
+
RequirePlaying("read");
|
|
316
|
+
if (target.StartsWith("#"))
|
|
317
|
+
{
|
|
318
|
+
var go = GameObject.Find(target.Substring(1)) ?? throw new ArgumentException("No active GameObject is named " + target.Substring(1) + ". `unity command scenoco.outline` lists them.");
|
|
319
|
+
return Node(go);
|
|
320
|
+
}
|
|
321
|
+
var (type, path) = Split(target);
|
|
322
|
+
var member = path.Length > 0 ? Member(type, path[0]) : null;
|
|
323
|
+
if (member != null && IsStatic(member)) return Plain(Walk(Value(member, null), path.Skip(1)), 3);
|
|
324
|
+
var live = Live(type);
|
|
325
|
+
if (path.Length == 0) return live.Select(b => Fields(b, 2)).ToList();
|
|
326
|
+
return live.Select(b => Plain(Walk(b, path), 3)).ToList();
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
[CliCommand(Group, "outline", "The loaded scenes as text: every GameObject, its components, and each game behaviour's fields.")]
|
|
330
|
+
static string Outline([CliArg("depth", "How deep under each root")] int depth = 4)
|
|
331
|
+
{
|
|
332
|
+
var clock = Clock();
|
|
333
|
+
var text = new StringBuilder($"time {clock["time"]}s · frame {clock["frame"]} · timeScale {clock["timeScale"]}{((bool)clock["held"] ? " · clock held" : "")}\n");
|
|
334
|
+
void Visit(Transform t, int level)
|
|
335
|
+
{
|
|
336
|
+
var indent = new string(' ', level * 2);
|
|
337
|
+
text.Append(indent).Append(t.name).Append(t.gameObject.activeInHierarchy ? "" : " (inactive)");
|
|
338
|
+
var parts = t.GetComponents<Component>().Where(c => c != null && !(c is Transform)).Select(c => c.GetType().Name);
|
|
339
|
+
text.Append(" [").Append(string.Join(", ", parts)).Append("]\n");
|
|
340
|
+
foreach (var b in t.GetComponents<MonoBehaviour>().Where(IsGame))
|
|
341
|
+
text.Append(indent).Append(" ").Append(b.GetType().Name).Append(' ').Append(Json(Fields(b, 1))).Append('\n');
|
|
342
|
+
if (level < depth) foreach (Transform child in t) Visit(child, level + 1);
|
|
343
|
+
}
|
|
344
|
+
for (var i = 0; i < SceneManager.sceneCount; i++)
|
|
345
|
+
foreach (var root in SceneManager.GetSceneAt(i).GetRootGameObjects()) Visit(root.transform, 0);
|
|
346
|
+
return text.ToString();
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
[CliCommand(Group, "until", "Hold the clock and step until a member of the game meets a condition: until --target Game.phase --equals over.", MainThreadRequired = false)]
|
|
350
|
+
static object Until(
|
|
351
|
+
[CliArg("target", "A member, as read takes it: Game.phase, Player.lives")] string target,
|
|
352
|
+
[CliArg("equals", "Met when it equals this (a number compares as a number)")] string equals = null,
|
|
353
|
+
[CliArg("above", "Met when it is greater than this number")] string above = null,
|
|
354
|
+
[CliArg("below", "Met when it is less than this number")] string below = null,
|
|
355
|
+
[CliArg("max_frames", "Give up after this many frames")] int maxFrames = 600)
|
|
356
|
+
{
|
|
357
|
+
Run(() => { RequirePlaying("until"); Hold(); });
|
|
358
|
+
Func<object, bool> test;
|
|
359
|
+
if (equals != null) test = v => double.TryParse(equals, NumberStyles.Float, CultureInfo.InvariantCulture, out var n) && Number(v) is double d ? Math.Abs(d - n) < 1e-6 : string.Equals(Text(v), equals, StringComparison.Ordinal);
|
|
360
|
+
else if (above != null) test = v => Number(v) > double.Parse(above, CultureInfo.InvariantCulture);
|
|
361
|
+
else if (below != null) test = v => Number(v) < double.Parse(below, CultureInfo.InvariantCulture);
|
|
362
|
+
else test = v => v is bool b ? b : v != null && !(Number(v) is double d && d == 0);
|
|
363
|
+
// Tested at the end of every frame, in the game's own loop, which holds the clock on the frame it is met.
|
|
364
|
+
var start = Run(() => Time.frameCount);
|
|
365
|
+
if (!Run(() => test(First(target)))) Pass(maxFrames, () => test(First(target)));
|
|
366
|
+
return Run(() =>
|
|
367
|
+
{
|
|
368
|
+
var v = First(target);
|
|
369
|
+
var result = Clock();
|
|
370
|
+
result["met"] = test(v);
|
|
371
|
+
result["frames"] = Time.frameCount - start;
|
|
372
|
+
result["value"] = Plain(v, 2);
|
|
373
|
+
return result;
|
|
374
|
+
});
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
/// <summary>A member of the first live behaviour of its class, or a static member: what `until` tests.</summary>
|
|
378
|
+
static object First(string target)
|
|
379
|
+
{
|
|
380
|
+
var (type, path) = Split(target);
|
|
381
|
+
if (path.Length == 0) return Live(type).FirstOrDefault();
|
|
382
|
+
var member = Member(type, path[0]);
|
|
383
|
+
if (member != null && IsStatic(member)) return Walk(Value(member, null), path.Skip(1));
|
|
384
|
+
var live = Live(type).FirstOrDefault();
|
|
385
|
+
return live == null ? null : Walk(live, path);
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
static (Type, string[]) Split(string target)
|
|
389
|
+
{
|
|
390
|
+
var parts = target.Split('.');
|
|
391
|
+
var type = FindType(parts[0]) ?? throw new ArgumentException("No class is named " + parts[0] + ". A target is a class of the game, then its members: Player, Player.lane, Game.phase.");
|
|
392
|
+
return (type, parts.Skip(1).ToArray());
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
static readonly Dictionary<string, Type> types = new Dictionary<string, Type>();
|
|
396
|
+
|
|
397
|
+
static Type FindType(string name)
|
|
398
|
+
{
|
|
399
|
+
if (types.TryGetValue(name, out var known)) return known;
|
|
400
|
+
var found = TypeCache.GetTypesDerivedFrom<object>()
|
|
401
|
+
.Where(t => t.Name == name && !t.Assembly.FullName.StartsWith("System") && !t.Assembly.FullName.StartsWith("mscorlib"))
|
|
402
|
+
.OrderBy(t => t.Assembly.GetName().Name.StartsWith("Assembly-CSharp") ? 0 : t.Assembly.GetName().Name.StartsWith("Unity") ? 2 : 1)
|
|
403
|
+
.FirstOrDefault();
|
|
404
|
+
if (found != null) types[name] = found;
|
|
405
|
+
return found;
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
static IEnumerable<UnityEngine.Object> Live(Type type)
|
|
409
|
+
{
|
|
410
|
+
if (!typeof(UnityEngine.Object).IsAssignableFrom(type)) throw new ArgumentException(type.Name + " is not a component: read a static member of it, Type.member.");
|
|
411
|
+
// Unity 6.6 deprecates the sort mode, but the order is what keeps `read` the same from call to call.
|
|
412
|
+
#pragma warning disable CS0618
|
|
413
|
+
return UnityEngine.Object.FindObjectsByType(type, FindObjectsSortMode.InstanceID);
|
|
414
|
+
#pragma warning restore CS0618
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
const BindingFlags Any = BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.FlattenHierarchy;
|
|
418
|
+
|
|
419
|
+
static MemberInfo Member(Type type, string name) =>
|
|
420
|
+
(MemberInfo)type.GetField(name, Any) ?? type.GetProperty(name, Any) ?? (MemberInfo)type.GetField("<" + name + ">k__BackingField", Any);
|
|
421
|
+
|
|
422
|
+
static bool IsStatic(MemberInfo m) => m is FieldInfo f ? f.IsStatic : m is PropertyInfo p && (p.GetGetMethod(true)?.IsStatic ?? false);
|
|
423
|
+
|
|
424
|
+
static object Value(MemberInfo m, object target) => m is FieldInfo f ? f.GetValue(target) : ((PropertyInfo)m).GetValue(target);
|
|
425
|
+
|
|
426
|
+
static object Walk(object value, IEnumerable<string> path)
|
|
427
|
+
{
|
|
428
|
+
foreach (var name in path)
|
|
429
|
+
{
|
|
430
|
+
if (value == null) return null;
|
|
431
|
+
var member = Member(value.GetType(), name) ?? throw new ArgumentException(value.GetType().Name + " has no member " + name + ".");
|
|
432
|
+
value = Value(member, value);
|
|
433
|
+
}
|
|
434
|
+
return value;
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
static bool IsGame(MonoBehaviour b) => b != null && b.GetType().Assembly.GetName().Name.StartsWith("Assembly-CSharp");
|
|
438
|
+
|
|
439
|
+
/// <summary>A behaviour's own fields — its class's and its game ancestors', public or not.</summary>
|
|
440
|
+
static Dictionary<string, object> Fields(object o, int depth)
|
|
441
|
+
{
|
|
442
|
+
var result = new Dictionary<string, object>();
|
|
443
|
+
for (var t = o.GetType(); t != null && t != typeof(MonoBehaviour) && t != typeof(object); t = t.BaseType)
|
|
444
|
+
foreach (var f in t.GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.DeclaredOnly))
|
|
445
|
+
{
|
|
446
|
+
var name = f.Name.StartsWith("<") ? f.Name.Substring(1, f.Name.IndexOf('>') - 1) : f.Name;
|
|
447
|
+
if (!result.ContainsKey(name)) result[name] = Plain(f.GetValue(o), depth);
|
|
448
|
+
}
|
|
449
|
+
return result;
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
static Dictionary<string, object> Node(GameObject go) => new Dictionary<string, object>
|
|
453
|
+
{
|
|
454
|
+
["name"] = go.name,
|
|
455
|
+
["active"] = go.activeInHierarchy,
|
|
456
|
+
["position"] = Plain(go.transform.position, 1),
|
|
457
|
+
["components"] = go.GetComponents<Component>().Where(c => c != null).Select(c => c.GetType().Name).ToList(),
|
|
458
|
+
["behaviours"] = go.GetComponents<MonoBehaviour>().Where(IsGame).ToDictionary(b => b.GetType().Name, b => (object)Fields(b, 1)),
|
|
459
|
+
};
|
|
460
|
+
|
|
461
|
+
/// <summary>A value as plain data: numbers, strings, lists, objects of fields.</summary>
|
|
462
|
+
static object Plain(object v, int depth)
|
|
463
|
+
{
|
|
464
|
+
switch (v)
|
|
465
|
+
{
|
|
466
|
+
case null: return null;
|
|
467
|
+
case string s: return s;
|
|
468
|
+
case bool b: return b;
|
|
469
|
+
case float f: return Round(f);
|
|
470
|
+
case double d: return Round(d);
|
|
471
|
+
case Enum e: return e.ToString();
|
|
472
|
+
case Vector2 a: return new[] { Round(a.x), Round(a.y) };
|
|
473
|
+
case Vector3 a: return new[] { Round(a.x), Round(a.y), Round(a.z) };
|
|
474
|
+
case Vector4 a: return new[] { Round(a.x), Round(a.y), Round(a.z), Round(a.w) };
|
|
475
|
+
case Quaternion q: return Plain(q.eulerAngles, depth);
|
|
476
|
+
case Color c: return "#" + ColorUtility.ToHtmlStringRGBA(c);
|
|
477
|
+
case GameObject go: return "#" + go.name;
|
|
478
|
+
case Component c: return c == null ? null : c.GetType().Name + " on #" + c.gameObject.name;
|
|
479
|
+
case UnityEngine.Object o: return o == null ? null : o.name;
|
|
480
|
+
}
|
|
481
|
+
if (v.GetType().IsPrimitive || v is decimal) return v;
|
|
482
|
+
// An engine object — a VisualElement, a Rigidbody2D's internals — reads as its own text, not its fields.
|
|
483
|
+
if (!(v is IEnumerable) && !v.GetType().Assembly.GetName().Name.StartsWith("Assembly-CSharp")) return v.ToString();
|
|
484
|
+
if (depth <= 0) return v.ToString();
|
|
485
|
+
if (v is IDictionary dict) { var r = new Dictionary<string, object>(); foreach (DictionaryEntry e in dict) r[e.Key.ToString()] = Plain(e.Value, depth - 1); return r; }
|
|
486
|
+
if (v is IEnumerable list) return list.Cast<object>().Take(50).Select(x => Plain(x, depth - 1)).ToList();
|
|
487
|
+
return Fields(v, depth - 1);
|
|
488
|
+
}
|
|
489
|
+
|
|
490
|
+
static double Round(double v) => Math.Round(v, 4);
|
|
491
|
+
|
|
492
|
+
static double? Number(object v) => v switch
|
|
493
|
+
{
|
|
494
|
+
null => null,
|
|
495
|
+
bool b => b ? 1 : 0,
|
|
496
|
+
Enum _ => null,
|
|
497
|
+
IConvertible c when !(v is string) => c.ToDouble(CultureInfo.InvariantCulture),
|
|
498
|
+
string s when double.TryParse(s, NumberStyles.Float, CultureInfo.InvariantCulture, out var n) => n,
|
|
499
|
+
_ => null,
|
|
500
|
+
};
|
|
501
|
+
|
|
502
|
+
static string Text(object v) => v is Enum e ? e.ToString() : Plain(v, 0)?.ToString();
|
|
503
|
+
|
|
504
|
+
static string Json(object v) => v switch
|
|
505
|
+
{
|
|
506
|
+
null => "null",
|
|
507
|
+
string s => "\"" + s.Replace("\\", "\\\\").Replace("\"", "\\\"") + "\"",
|
|
508
|
+
bool b => b ? "true" : "false",
|
|
509
|
+
IDictionary<string, object> d => "{" + string.Join(", ", d.Select(p => p.Key + ": " + Json(p.Value))) + "}",
|
|
510
|
+
IEnumerable e => "[" + string.Join(", ", e.Cast<object>().Select(Json)) + "]",
|
|
511
|
+
IFormattable f => f.ToString(null, CultureInfo.InvariantCulture),
|
|
512
|
+
_ => v.ToString(),
|
|
513
|
+
};
|
|
514
|
+
|
|
515
|
+
// --- Input --------------------------------------------------------------------------------
|
|
516
|
+
#if SCENOCO_INPUT_SYSTEM
|
|
517
|
+
static InputSettings savedSettings;
|
|
518
|
+
static Mouse mouse;
|
|
519
|
+
static Touchscreen touch;
|
|
520
|
+
static Keyboard keyboard;
|
|
521
|
+
static readonly HashSet<Key> pressed = new HashSet<Key>();
|
|
522
|
+
/// <summary>What to send the game, one entry per frame of its own: input queued from the Editor's update reaches the Editor, not the game.</summary>
|
|
523
|
+
static readonly Queue<Action> script = new Queue<Action>();
|
|
524
|
+
|
|
525
|
+
static void BeforeInput()
|
|
526
|
+
{
|
|
527
|
+
if (InputState.currentUpdateType != InputUpdateType.Dynamic || script.Count == 0) return;
|
|
528
|
+
script.Dequeue()?.Invoke();
|
|
529
|
+
}
|
|
530
|
+
|
|
531
|
+
/// <summary>The driver's own devices: the real ones keep sending their state, which would undo what is sent here.</summary>
|
|
532
|
+
static T Device<T>(ref T device, string name) where T : InputDevice
|
|
533
|
+
{
|
|
534
|
+
if (device == null || !device.added) device = InputSystem.AddDevice<T>(name);
|
|
535
|
+
// The Editor turns devices off whenever it loses focus.
|
|
536
|
+
if (!device.enabled) InputSystem.EnableDevice(device);
|
|
537
|
+
return device;
|
|
538
|
+
}
|
|
539
|
+
|
|
540
|
+
/// <summary>Send `frames` (one entry a frame, null for none) and let them all reach the game.</summary>
|
|
541
|
+
static object Send(IEnumerable<Action> frames)
|
|
542
|
+
{
|
|
543
|
+
var count = Run(() =>
|
|
544
|
+
{
|
|
545
|
+
RequirePlaying("input");
|
|
546
|
+
foreach (var f in frames) script.Enqueue(f);
|
|
547
|
+
return script.Count;
|
|
548
|
+
});
|
|
549
|
+
Pass(count + 1);
|
|
550
|
+
return Run(Clock);
|
|
551
|
+
}
|
|
552
|
+
|
|
553
|
+
static Vector2 Point(string verb, float x, float y)
|
|
554
|
+
{
|
|
555
|
+
PlayModeWindow.GetRenderingResolution(out var width, out var height);
|
|
556
|
+
if (x < 0 || y < 0 || x > width || y > height)
|
|
557
|
+
throw new ArgumentException($"{verb}: ({x}, {y}) is outside the Game view, which is {width}×{height}. x and y are pixels from its top-left.");
|
|
558
|
+
// From the top-left, as the web bridge takes them; Unity counts from the bottom-left.
|
|
559
|
+
return new Vector2(x, height - y);
|
|
560
|
+
}
|
|
561
|
+
|
|
562
|
+
static Action PointerAt(bool touchscreen, Vector2 at, UnityEngine.InputSystem.TouchPhase phase) => () =>
|
|
563
|
+
{
|
|
564
|
+
if (touchscreen)
|
|
565
|
+
InputSystem.QueueStateEvent(Device(ref touch, "SceNoCoTouch"), new TouchState { touchId = 1, phase = phase, position = at });
|
|
566
|
+
else
|
|
567
|
+
{
|
|
568
|
+
// A move keeps the button as it was: down while dragging, up while hovering.
|
|
569
|
+
if (phase == UnityEngine.InputSystem.TouchPhase.Began) buttonDown = true;
|
|
570
|
+
if (phase == UnityEngine.InputSystem.TouchPhase.Ended) buttonDown = false;
|
|
571
|
+
// With its delta, as a real mouse sends it: a game that steers by "the mouse moved" reads that.
|
|
572
|
+
InputSystem.QueueStateEvent(Device(ref mouse, "SceNoCoMouse"), new MouseState { position = at, delta = at - mouseAt }.WithButton(MouseButton.Left, buttonDown));
|
|
573
|
+
mouseAt = at;
|
|
574
|
+
}
|
|
575
|
+
};
|
|
576
|
+
|
|
577
|
+
static bool buttonDown;
|
|
578
|
+
static Vector2 mouseAt;
|
|
579
|
+
|
|
580
|
+
static Action Keys(Key key, bool down) => () =>
|
|
581
|
+
{
|
|
582
|
+
if (down) pressed.Add(key); else pressed.Remove(key);
|
|
583
|
+
InputSystem.QueueStateEvent(Device(ref keyboard, "SceNoCoKeyboard"), new KeyboardState(pressed.ToArray()));
|
|
584
|
+
};
|
|
585
|
+
|
|
586
|
+
static Key KeyNamed(string name)
|
|
587
|
+
{
|
|
588
|
+
switch (name)
|
|
589
|
+
{
|
|
590
|
+
case " ": case "Space": return Key.Space;
|
|
591
|
+
case "ArrowLeft": return Key.LeftArrow;
|
|
592
|
+
case "ArrowRight": return Key.RightArrow;
|
|
593
|
+
case "ArrowUp": return Key.UpArrow;
|
|
594
|
+
case "ArrowDown": return Key.DownArrow;
|
|
595
|
+
case "Shift": return Key.LeftShift;
|
|
596
|
+
case "Control": return Key.LeftCtrl;
|
|
597
|
+
case "Alt": return Key.LeftAlt;
|
|
598
|
+
case "Meta": return Key.LeftMeta;
|
|
599
|
+
}
|
|
600
|
+
if (name.Length == 1 && char.IsDigit(name[0])) return (Key)Enum.Parse(typeof(Key), "Digit" + name);
|
|
601
|
+
if (Enum.TryParse<Key>(name, true, out var key) && key != Key.None) return key;
|
|
602
|
+
throw new ArgumentException("No key is named " + name + ". Keys are named as on the web: Space, ArrowLeft, Enter, Escape, a, 7 — or by Unity's Key: LeftArrow, Digit7.");
|
|
603
|
+
}
|
|
604
|
+
|
|
605
|
+
[CliCommand(Group, "press", "Hold a key for some frames, then let it go: press --key Space.", MainThreadRequired = false)]
|
|
606
|
+
static object Press([CliArg("key", "Space, ArrowLeft, Enter, Escape, a, 7")] string key, [CliArg("frames", "Frames to hold it")] int frames = 6)
|
|
607
|
+
{
|
|
608
|
+
var k = KeyNamed(key);
|
|
609
|
+
return Send(new[] { Keys(k, true) }.Concat(Enumerable.Repeat<Action>(null, Math.Max(0, frames - 1))).Concat(new[] { Keys(k, false) }));
|
|
610
|
+
}
|
|
611
|
+
|
|
612
|
+
[CliCommand(Group, "key_down", "Press a key and keep it down.", MainThreadRequired = false)]
|
|
613
|
+
static object KeyDown([CliArg("key", "Space, ArrowLeft, Enter, Escape, a, 7")] string key) => Send(new[] { Keys(KeyNamed(key), true) });
|
|
614
|
+
|
|
615
|
+
[CliCommand(Group, "key_up", "Let a key go.", MainThreadRequired = false)]
|
|
616
|
+
static object KeyUp([CliArg("key", "Space, ArrowLeft, Enter, Escape, a, 7")] string key) => Send(new[] { Keys(KeyNamed(key), false) });
|
|
617
|
+
|
|
618
|
+
[CliCommand(Group, "click", "Click — or with --touch, tap — at a point of the Game view, in pixels from its top-left.", MainThreadRequired = false)]
|
|
619
|
+
static object Click([CliArg("x", "Pixels from the left")] float x, [CliArg("y", "Pixels from the top")] float y, [CliArg("touch", "A finger instead of the mouse")] bool touch = false)
|
|
620
|
+
{
|
|
621
|
+
var at = Run(() => Point("click", x, y));
|
|
622
|
+
return Send(new[] { PointerAt(touch, at, UnityEngine.InputSystem.TouchPhase.Began), PointerAt(touch, at, UnityEngine.InputSystem.TouchPhase.Ended) });
|
|
623
|
+
}
|
|
624
|
+
|
|
625
|
+
[CliCommand(Group, "pointer_down", "Press the mouse — or with --touch, a finger — at a point, and keep it down.", MainThreadRequired = false)]
|
|
626
|
+
static object PointerDown([CliArg("x", "Pixels from the left")] float x, [CliArg("y", "Pixels from the top")] float y, [CliArg("touch", "A finger instead of the mouse")] bool touch = false)
|
|
627
|
+
{
|
|
628
|
+
var at = Run(() => Point("pointer_down", x, y));
|
|
629
|
+
pointerAt = at;
|
|
630
|
+
return Send(new[] { PointerAt(touch, at, UnityEngine.InputSystem.TouchPhase.Began) });
|
|
631
|
+
}
|
|
632
|
+
|
|
633
|
+
[CliCommand(Group, "pointer_move", "Move the pointer — held or not — to a point.", MainThreadRequired = false)]
|
|
634
|
+
static object PointerMove([CliArg("x", "Pixels from the left")] float x, [CliArg("y", "Pixels from the top")] float y, [CliArg("touch", "A finger instead of the mouse")] bool touch = false)
|
|
635
|
+
{
|
|
636
|
+
var at = Run(() => Point("pointer_move", x, y));
|
|
637
|
+
pointerAt = at;
|
|
638
|
+
return Send(new[] { PointerAt(touch, at, UnityEngine.InputSystem.TouchPhase.Moved) });
|
|
639
|
+
}
|
|
640
|
+
|
|
641
|
+
[CliCommand(Group, "pointer_up", "Let the pointer go where it is.", MainThreadRequired = false)]
|
|
642
|
+
static object PointerUp([CliArg("touch", "A finger instead of the mouse")] bool touch = false) =>
|
|
643
|
+
Send(new[] { PointerAt(touch, pointerAt, UnityEngine.InputSystem.TouchPhase.Ended) });
|
|
644
|
+
|
|
645
|
+
static Vector2 pointerAt;
|
|
646
|
+
|
|
647
|
+
[CliCommand(Group, "swipe", "Press at one point, drag to another over some frames, let go: swipe --from 500,400 --to 300,400.", MainThreadRequired = false)]
|
|
648
|
+
static object Swipe(
|
|
649
|
+
[CliArg("from", "x,y in pixels from the Game view's top-left")] string from,
|
|
650
|
+
[CliArg("to", "x,y in pixels from the Game view's top-left")] string to,
|
|
651
|
+
[CliArg("frames", "Frames the drag takes")] int frames = 8,
|
|
652
|
+
[CliArg("touch", "A finger instead of the mouse")] bool touch = false)
|
|
653
|
+
{
|
|
654
|
+
Vector2 Parse(string point)
|
|
655
|
+
{
|
|
656
|
+
var xy = point.Split(',');
|
|
657
|
+
if (xy.Length != 2 || !float.TryParse(xy[0], NumberStyles.Float, CultureInfo.InvariantCulture, out var x) || !float.TryParse(xy[1], NumberStyles.Float, CultureInfo.InvariantCulture, out var y))
|
|
658
|
+
throw new ArgumentException("swipe: " + point + " is not a point — write it x,y: swipe --from 500,400 --to 300,400.");
|
|
659
|
+
return Run(() => Point("swipe", x, y));
|
|
660
|
+
}
|
|
661
|
+
var a = Parse(from);
|
|
662
|
+
var b = Parse(to);
|
|
663
|
+
var steps = new List<Action> { PointerAt(touch, a, UnityEngine.InputSystem.TouchPhase.Began) };
|
|
664
|
+
for (var i = 1; i <= Math.Max(1, frames); i++) steps.Add(PointerAt(touch, Vector2.Lerp(a, b, i / (float)Math.Max(1, frames)), UnityEngine.InputSystem.TouchPhase.Moved));
|
|
665
|
+
steps.Add(PointerAt(touch, b, UnityEngine.InputSystem.TouchPhase.Ended));
|
|
666
|
+
return Send(steps);
|
|
667
|
+
}
|
|
668
|
+
#endif
|
|
669
|
+
|
|
670
|
+
const string HelpText = @"scenoco — the game in the Editor's Play mode, driven as window.__scenoco drives it on the web.
|
|
671
|
+
Every command: unity command scenoco.<verb> [--name value …] — scenoco.step --frames 10. Each returns plain data.
|
|
672
|
+
|
|
673
|
+
Start:
|
|
674
|
+
import build the last export and list what did not come across — read every warning
|
|
675
|
+
setup [--width 1080 --height 1920] keep the Editor ticking unfocused, run the game in the background, route input to it;
|
|
676
|
+
sets the Game view's resolution too
|
|
677
|
+
play enter Play mode; it reloads the scripts, and this server with them
|
|
678
|
+
ready wait for the game's first frames — call it until it answers: input sent sooner reaches nothing
|
|
679
|
+
Clock — a held clock moves only when stepped, 1/60 s a frame, so every reading lands on an exact frame:
|
|
680
|
+
pause play clock stop
|
|
681
|
+
step [--frames 1] advance exactly this many frames
|
|
682
|
+
until --target Game.phase --equals over [--max_frames 600] step until it holds; also --above n, --below n, or neither (truthy)
|
|
683
|
+
a wait longer than Unity's CLI allows (30 s): add --timeout 120 after the verb
|
|
684
|
+
Reading — a target is a class of the game, then its members; the first live one is the one `until` tests:
|
|
685
|
+
read --target Player | Player.lane | #runner every live Player's fields; that member of each; the GameObject named runner
|
|
686
|
+
outline [--depth 4] the loaded scenes as text, with each game behaviour's fields
|
|
687
|
+
Input — through the Input System, as the player's, stepped while the clock is held; x, y in pixels from the Game view's top-left:
|
|
688
|
+
press --key Space [--frames 6] key_down --key a key_up --key a Space, ArrowLeft, Enter, Escape, a, 7
|
|
689
|
+
click --x 540 --y 960 pointer_down / pointer_move --x --y pointer_up swipe --from 540,1400 --to 540,600 [--frames 8]
|
|
690
|
+
add --touch true to any pointer verb for a finger instead of the mouse
|
|
691
|
+
The legacy Input Manager (UnityEngine.Input) is not driven: read input through the Input System.
|
|
692
|
+
Looking and anything else, from Unity's own commands:
|
|
693
|
+
unity command capture.game_view -- --save_path Screenshots/now.png what the Game view shows, HUD included
|
|
694
|
+
unity command console.get -- --level error exceptions
|
|
695
|
+
unity command script.eval ""return FindFirstObjectByType<Game>().score;"" any C#";
|
|
696
|
+
}
|
|
697
|
+
}
|