Tanoda
FileUploadExample.cs
Go to the documentation of this file.
1using System.Collections;
2using System.IO;
3using UnityEngine;
5
6#if UNITY_5_3 || UNITY_5_3_OR_NEWER
7using UnityEngine.SceneManagement;
8#endif
9
11{
15 public class FileUploadExample : MonoBehaviour
16 {
17 // Use this for initialization
18 void Start ()
19 {
20 Debug.Log("WebGLFileUploadManager.getOS: " + WebGLFileUploadManager.getOS);
21 Debug.Log("WebGLFileUploadManager.isMOBILE: " + WebGLFileUploadManager.IsMOBILE);
22 Debug.Log("WebGLFileUploadManager.getUserAgent: " + WebGLFileUploadManager.GetUserAgent);
23
24 WebGLFileUploadManager.SetDebug(true);
25 if (
26 #if UNITY_WEBGL && !UNITY_EDITOR
27 WebGLFileUploadManager.IsMOBILE
28 #else
29 Application.isMobilePlatform
30 #endif
31 ) {
32 WebGLFileUploadManager.Show (false);
33 WebGLFileUploadManager.SetDescription("Select image files (.png|.jpg|.gif)");
34
35 }else{
36 WebGLFileUploadManager.Show (true);
37 WebGLFileUploadManager.SetDescription("Drop image files (.png|.jpg|.gif) here");
38 }
39 WebGLFileUploadManager.SetImageEncodeSetting(true);
40 WebGLFileUploadManager.SetAllowedFileName("\\.(png|jpe?g|gif)$");
41 WebGLFileUploadManager.SetImageShrinkingSize(1280 ,960);
42 WebGLFileUploadManager.onFileUploaded += OnFileUploaded;
43 }
44
45 // Update is called once per frame
46 void Update ()
47 {
48
49 }
50
54 void OnDestroy ()
55 {
56 WebGLFileUploadManager.onFileUploaded -= OnFileUploaded;
57 WebGLFileUploadManager.Dispose();
58 }
59
64 private void OnFileUploaded(UploadedFileInfoV2[] result)
65 {
66 if(result.Length == 0) {
67 Debug.Log("File upload Error!");
68 }else{
69 Debug.Log("File upload success! (result.Length: " + result.Length + ")");
70 }
71
72 foreach(var file in result){
73 if(file.isSuccess){
74 Debug.Log("file.filePath: " + file.filePath + " exists:" + File.Exists(file.filePath));
75
76 Texture2D texture = new Texture2D (2, 2);
77 byte[] byteArray = File.ReadAllBytes (file.filePath);
78 texture.LoadImage (byteArray);
79 gameObject.GetComponent<Renderer> ().material.mainTexture = texture;
80
81 Debug.Log("File.ReadAllBytes:byte[].Length: " + byteArray.Length);
82
83 break;
84 }
85 }
86 }
87
91 public void OnBackButtonClick ()
92 {
93 #if UNITY_5_3 || UNITY_5_3_OR_NEWER
94 SceneManager.LoadScene ("WebGLFileUploaderExample");
95 #else
96 Application.LoadLevel ("WebGLFileUploaderExample");
97 #endif
98 }
99
104 {
105 WebGLFileUploadManager.Show(false, !WebGLFileUploadManager.IsOverlay);
106 }
107
112 {
113 WebGLFileUploadManager.Show(true, !WebGLFileUploadManager.IsOverlay);
114 }
115
120 {
121 WebGLFileUploadManager.PopupDialog(null, "Select image files (.png|.jpg|.gif)");
122 }
123
127 public void OnEnableButtonClick ()
128 {
129 WebGLFileUploadManager.Enable ();
130 }
131
135 public void OnDisableButtonClick ()
136 {
137 WebGLFileUploadManager.Disable ();
138 }
139 }
140}
UnityEngine.Debug Debug
Definition: TanodaServer.cs:19
void OnDisableButtonClick()
Raises the disable button click event.
void OnEnableButtonClick()
Raises the enable button click event.
void OnBackButtonClick()
Raises the back button click event.
void OnSwitchButtonOverlayStateButtonClick()
Raises the switch button overlay state button click event.
void OnSwitchDropOverlayStateButtonClick()
Raises the switch drop overlay state button click event.
void OnPopupDialogButtonClick()
Raises the popup dialog button click event.