不知道怎么使用阿里云OSS的,请点击这里
更多OSS详细的设置请看另一篇文章,请点击这里
这两个文章的功能都是一样的,只是另一个文字,打包网页后,不能调用Win系统对话框选择图片,只能把程序里的image的图片上传到OSS,
当前文章可以实现打开Win系统对话框选择本地图片上传到OSS
第一步 在Plugins文件下创建 OSSFileUploader.jslib(用记事本创建,更改后缀名就行)文件
mergeInto(LibraryManager.library, {
// Global variables for callback functions
uploadCallback: null,
statusCallback: null,
// Initialize uploader
InitializeUploader: function() {
// Create hidden file input element
var fileInput = document.createElement('input');
fileInput.type = 'file';
fileInput.id = 'unityFileInput';
fileInput.style.display = 'none';
document.body.appendChild(fileInput);
// Listen for file selection events
fileInput.addEventListener('change', async function(event) {
var file = event.target.files[0];
if (file) {
console.log('Unity selected file:', file.name);
// Get global scope safely within the event handler
var globalScope;
if (typeof window !== 'undefined') {
globalScope = window;
} else if (typeof global !== 'undefined') {
globalScope = global;
} else if (typeof self !== 'undefined') {
globalScope = self;
} else {
globalScope = {
};
}
// Call Unity callback function
if (globalScope.uploadCallbackObjectName && globalScope.uploadCallbackMethodName) {
SendMessage(globalScope.uploadCallbackObjectName, globalScope.uploadCallbackMethodName, file.name);
}
// Start upload - inline all functionality here
try {
// Notify Unity of status update
if (globalScope.statusCallbackObjectName && globalScope.statusCallbackMethodName) {
SendMessage(globalScope.statusCallbackObjectName, globalScope.statusCallbackMethodName, "Getting upload signature...");
}
// Generate timestamped filename
var now = new Date();
var timestamp = now.getFullYear() +
String(now.getMonth() + 1).padStart(2, '0') +
String(now.getDate()).padStart(2, '0') +
String(now.getHours()).padStart(2, '0') +
String(now.getMinutes()).padStart(2, '0') +
String(now.getSeconds()

最低0.47元/天 解锁文章
6692

被折叠的 条评论
为什么被折叠?



