This commit is contained in:
ousttrue
2025-01-27 19:34:28 +09:00
parent e48867cfea
commit 6536238722
19 changed files with 206 additions and 14 deletions

View File

@@ -56,5 +56,8 @@
"Scriptable",
"UNIVRM"
],
"dotnet.defaultSolution": "UniVRM.sln"
"dotnet.defaultSolution": "UniVRM.sln",
"files.associations": {
"*.jslib": "javascript",
}
}

View File

@@ -7,9 +7,9 @@ namespace VRM.SimpleViewer
#if UNITY_STANDALONE_WIN
return FileDialogForWindows.FileDialog(title, extensions);
#elif UNITY_WEBGL
// Open UniVRM_Sample_WebGLFileDialog
// Open WebGL_VRM0X_SimpleViewer_FileDialog
// see: Assets/UniGLTF/Runtime/Utils/Plugins/OpenFile.jslib
WebGLUtil.UniVRM_Sample_WebGLFileDialog("Canvas", "FileSelected");
WebGLUtil.WebGL_VRM0X_SimpleViewer_FileDialog("Canvas", "FileSelected");
// Control flow does not return here. return empty string with dummy
return "";
#elif UNITY_EDITOR

View File

@@ -6,7 +6,7 @@ namespace VRM.SimpleViewer
public static class WebGLUtil
{
[DllImport("__Internal")]
public static extern void UniVRM_Sample_WebGLFileDialog(string target, string message);
public static extern void WebGL_VRM0X_SimpleViewer_FileDialog(string target, string message);
}
}
#endif

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 453de3a4f46d44d4087a1fca730e04d5
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,23 @@
mergeInto(LibraryManager.library, {
WebGL_VRM0X_SimpleViewer_FileDialog: function (_target, _message) {
const target = UTF8ToString(_target);
const message = UTF8ToString(_message);
const file_input_id = "file-input";
var file_input = document.getElementById(file_input_id);
if (!file_input) {
file_input = document.createElement('input');
file_input.setAttribute('type', 'file');
file_input.setAttribute('id', file_input_id);
file_input.style.visibility = 'hidden';
file_input.onclick = function (event) {
event.target.value = null;
};
file_input.onchange = function (event) {
console.log('SendMessage', target, message);
SendMessage(target, message, URL.createObjectURL(event.target.files[0]));
}
document.body.appendChild(file_input);
}
file_input.click();
},
});

View File

@@ -0,0 +1,32 @@
fileFormatVersion: 2
guid: ef25d97dc58954a4ca17b4173225e58f
PluginImporter:
externalObjects: {}
serializedVersion: 2
iconMap: {}
executionOrder: {}
defineConstraints: []
isPreloaded: 0
isOverridable: 0
isExplicitlyReferenced: 0
validateReferences: 1
platformData:
- first:
Any:
second:
enabled: 0
settings: {}
- first:
Editor: Editor
second:
enabled: 0
settings:
DefaultValueInitialized: true
- first:
WebGL: WebGL
second:
enabled: 1
settings: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,5 +1,5 @@
mergeInto(LibraryManager.library, {
UniVRM_Sample_WebGLFileDialog: function (_target, _message) {
WebGL_VRM10_VRM10Viewer_FileDialog: function (_target, _message) {
const target = UTF8ToString(_target);
const message = UTF8ToString(_message);
const file_input_id = "file-input";

View File

@@ -641,16 +641,16 @@ namespace UniVRM10.VRM10Viewer
}
[DllImport("__Internal")]
public static extern void UniVRM_Sample_WebGLFileDialog(string target, string message);
public static extern void WebGL_VRM10_VRM10Viewer_FileDialog(string target, string message);
string FileDialog()
{
#if UNITY_STANDALONE_WIN
return VRM10FileDialogForWindows.FileDialog("open VRM", "vrm");
#elif UNITY_WEBGL
// Open UniVRM_Sample_WebGLFileDialog
// Open WebGL_VRM10_VRM10Viewer_FileDialog
// see: Assets/UniGLTF/Runtime/Utils/Plugins/OpenFile.jslib
UniVRM_Sample_WebGLFileDialog("Canvas", "FileSelected");
WebGL_VRM10_VRM10Viewer_FileDialog("Canvas", "FileSelected");
// Control flow does not return here. return empty string with dummy
return null;
#elif UNITY_EDITOR

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: a75c9f76297d99041bdf9ca2458d12bb
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,23 @@
mergeInto(LibraryManager.library, {
WebGL_VRM10_VRM10Viewer_FileDialog: function (_target, _message) {
const target = UTF8ToString(_target);
const message = UTF8ToString(_message);
const file_input_id = "file-input";
var file_input = document.getElementById(file_input_id);
if (!file_input) {
file_input = document.createElement('input');
file_input.setAttribute('type', 'file');
file_input.setAttribute('id', file_input_id);
file_input.style.visibility = 'hidden';
file_input.onclick = function (event) {
event.target.value = null;
};
file_input.onchange = function (event) {
console.log('SendMessage', target, message);
SendMessage(target, message, URL.createObjectURL(event.target.files[0]));
}
document.body.appendChild(file_input);
}
file_input.click();
},
});

View File

@@ -0,0 +1,32 @@
fileFormatVersion: 2
guid: 2e8941ad33d65584f8ef2f8b829a05e7
PluginImporter:
externalObjects: {}
serializedVersion: 2
iconMap: {}
executionOrder: {}
defineConstraints: []
isPreloaded: 0
isOverridable: 0
isExplicitlyReferenced: 0
validateReferences: 1
platformData:
- first:
Any:
second:
enabled: 0
settings: {}
- first:
Editor: Editor
second:
enabled: 0
settings:
DefaultValueInitialized: true
- first:
WebGL: WebGL
second:
enabled: 1
settings: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -641,16 +641,16 @@ namespace UniVRM10.VRM10Viewer
}
[DllImport("__Internal")]
public static extern void UniVRM_Sample_WebGLFileDialog(string target, string message);
public static extern void WebGL_VRM10_VRM10Viewer_FileDialog(string target, string message);
string FileDialog()
{
#if UNITY_STANDALONE_WIN
return VRM10FileDialogForWindows.FileDialog("open VRM", "vrm");
#elif UNITY_WEBGL
// Open UniVRM_Sample_WebGLFileDialog
// Open WebGL_VRM10_VRM10Viewer_FileDialog
// see: Assets/UniGLTF/Runtime/Utils/Plugins/OpenFile.jslib
UniVRM_Sample_WebGLFileDialog("Canvas", "FileSelected");
WebGL_VRM10_VRM10Viewer_FileDialog("Canvas", "FileSelected");
// Control flow does not return here. return empty string with dummy
return null;
#elif UNITY_EDITOR

View File

@@ -7,9 +7,9 @@ namespace VRM.SimpleViewer
#if UNITY_STANDALONE_WIN
return FileDialogForWindows.FileDialog(title, extensions);
#elif UNITY_WEBGL
// Open UniVRM_Sample_WebGLFileDialog
// Open WebGL_VRM0X_SimpleViewer_FileDialog
// see: Assets/UniGLTF/Runtime/Utils/Plugins/OpenFile.jslib
WebGLUtil.UniVRM_Sample_WebGLFileDialog("Canvas", "FileSelected");
WebGLUtil.WebGL_VRM0X_SimpleViewer_FileDialog("Canvas", "FileSelected");
// Control flow does not return here. return empty string with dummy
return "";
#elif UNITY_EDITOR

View File

@@ -6,7 +6,7 @@ namespace VRM.SimpleViewer
public static class WebGLUtil
{
[DllImport("__Internal")]
public static extern void UniVRM_Sample_WebGLFileDialog(string target, string message);
public static extern void WebGL_VRM0X_SimpleViewer_FileDialog(string target, string message);
}
}
#endif

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 453de3a4f46d44d4087a1fca730e04d5
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,23 @@
mergeInto(LibraryManager.library, {
WebGL_VRM0X_SimpleViewer_FileDialog: function (_target, _message) {
const target = UTF8ToString(_target);
const message = UTF8ToString(_message);
const file_input_id = "file-input";
var file_input = document.getElementById(file_input_id);
if (!file_input) {
file_input = document.createElement('input');
file_input.setAttribute('type', 'file');
file_input.setAttribute('id', file_input_id);
file_input.style.visibility = 'hidden';
file_input.onclick = function (event) {
event.target.value = null;
};
file_input.onchange = function (event) {
console.log('SendMessage', target, message);
SendMessage(target, message, URL.createObjectURL(event.target.files[0]));
}
document.body.appendChild(file_input);
}
file_input.click();
},
});

View File

@@ -0,0 +1,32 @@
fileFormatVersion: 2
guid: ef25d97dc58954a4ca17b4173225e58f
PluginImporter:
externalObjects: {}
serializedVersion: 2
iconMap: {}
executionOrder: {}
defineConstraints: []
isPreloaded: 0
isOverridable: 0
isExplicitlyReferenced: 0
validateReferences: 1
platformData:
- first:
Any:
second:
enabled: 0
settings: {}
- first:
Editor: Editor
second:
enabled: 0
settings:
DefaultValueInitialized: true
- first:
WebGL: WebGL
second:
enabled: 1
settings: {}
userData:
assetBundleName:
assetBundleVariant: