From 8cabee9d2aab1b2bc24ddfec6a39efd378d6db92 Mon Sep 17 00:00:00 2001 From: Nicholas Perell <58918508+nicholas-hoy-champain@users.noreply.github.com> Date: Fri, 21 Jun 2024 17:30:30 -0400 Subject: [PATCH 1/3] Add ability for WebGL to download from a segement of a byte array (#2) Useful for grabbing the correct segment of a buffer, like in a MemoryStream. Avoids using ToArray on the C# end, which makes a copy. --- .../Plugins/StandaloneFileBrowser.jslib | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/StandaloneFileBrowser/Plugins/StandaloneFileBrowser.jslib b/StandaloneFileBrowser/Plugins/StandaloneFileBrowser.jslib index 48c8739..ca09823 100644 --- a/StandaloneFileBrowser/Plugins/StandaloneFileBrowser.jslib +++ b/StandaloneFileBrowser/Plugins/StandaloneFileBrowser.jslib @@ -54,6 +54,39 @@ var StandaloneFileBrowserWebGLPlugin = { } }, + // Save file from span of bytes + // DownloadFile method does not open SaveFileDialog like standalone builds, its just allows user to download file + // gameObjectNamePtr: Unique GameObject name. Required for calling back unity with SendMessage. + // methodNamePtr: Callback method name on given GameObject. + // filenamePtr: Filename with extension + // byteArray: byte[] to pull a span from + // byteSpanStart: start index of span + // byteSpanSize: length of span + DownloadFileSpan: function(gameObjectNamePtr, methodNamePtr, filenamePtr, byteArray, byteSpanStart, byteSpanSize) { + gameObjectName = UTF8ToString(gameObjectNamePtr); + methodName = UTF8ToString(methodNamePtr); + filename = UTF8ToString(filenamePtr); + + var bytes = new Uint8Array(byteSpanSize); + for (var i = 0; i < byteSpanSize; i++) { + bytes[i] = HEAPU8[byteArray + byteSpanStart + i]; + } + + var downloader = window.document.createElement('a'); + downloader.setAttribute('id', gameObjectName); + downloader.href = window.URL.createObjectURL(new Blob([bytes], { type: 'application/octet-stream' })); + downloader.download = filename; + document.body.appendChild(downloader); + + document.onmouseup = function() { + downloader.click(); + document.body.removeChild(downloader); + document.onmouseup = null; + + SendMessage(gameObjectName, methodName); + } + }, + // Save file // DownloadFile method does not open SaveFileDialog like standalone builds, its just allows user to download file // gameObjectNamePtr: Unique GameObject name. Required for calling back unity with SendMessage. From 69dd5b70d767673d9673578c6d5bedaacf9a5a82 Mon Sep 17 00:00:00 2001 From: Nicholas Perell <58918508+nicholas-hoy-champain@users.noreply.github.com> Date: Fri, 21 Jun 2024 17:37:54 -0400 Subject: [PATCH 2/3] Update package.json ver # --- StandaloneFileBrowser/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/StandaloneFileBrowser/package.json b/StandaloneFileBrowser/package.json index 9b3c951..656606d 100644 --- a/StandaloneFileBrowser/package.json +++ b/StandaloneFileBrowser/package.json @@ -3,7 +3,7 @@ "description": "Native open and save UIs for Windows, MacOS, Linux, WebGL", "name": "com.virtualmaker.filebrowser", "unity": "2019.4", - "version": "1.0.3", + "version": "1.0.4", "category": "utilities", "dependencies": {} } From fed7e2d944b53b3e20373888bd2dab3033219a0b Mon Sep 17 00:00:00 2001 From: Nicholas Perell <58918508+nicholas-hoy-champain@users.noreply.github.com> Date: Fri, 21 Jun 2024 17:46:53 -0400 Subject: [PATCH 3/3] Update package.json --- StandaloneFileBrowser/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/StandaloneFileBrowser/package.json b/StandaloneFileBrowser/package.json index 656606d..2ca4129 100644 --- a/StandaloneFileBrowser/package.json +++ b/StandaloneFileBrowser/package.json @@ -3,7 +3,7 @@ "description": "Native open and save UIs for Windows, MacOS, Linux, WebGL", "name": "com.virtualmaker.filebrowser", "unity": "2019.4", - "version": "1.0.4", + "version": "1.0.5", "category": "utilities", "dependencies": {} }