Skip to content

Commit 8405348

Browse files
authored
Merge pull request #3 from decentraland/feat/update-post-messages
feat: Add OnLoadComplete event
2 parents 0dc5c37 + d0c3d14 commit 8405348

2 files changed

Lines changed: 42 additions & 7 deletions

File tree

Assets/JSPlugin/JSBridge.jslib

Lines changed: 36 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,41 @@
11
mergeInto(LibraryManager.library, {
22
OnScreenshotTaken: function (strPtr) {
3-
const base64str = UTF8ToString(strPtr);
4-
window.parent.postMessage(
3+
const base64str = UTF8ToString(strPtr)
4+
const targetWindow = (() => {
5+
try {
6+
return window.self !== window.top ? window : window.parent
7+
} catch (e) {
8+
return window.parent
9+
}
10+
})()
11+
targetWindow.postMessage(
512
{
6-
type: 'unity-screenshot',
7-
data: base64str
13+
type: 'unity-renderer',
14+
payload: {
15+
type: 'screenshot',
16+
payload: base64str,
17+
},
818
},
919
'*'
10-
);
11-
}
12-
});
20+
)
21+
},
22+
OnLoadComplete: function () {
23+
const targetWindow = (() => {
24+
try {
25+
return window.self !== window.top ? window : window.parent
26+
} catch (e) {
27+
return window.parent
28+
}
29+
})()
30+
targetWindow.postMessage(
31+
{
32+
type: 'unity-renderer',
33+
payload: {
34+
type: 'loaded',
35+
payload: true,
36+
},
37+
},
38+
'*'
39+
)
40+
},
41+
})

Assets/Scripts/PreviewLoader.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using System.Linq;
44
using System.Text;
55
using System.Threading.Tasks;
6+
using System.Runtime.InteropServices;
67
using Data;
78
using GLTF;
89
using JetBrains.Annotations;
@@ -33,6 +34,9 @@ public class PreviewLoader : MonoBehaviour
3334
public bool HasEmoteAudio => _emoteAudio != null;
3435
public bool HasWearableOverride => _overrideWearableCategory != null && !HasEmoteOverride;
3536

37+
[DllImport("__Internal")]
38+
private static extern void OnLoadComplete();
39+
3640
public async Awaitable LoadPreview(PreviewConfiguration config)
3741
{
3842
gameObject.SetActive(false);
@@ -211,6 +215,8 @@ await Task.WhenAll(wearableDefinitions
211215
}
212216

213217
Debug.Log("Loaded all wearables!");
218+
219+
OnLoadComplete();
214220
}
215221

216222
private void SetupFacialFeatures(GameObject bodyGO)

0 commit comments

Comments
 (0)