GGua REFERENCE日本語GitHub ↗
DOCS / UNITY

Unity API and specification

A reference for Unity package choices, public types, supported UI and actions, and extension points.

Choosing a package

PackageUseTarget
com.link1345.guaThe UPM package for Unity projects, including automatic startup, UI collection, actions, and screenshotsUnity 6000.0+
Gua.RuntimeShared runtime API for implementing another engine adapternet10.0 / netstandard2.1
Gua.Testing.UnityBuild, launch, and connect to the Unity Editor or Player from external .NET testsnet10.0 / netstandard2.1
Gua.TestingEngine-neutral testing API for locators, assertions, remote connections, and screenshotsEngine-neutral
Gua.Testing.VisualAdd PNG baseline comparison and diff artifacts to any Gua context, including Unitynet10.0 / netstandard2.1
Gua.Testing.RecordingRecord and replay semantic actions against any Gua context, including Unitynet10.0 / netstandard2.1

Unity public types

TypeContract
GuaUnityRuntimeAutomatically started MonoBehaviour; exposes EnsureStarted() and manual RunFrame()
GuaIdOptional stable Value for uGUI/TMP GameObjects
GuaScreenOptional logical screen Value; otherwise active scene name/path
IGuaUnityControlAdapterTryDescribe/TryApply extension point for custom uGUI-like controls
GuaUnityAdapterRegistryAdd control adapters with Register(adapter)
GuaUnityKeyEventMaps protocol keys and modifier bits to Unity Events

Gua.Runtime surface

Normal Unity projects do not need to call this layer directly because the UPM package manages it. When building a custom engine adapter, GuaRuntime creates and owns the native runtime and destroys its bridge and handle in Dispose(). Its primary API includes StartInspectorBridge/StopInspectorBridge, SetAdapterVersion, BeginFrame/EndFrame, RegisterNode, TryConsumeAction/EmitActionResult, TryConsumeScreenshotRequest/CompleteScreenshot, AddLog, GetUiTreeJson, and GetVersionJson.

Test-host API

MemberMeaning
UnityPlayerBuilder.BuildBatch-build a Windows64 Mono Player for one scene
LoadPlayerStart a headless Player
LoadRenderedPlayerStart a rendered Player
LoadEditorStart a scene through the StartPlayMode editor command
BuildAndLoadPlayerBuild and launch in one call
Context / RemoteContextShared IGuaContext / WebSocket implementation
CaptureScreenshotWait for an on-demand PNG after the current frame sequence
CreateDiagnosticsSessionAdd Unity log and process metadata to shared artifacts

UI mapping

RoleUI ToolkituGUI / TMPActions
buttonButtonButton / Button with TMP labelclick, focus
checkboxToggleToggleclick, focus, set_checked
textboxTextFieldInputField / TMP_InputFieldfocus, set_value, press_key
sliderSlider / SliderIntSliderfocus, set_value
comboboxDropdownFieldDropdown / TMP_Dropdownfocus, select
list / listitemListView and all itemsSource entriesNo standard mappingfocus, select, scroll
tablist / tabTabView / TabNo standard mappingselect
scrollareaScrollViewScrollRectscroll
text / panelLabel / fallbackText, TMP_Text / fallbackObserve only

Each frame collects role, label, text/value, visible, enabled, focused, checkbox checked state, ListView item selected state, slider range, parentId, and bounds. Virtualized offscreen ListView entries still get nodes, but unrealized entries have visible: false and zero bounds.

Actions and completion

The adapter consumes only actions declared by the target role. It emits the original requestId after synchronous Unity listeners return; it does not wait for coroutines, async void, or next-frame work. Invalid numbers, choices, and keys return invalid_value; unavailable combinations return unsupported. Exceptions are logged to both Gua and the Unity Console and become failed results.

press_key modifier bits are 1=Shift, 2=Alt, 4=Control, and 8=Command. Enter, Esc, and Arrow* aliases are normalized to Unity KeyCode names. A global key request is routed to the focused textbox.

Engine-neutral specification

  • version_v1 includes an optional adapterVersions map. Unity reports the loaded native runtime version as {"unity":"<runtime version>"}.
  • godotPluginVersion remains for compatibility and is null outside Godot.
  • Adapter bounds use physical viewport pixels with a top-left origin and positive right/down axes; NaN and Infinity are not allowed.
  • GuaWebSocketContext, the remote tree, and captured screenshots are available from Gua.Testing.
  • The C ABI includes gua_runtime_set_adapter_version(runtime, adapter, version); existing exports remain available.
  • A screenshot consumed before a session reset completes as stale_session, preventing an old image from appearing in the new session.

Lifecycle and ownership

BeforeSceneLoad creates two persistent GameObjects: a bootstrap driver and the runtime. Driver LateUpdate() runs begin → collect → end → dispatch actions → service screenshot requests. Destruction stops the bridge and disposes the native handle. The UPM artifact bundles Gua.Core.dll, Gua.Runtime.dll and dependencies, gua.dll, and gua_runtime.dll.

Usage notes

  • For screens that need external integer-slider changes, use Slider for now. SliderInt state can still be observed.
  • Toggle clicks are delivered as value changes. Custom behavior should listen for value/change events as well as pointer events.
  • When registering a custom Control, implement the role's actions in TryApply. Observation-only controls can use a role without interactive actions.
  • Parallel Unity test hosts use dynamic ports. Avoid running an unrelated process that pins the same port range.