Skip to content

Commit 4f1a7ac

Browse files
committed
Add native pairing to Unity example
1 parent adf29d3 commit 4f1a7ac

9 files changed

Lines changed: 95 additions & 23 deletions

File tree

‎Assets/Resources.meta‎

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
%YAML 1.1
2+
%TAG !u! tag:unity3d.com,2011:
3+
--- !u!114 &11400000
4+
MonoBehaviour:
5+
m_ObjectHideFlags: 0
6+
m_CorrespondingSourceObject: {fileID: 0}
7+
m_PrefabInstance: {fileID: 0}
8+
m_PrefabAsset: {fileID: 0}
9+
m_GameObject: {fileID: 0}
10+
m_Enabled: 1
11+
m_EditorHideFlags: 0
12+
m_Script: {fileID: 11500000, guid: 6e2143e79984bc98d820e9e880430b87, type: 3}
13+
m_Name: PrototirSettings
14+
m_EditorClassIdentifier: Prototir.Unity::Prototir.PrototirSettings
15+
prototypeSlug:
16+
apiBaseUrl: https://api.prototir.com/api
17+
deviceLabel:

‎Assets/Resources/PrototirSettings.asset.meta‎

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎Assets/Scripts/PrototirExample.cs‎

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,14 @@ public sealed class PrototirExample : MonoBehaviour
1111

1212
private async void Start()
1313
{
14+
// This IMGUI-only scene has no camera in its hierarchy. A solid backdrop also keeps the
15+
// native pairing overlay free of Unity's "No cameras rendering" message.
16+
if (FindFirstObjectByType<Camera>() == null)
17+
{
18+
var camera = new GameObject("Example backdrop").AddComponent<Camera>();
19+
camera.clearFlags = CameraClearFlags.SolidColor;
20+
camera.backgroundColor = new Color(0.059f, 0.059f, 0.067f);
21+
}
1422
#if UNITY_EDITOR
1523
PrototirSdk.MockAiHandler = options =>
1624
Task.FromResult($"Editor mock: explore the signal hidden beyond the next door.");
@@ -31,7 +39,7 @@ private async void Start()
3139
private void OnGUI()
3240
{
3341
var width = Mathf.Min(560f, Screen.width - 40f);
34-
var height = Mathf.Min(520f, Screen.height - 40f);
42+
var height = Mathf.Min(580f, Screen.height - 40f);
3543
var area = new Rect((Screen.width - width) / 2f, (Screen.height - height) / 2f, width, height);
3644
GUILayout.BeginArea(area, GUI.skin.box);
3745
GUILayout.Space(20);
@@ -42,12 +50,26 @@ private void OnGUI()
4250
GUI.enabled = !busy;
4351
if (GUILayout.Button("Add 10 points", GUILayout.Height(52))) _ = AddPointsAsync();
4452
if (GUILayout.Button("Generate a quest hook", GUILayout.Height(52))) _ = GenerateQuestAsync();
53+
#if !UNITY_WEBGL || UNITY_EDITOR
54+
if (GUILayout.Button(PrototirSdk.IsPaired ? "Connection" : "Pair this build", GUILayout.Height(52)))
55+
OpenPairing();
56+
#endif
4557
GUI.enabled = true;
4658
GUILayout.Space(16);
4759
GUILayout.Label(status, GUI.skin.textArea, GUILayout.ExpandHeight(true));
4860
GUILayout.EndArea();
4961
}
5062

63+
#if !UNITY_WEBGL || UNITY_EDITOR
64+
private void OpenPairing()
65+
{
66+
// Hide the playground while the SDK overlay is open, then bring it back on dismissal.
67+
enabled = false;
68+
var screen = Prototir.Native.PrototirPairingScreen.Show();
69+
screen.Closed += () => { if (this != null) enabled = true; };
70+
}
71+
#endif
72+
5173
private async Task AddPointsAsync()
5274
{
5375
busy = true;

‎Packages/manifest.json‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
{
22
"dependencies": {
3-
"com.prototir.sdk": "https://github.com/prototir/unity-sdk.git#v0.2.0",
4-
"com.unity.collab-proxy": "2.11.2",
5-
"com.unity.ide.rider": "3.0.38",
6-
"com.unity.ide.visualstudio": "2.0.25",
3+
"com.prototir.sdk": "https://github.com/prototir/unity-sdk.git#8086c3776afe11c90cb49a1f32fd02d03a265b0d",
4+
"com.unity.collab-proxy": "2.13.6",
5+
"com.unity.ide.rider": "3.0.40",
6+
"com.unity.ide.visualstudio": "2.0.26",
77
"com.unity.ide.vscode": "1.2.5",
88
"com.unity.test-framework": "1.6.0",
9-
"com.unity.timeline": "1.8.9",
9+
"com.unity.timeline": "1.8.13",
1010
"com.unity.ugui": "2.0.0"
1111
}
1212
}

‎Packages/packages-lock.json‎

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
{
22
"dependencies": {
33
"com.prototir.sdk": {
4-
"version": "https://github.com/prototir/unity-sdk.git#v0.1.0",
4+
"version": "https://github.com/prototir/unity-sdk.git#8086c3776afe11c90cb49a1f32fd02d03a265b0d",
55
"depth": 0,
66
"source": "git",
7-
"dependencies": {},
8-
"hash": "f413fc042315383a7da41ba88f9b97985cc1c065"
7+
"dependencies": {
8+
"com.unity.modules.unitywebrequest": "1.0.0",
9+
"com.unity.modules.jsonserialize": "1.0.0"
10+
},
11+
"hash": "8086c3776afe11c90cb49a1f32fd02d03a265b0d"
912
},
1013
"com.unity.collab-proxy": {
11-
"version": "2.11.2",
14+
"version": "2.13.6",
1215
"depth": 0,
1316
"source": "registry",
1417
"dependencies": {},
@@ -21,7 +24,7 @@
2124
"dependencies": {}
2225
},
2326
"com.unity.ide.rider": {
24-
"version": "3.0.38",
27+
"version": "3.0.40",
2528
"depth": 0,
2629
"source": "registry",
2730
"dependencies": {
@@ -30,11 +33,11 @@
3033
"url": "https://packages.unity.com"
3134
},
3235
"com.unity.ide.visualstudio": {
33-
"version": "2.0.25",
36+
"version": "2.0.26",
3437
"depth": 0,
3538
"source": "registry",
3639
"dependencies": {
37-
"com.unity.test-framework": "1.1.31"
40+
"com.unity.test-framework": "1.1.33"
3841
},
3942
"url": "https://packages.unity.com"
4043
},
@@ -56,7 +59,7 @@
5659
}
5760
},
5861
"com.unity.timeline": {
59-
"version": "1.8.9",
62+
"version": "1.8.13",
6063
"depth": 0,
6164
"source": "registry",
6265
"dependencies": {
@@ -120,6 +123,12 @@
120123
"depth": 1,
121124
"source": "builtin",
122125
"dependencies": {}
126+
},
127+
"com.unity.modules.unitywebrequest": {
128+
"version": "1.0.0",
129+
"depth": 1,
130+
"source": "builtin",
131+
"dependencies": {}
123132
}
124133
}
125134
}

‎ProjectSettings/ProjectVersion.txt‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
m_EditorVersion: 6000.3.9f1
2-
m_EditorVersionWithRevision: 6000.3.9f1 (7a9955a4f2fa)
1+
m_EditorVersion: 6000.3.23f1
2+
m_EditorVersionWithRevision: 6000.3.23f1 (09d2ecc7fb28)

‎README.md‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,18 @@ through the SDK's local mocks.
1010
1. Install Unity 6 with Web Build Support.
1111
2. Clone this repository.
1212
3. Open the repository folder as a Unity project.
13-
4. Wait for Package Manager to install `com.prototir.sdk` from the pinned `v0.1.0` tag.
13+
4. Wait for Package Manager to install `com.prototir.sdk` from the pinned SDK commit.
1414
5. Open **Prototir > Project Setup** and resolve every blocking issue.
1515
6. Open `Assets/Scenes/Main.unity` and enter Play mode.
1616

1717
The example configures a local managed-AI mock in the Editor. A Web build uses the real Prototir
1818
player and requires managed AI to be enabled for the uploaded prototype.
1919

20+
For a native build, press **Pair this build** in the example scene. The SDK displays a code and QR
21+
over the game; scan and approve it to connect the build. The playground returns when you close the
22+
pairing screen. In the Editor, set `Assets/Resources/PrototirSettings.asset` to a prototype slug
23+
before pairing. A downloaded build receives its slug from Prototir during upload.
24+
2025
## Build and upload
2126

2227
1. Switch to the Web platform.

‎tools/check.mjs‎

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,19 @@ for (const path of [
1111
]) assert.ok(existsSync(new URL(`../${path}`, import.meta.url)), `Missing ${path}`);
1212

1313
const packages = JSON.parse(read('Packages/manifest.json'));
14-
// The invariant is that the example pins a release, not that it pins one particular release.
15-
// A literal version here only asserted that nobody had shipped an SDK since, and the fix was to
16-
// edit the number, which proves nothing: what actually matters is that two people opening this
17-
// example on different days get the same code.
14+
// Pin an immutable SDK revision so two people opening this project get the same code. A tagged
15+
// release or a full commit hash works; Unity does not accept an abbreviated hash.
1816
const sdk = packages.dependencies['com.prototir.sdk'];
1917
assert.match(
2018
sdk,
21-
/^https:\/\/github\.com\/prototir\/unity-sdk\.git#v\d+\.\d+\.\d+$/,
22-
`the example must pin a tagged SDK release, got ${sdk}`
19+
/^https:\/\/github\.com\/prototir\/unity-sdk\.git#(?:v\d+\.\d+\.\d+|[0-9a-f]{40})$/,
20+
`the example must pin an immutable SDK revision, got ${sdk}`
2321
);
22+
const lockedSdk = JSON.parse(read('Packages/packages-lock.json')).dependencies['com.prototir.sdk'];
23+
assert.equal(lockedSdk.version, sdk, 'the lockfile must resolve the SDK revision in the manifest');
24+
assert.equal(lockedSdk.source, 'git');
25+
if (/#[0-9a-f]{40}$/.test(sdk))
26+
assert.equal(lockedSdk.hash, sdk.slice(-40), 'the lockfile must use that exact SDK commit');
2427
const manifest = JSON.parse(read('Assets/Prototir/prototir.json'));
2528
assert.equal(manifest.runtime?.engine, 'unity');
2629
assert.equal(manifest.runtime?.profile, 'standard');

0 commit comments

Comments
 (0)