The airconsole-unity-plugin project targets Unity 2022.3.x and ships the full AirConsole runtime, editor tooling, Android TV helpers, and WebGL controller templates. This guide is tailored to the contents under Assets/AirConsole.
scripts/Runtime: Core API surface (AirConsole.cs), websocket/webview bridges (WebsocketListener.cs,WebViewManager.cs), runtime settings (Settings.cs,AirconsoleRuntimeSettings.cs,NativeGameSizingSettings.cs), logging (AirConsoleLogger.cs,DebugLevel.cs), platform runtime configurators, and Android plugin wrappers underRuntime/Plugin/Android.scripts/Editor: Custom inspectors/windows (Inspector.cs,SettingWindow.cs,PlayMode.cs,SafeAreaTester.cs,WebListener.cs), build automation (BuildAutomation/*), project maintenance checks (ProjectMaintenance/*), and plugin developer helpers (PluginDevelopment/*).scripts/SupportCheck: Unity version/platform validator ASMDEF used in-editor.scripts/Tests: ASMDEF-scoped EditMode, PlayMode, and Editor tests.examples: Sample scenes (basic,pong,platformer,swipe,game-states,safe-area,translations) for manual validation.extras: Controller template HTML andHighScoreHelper.cs.plugins: Managed dependencies (Newtonsoft.Json.dll,websocket-sharp.dll) plus Android native plugin payload underplugins/Android.unity-webview: Embedded WebView plugin with runtime/editor asmdefs and native binaries underPlugins.unity-webviewis an imported external dependency. You are not allowed to alter it.- Docs and misc:
Documentation_1.7.pdf,Documentation for AndroidTV.pdf,Upgrade_Plugin_Version.md,README.txt,airconsole.prefs, and the distributableairconsole-code.unitypackage.
- API + bridge:
AirConsole.csexposes the public API;WebsocketListenerroutes JSON actions/events;WebViewManagercoordinates the embedded webview. Add new events in both the listener and the API surface. - Config assets:
AirconsoleRuntimeSettings.assetandNativeGameSizingSettings.asset(inscripts/Runtime/Resources) hold defaults for ports, safe-area sizing, etc. Adjust via the editor UI instead of hardcoding. - Platform setup: Implementations of
IRuntimeConfigurator(AndroidRuntimeConfigurator,WebGLRuntimeConfigurator,EditorRuntimeConfigurator) handle platform-specific initialization. Extend these rather than branching deep in the API. - Android plugin wrappers:
PluginManager,AndroidUnityUtils, and callback helpers (UnityPluginExecutionCallback,UnityPluginStringCallback,GenericUnityPluginCallback,UnityAndroidObjectProvider) encapsulate Java bridge calls. Keep new native hooks consistent with these wrappers. - Logging & diagnostics: Use
AirConsoleLoggerwithDebugLevelenums to respect runtime debug settings.
- UI/inspectors:
SettingWindow,Inspector,PlayMode,SafeAreaTester, andWebListenerprovide editor UI and simulator hooks. Prefer extending these instead of adding ad-hoc windows. - Build automation (
scripts/Editor/BuildAutomation):PreBuildProcessingandPostBuildProcesswrap pre/post hooks; post steps validate WebGL template AirConsole JS versions.AndroidManifestProcessor,AndroidGradleProcessor,AndroidProjectProcessor,AndroidManifest, andAndroidXMLDocumentmutate generated Android projects/manifests. Use these helpers instead of manual IO.
- Project maintenance (
ProjectMaintenance):ProjectDependencyCheck,SemVerCheck, andProjectConfigurationCheckenforce Unity version and project settings;ProjectPreferenceManager/ProjectPreferencesmanage stored preferences;ProjectUpgradeEditorsupports upgrade flows. - Plugin development helpers (
PluginDevelopment):BuildHelperhosts build/packaging entry points (Web/Android) and can auto-zip or auto-commit;DevelopmentToolsincludes additional packager utilities.
- Tests live under
scripts/Tests(EditMode/PlayMode/Editor asmdefs). Run via Unity Test Runner; some PlayMode tests expect Android as the active build target. - Manual checks: leverage sample scenes in
examplesto verify controller flows, safe-area behavior, translations, and Android TV input. - WebGL validation: keep
PostBuildProcessversion checks aligned with the AirConsole JS used inAssets/WebGLTemplates/AirConsole-*.
- Managed DLLs:
Newtonsoft.Json.dllandwebsocket-sharp.dllare underplugins/and referenced by runtime asmdefs. - Embedded webview:
unity-webviewincludes runtime/editor code plus native libs underunity-webview/Plugins. - Android native pieces are under
plugins/Android; ensure gradle/manifest processors remain compatible when updating them.
- Add/extend an API event: Update
WebsocketListenerto parse/route the action, expose it inAirConsole, and wire through logging; add tests where possible. - Adjust runtime defaults: Modify
AirconsoleRuntimeSettings.assetorNativeGameSizingSettings.asset(via editor windows). Avoid hardcoded constants in code. - Android manifest/Gradle edits: Implement changes in
AndroidManifestProcessor/AndroidGradleProcessor/AndroidProjectProcessor; ensureuseCustomMainManifeststays enabled. - WebGL template/JS version bumps: Update constants/regex in
PostBuildProcess, refreshSettings.RequiredMinimumVersionif needed, and sync HTML inAssets/WebGLTemplates/AirConsole-*. - Packaging/exports: Use
BuildHelper.BuildWeb(),BuildHelper.BuildAndroid(), orBuildHelper.BuildAndroidInternal(); they run configuration checks and can zip outputs.
- Conditional compilation is heavily used:
#if !DISABLE_AIRCONSOLE,UNITY_ANDROID,UNITY_EDITOR,UNITY_WEBGL. Keep new code behind appropriate defines and asmdefs. - Respect asmdef boundaries (
AirConsole.Runtime,AirConsole.Editor,AirConsole.SupportCheck,AirConsole.Examples,unity-webview); place new files in matching folders. - Embedded websocket/webview server underpins editor play; avoid breaking
WebsocketListener/WebViewManagerinteractions (ports come from runtime settings). - Safe-area handling is central for Android TV/Automotive—maintain
OnSafeAreaChangedflows and avoid state changes before safe-area readiness. - Build helper may auto-commit with
build: TIMESTAMPwhen uncommitted changes exist; be mindful when running locally.
The WebView plugin uses a thread-safe event queue to handle callbacks from native code (Android only at this point):
Events are processed at multiple points to ensure timely delivery:
Update(): Primary drain point (every frame)LateUpdate(): Secondary drain (end of frame)FixedUpdate(): Tertiary drain (physics frame / fixed timestep / before rendering)OnApplicationPause(false): Flush on resumeOnDisable(): Flush before component teardownOnApplicationQuit(): Final flush before app exit
Documentation_1.7.pdf(setup/examples),Documentation for AndroidTV.pdf, andUpgrade_Plugin_Version.mdfor upgrade flows.- Controller HTML template:
extras/controller-template.html. - Quick intro:
Assets/AirConsole/README.txt; preferences fileairconsole.prefs.