2using System.Collections;
3using System.Collections.Generic;
5using System.Runtime.InteropServices;
15 public static class WebGLFileUploadManager
20 public static event Action<UploadedFileInfoV2[]> onFileUploaded;
32 public static bool Show (
bool isDropInput =
false,
bool isOverlay =
false,
int x = -1,
int y = -1,
int width = -1,
int height = -1)
34 #if UNITY_WEBGL && !UNITY_EDITOR
35 bool success = WebGLFileUploadManager.Unity_FileUploadManager_Show(isDropInput, isOverlay, x, y, width, height);
36 WebGLFileUploadManager.Unity_FileUploadManager_SetCallback (WebGLFileUploadManager.Callback);
50 public static bool PopupDialog (
string titleText =
"",
string uploadBtnText =
"",
string cancelBtnText =
"")
52 #if UNITY_WEBGL && !UNITY_EDITOR
53 if (Screen.fullScreen)
55 if( Unity_FileUploadManager_IsRunningOnEdgeBrowser() ){
56 Screen.fullScreen =
false;
58 Unity_FileUploadManager_HideUnityScreenIfHtmlOverlayCant();
61 bool success = WebGLFileUploadManager.Unity_FileUploadManager_PopupDialog(titleText, uploadBtnText, cancelBtnText);
62 WebGLFileUploadManager.Unity_FileUploadManager_SetCallback (WebGLFileUploadManager.Callback);
72 public static void Hide ()
74 #if UNITY_WEBGL && !UNITY_EDITOR
75 WebGLFileUploadManager.Unity_FileUploadManager_Hide ();
79 public static void Dispose ()
81 #if UNITY_WEBGL && !UNITY_EDITOR
82 WebGLFileUploadManager.Unity_FileUploadManager_Dispose();
86 public static void Enable ()
88 #if UNITY_WEBGL && !UNITY_EDITOR
89 WebGLFileUploadManager.Unity_FileUploadManager_Enable ();
93 public static void Disable ()
95 #if UNITY_WEBGL && !UNITY_EDITOR
96 WebGLFileUploadManager.Unity_FileUploadManager_Disable();
100 public static void SetDescription (
string description)
102 #if UNITY_WEBGL && !UNITY_EDITOR
103 WebGLFileUploadManager.Unity_FileUploadManager_SetDescription (description);
107 public static void SetAllowedFileName (
string filenameReg)
109 #if UNITY_WEBGL && !UNITY_EDITOR
110 WebGLFileUploadManager.Unity_FileUploadManager_SetAllowedFileName (filenameReg);
113 public static void SetImageEncodeSetting (
bool enable,
int threshold = -1)
115 #if UNITY_WEBGL && !UNITY_EDITOR
116 WebGLFileUploadManager.Unity_FileUploadManager_SetImageEncodeSetting (enable, threshold);
120 public static void SetImageShrinkingSize (
int width = 640,
int height = 480)
122 #if UNITY_WEBGL && !UNITY_EDITOR
123 WebGLFileUploadManager.Unity_FileUploadManager_SetImageShrinkingSize (width, height);
127 public static bool IsDropInput {
129 #if UNITY_WEBGL && !UNITY_EDITOR
130 return WebGLFileUploadManager.Unity_FileUploadManager_IsDropInput ();
137 public static bool IsOverlay {
139 #if UNITY_WEBGL && !UNITY_EDITOR
140 return WebGLFileUploadManager.Unity_FileUploadManager_IsOverlay ();
147 public static bool IsPopupDialog {
149 #if UNITY_WEBGL && !UNITY_EDITOR
150 return WebGLFileUploadManager.Unity_FileUploadManager_IsPopupDialog ();
157 public static void SetDebug (
bool value)
159 #if UNITY_WEBGL && !UNITY_EDITOR
160 WebGLFileUploadManager.Unity_FileUploadManager_SetDebug (value);
166 #if UNITY_WEBGL && !UNITY_EDITOR
167 string osName = Unity_FileUploadManager_GetOS();
200 public static bool IsMOBILE {
202 #if UNITY_WEBGL && !UNITY_EDITOR
203 return Unity_FileUploadManager_IsMobile();
210 public static bool IsIOS {
212 #if UNITY_WEBGL && !UNITY_EDITOR
220 public static bool IsMac {
222 #if UNITY_WEBGL && !UNITY_EDITOR
230 public static bool IsAndroid {
232 #if UNITY_WEBGL && !UNITY_EDITOR
233 return (getOS ==
OS_NAME.Android);
240 public static bool IsWindows {
242 #if UNITY_WEBGL && !UNITY_EDITOR
243 return (getOS ==
OS_NAME.Windows);
250 public static bool IsChromeOS {
252 #if UNITY_WEBGL && !UNITY_EDITOR
253 return (getOS ==
OS_NAME.ChromeOS);
260 public static bool IsFireFoxOS {
262 #if UNITY_WEBGL && !UNITY_EDITOR
263 return (getOS ==
OS_NAME.FireFoxOS);
270 public static string GetUserAgent
273 #if UNITY_WEBGL && !UNITY_EDITOR
274 return Unity_FileUploadManager_GetUserAgent();
283 [DllImport (
"__Internal")]
284 private static extern bool Unity_FileUploadManager_Show (
bool isDropInput,
bool isOverlay,
int x,
int y,
int width,
int height);
286 [DllImport (
"__Internal")]
287 private static extern bool Unity_FileUploadManager_PopupDialog (
string title,
string uploadBtnText,
string cancelBtnText);
289 [DllImport (
"__Internal")]
290 private static extern void Unity_FileUploadManager_Hide ();
292 [DllImport (
"__Internal")]
293 private static extern void Unity_FileUploadManager_Dispose ();
295 [DllImport (
"__Internal")]
296 private static extern void Unity_FileUploadManager_Enable ();
298 [DllImport (
"__Internal")]
299 private static extern void Unity_FileUploadManager_Disable ();
301 [DllImport (
"__Internal")]
302 private static extern void Unity_FileUploadManager_SetCallback (Action<string> callback);
304 [AOT.MonoPInvokeCallback (typeof(Action<string>))]
305 private static void Callback (
string fileUploadDataJSON)
307 Debug.Log (
"Callback called " + fileUploadDataJSON);
309 if(onFileUploaded ==
null) {
310 Debug.Log (
"onFileUploaded == null");
315 if (!
string.IsNullOrEmpty(fileUploadDataJSON))
317 Debug.Log($
"fileUploadDataJSON");
322 var filePathIndex = fileUploadDataJSON.IndexOf(
"filePath\":\"") + 11;
323 var fileNameIndex = fileUploadDataJSON.IndexOf(
"name\":\"") + 7;
325 var filePath = fileUploadDataJSON.Remove(0, filePathIndex);
326 var fileName = fileUploadDataJSON.Remove(0, fileNameIndex);
327 Debug.Log($
"filePath1: {filePath}");
328 filePath = filePath.Remove(filePath.IndexOf(
'"')).Replace(
"\"",
"");
329 fileName = fileName.Remove(fileName.IndexOf(
'"')).Replace(
"\"",
"");
330 Debug.Log($
"filePath2: {filePath}");
331 Debug.Log($
"fileName: {fileName}");
337 isSuccess = fileUploadDataJSON.Contains(
"true"),
344 onFileUploaded.Invoke(files);
349 onFileUploaded.Invoke(files);
355 [DllImport (
"__Internal")]
356 private static extern void Unity_FileUploadManager_SetDescription (
string str);
358 [DllImport (
"__Internal")]
359 private static extern void Unity_FileUploadManager_SetAllowedFileName (
string str);
361 [DllImport (
"__Internal")]
362 private static extern void Unity_FileUploadManager_SetImageShrinkingSize (
int width,
int height);
364 [DllImport (
"__Internal")]
365 private static extern void Unity_FileUploadManager_SetImageEncodeSetting (
bool enable,
int threshold);
367 [DllImport (
"__Internal")]
368 private static extern bool Unity_FileUploadManager_IsDropInput ();
370 [DllImport (
"__Internal")]
371 private static extern bool Unity_FileUploadManager_IsOverlay ();
373 [DllImport (
"__Internal")]
374 private static extern bool Unity_FileUploadManager_IsPopupDialog ();
376 [DllImport (
"__Internal")]
377 private static extern void Unity_FileUploadManager_SetDebug (
bool value);
379 [DllImport (
"__Internal")]
380 private static extern string Unity_FileUploadManager_GetOS ();
382 [DllImport (
"__Internal")]
383 private static extern bool Unity_FileUploadManager_IsMobile ();
385 [DllImport (
"__Internal")]
386 private static extern string Unity_FileUploadManager_GetUserAgent ();
388 [DllImport(
"__Internal")]
389 private static extern void Unity_FileUploadManager_HideUnityScreenIfHtmlOverlayCant();
391 [DllImport(
"__Internal")]
392 private static extern bool Unity_FileUploadManager_IsRunningOnEdgeBrowser();
396 class FileUploadResult
402 struct FileUploadResultV2