Tanoda
FileDragAndDrop.cs
Go to the documentation of this file.
1using System;
2using System.Collections;
3using System.Collections.Generic;
4using System.IO;
5using System.Linq;
6using System.Text;
7using UnityEngine;
8using B83.Win32;
9using GILES.Interface;
10using UnityEngine.Networking;
11using UnityEngine.UI;
12using UnityEngine.Video;
13using NaughtyAttributes;
14using TMPro;
15#if TRILIB_2
16using TriLibCore;
17using TriLibCore.SFB;
18#endif
20
21public class FileDragAndDrop : MonoBehaviour
22{
25
26 private RuntimeTriLibLoader trlib;
27 private RuntimeCADLoader cadLoader;
28 private bool isLoading = true;
29 private Preloader currentPreloader;
30
31 internal GameObject paretnObject;
32 private Coroutine lateRebuild;
33#if UNITY_EDITOR
34 public bool EditorFastLoad;
35#endif
36 System.Diagnostics.Stopwatch stopwatch = new System.Diagnostics.Stopwatch();
37
38 void Start()
39 {
40 instance = this;
41
42 currentPreloader = FindObjectOfType<Preloader>();
43
44 paretnObject = new GameObject("uploaded objects");
45 paretnObject.SetActive(false);
46 trlib = GameObject.Find("RuntimeTriLibLoader")?.GetComponent<RuntimeTriLibLoader>();
47 cadLoader = GameObject.Find("RuntimeTriLibLoader")?.GetComponent<RuntimeCADLoader>();
48
49#if !UNITY_WEBGL
50 Directory.CreateDirectory(Path.Combine(Application.streamingAssetsPath, "models"));
51 Directory.CreateDirectory(Path.Combine(Application.streamingAssetsPath, "pictures"));
52 Directory.CreateDirectory(Path.Combine(Application.streamingAssetsPath, "quizes"));
53 Directory.CreateDirectory(Path.Combine(Application.streamingAssetsPath, "sounds"));
54 Directory.CreateDirectory(Path.Combine(Application.streamingAssetsPath, "videos"));
55 Directory.CreateDirectory(Path.Combine(Application.streamingAssetsPath, "scripts"));
56 Directory.CreateDirectory(Path.Combine(Application.streamingAssetsPath, "helps"));
57#endif
58#if UNITY_WEBGL
59 WebGLFileUploadManager.SetDebug(false);
60 if (
61#if UNITY_WEBGL && !UNITY_EDITOR
62 WebGLFileUploadManager.IsMOBILE
63#else
64 Application.isMobilePlatform
65#endif
66 )
67 {
68 WebGLFileUploadManager.Show(false);
69 WebGLFileUploadManager.SetDescription("Select assets files");
70
71 }
72 else
73 {
74 WebGLFileUploadManager.Show(true);
75 WebGLFileUploadManager.SetDescription("Húzza ide a feltöltendõ fájljait");
76 }
77 WebGLFileUploadManager.SetImageShrinkingSize(4096, 4096);
78 //WebGLFileUploadManager.SetAllowedFileName("\\.(assetBundle|obj|gltf|glb|stl|3dxml)$");
79 WebGLFileUploadManager.onFileUploaded += OnFileUploaded;
80#endif
81
82#if UNITY_EDITOR && !UNITY_WEBGL
83 if (EditorFastLoad)
84 {
85 try
86 {
87 TestLoadImage();
88 }
89 catch (Exception)
90 {
91 }
92 try
93 {
94 TestLoadModel();
95 }
96 catch (Exception)
97 {
98 }
99 try
100 {
101 TestLoadModel2();
102 }
103 catch (Exception)
104 {
105 }
106 }
107#endif
108 }
109
110 public bool GetUploadedGOFromName(string value, out GameObject retval)
111 {
112 if (string.IsNullOrEmpty(value))
113 {
114 retval = null;
115 return false;
116 }
117 retval = paretnObject.transform.Find(value)?.gameObject;
118 return retval != null;
119 }
120
121 void OnEnable()
122 {
123 // must be installed on the main thread to get the right thread id.
124 UnityDragAndDropHook.InstallHook();
125 UnityDragAndDropHook.OnDroppedFiles += OnFiles;
126 }
127
128 void OnDestroy()
129 {
130 WebGLFileUploadManager.onFileUploaded -= OnFileUploaded;
131 WebGLFileUploadManager.Dispose();
132 }
133
134 void OnDisable()
135 {
136 UnityDragAndDropHook.UninstallHook();
137 }
138
139 public IEnumerator ThreadedLoad(List<string> aFiles, bool recursive = false)
140 {
141 isLoading = true;
142 LoadingManager.instance.SetLoading();
143 LoadingManager.instance.ShowWindow();
144 LoadingManager.instance.timeout = 90f;
145#if UNITY_EDITOR
146 if (EditorFastLoad/* || SavedUser.instance.isTutorial*/)
147 {
148 yield return null;
149 isLoading = false;
150 lateRebuild = StartCoroutine(LateRebuild());
151 LoadingManager.instance.HideWindow();
152 yield break;
153 }
154#endif
155 byte loadbalance = 0;
156 foreach (var aFile in aFiles)
157 {
158#if !DANA
159 loadbalance++;
160 if (loadbalance % 2 == 0)
161 yield return null;
162#else
163 yield return null;
164#endif
165
166 if (alreadyLoaded(aFile))
167 {
168 continue;
169 }
170
171 if (Directory.Exists(aFile))
172 {
173 var files = Directory.GetFiles(aFile);
174 yield return ThreadedLoad(files.ToList(), true);
175 }
176 else
177 {
178 OnFiles(new List<string> { aFile }, new POINT(-1, -1));
179 }
180 }
181
182 if (recursive)
183 {
184 LoadingManager.instance.HideWindow();
185 yield break;
186 }
187 yield return null;
188 isLoading = false;
189 lateRebuild = StartCoroutine(LateRebuild());
190 LoadingManager.instance.HideWindow();
191 LoadingManager.instance.FilesLoaded = true;
192 stopwatch.Stop();
193 Debug.Log($"All files loaded in: {stopwatch.ElapsedMilliseconds}ms");
194 }
195
196 public bool alreadyLoaded(string aFile)
197 {
198 foreach (var keys in pb_PrefabBrowser.instance.prefabs.Keys)
199 {
200 if (keys.name == Path.GetFileName(aFile))
201 {
202 return true;
203 }
204 }
205 return false;
206 }
207 private void OnFileUploaded(UploadedFileInfoV2[] result)
208 {
209 if (result.Length == 0)
210 {
211 Debug.Log("File upload Error!");
212 PopupManager.instance.ShowPopup("UPLOAD_ERROR", "UPLOAD_ERROR_TEXT");
213 LoadingManager.instance.HideWindow();
214 return;
215 }
216 else
217 {
218 Debug.Log("File upload success! (result.Length: " + result.Length + ")");
219 }
220
221 foreach (var file in result)
222 {
223 Debug.Log($"{file.name}|{file.isSuccess}");
224 if (file.isSuccess)
225 {
226 OnFiles(new List<string> { file.filePath.Replace('/', '\\') }, new POINT(1, 1));
227 }
228 }
229 }
230
231 public void OnFiles(List<string> aFiles, POINT aPos)
232 {
233 if (!stopwatch.IsRunning)
234 {
235 stopwatch.Start();
236 Debug.Log("File loading started!");
237 }
238 //Debug.Log($"OnFiles");
239 LoadingManager.instance.SetLoading();
240 LoadingManager.instance.ShowWindow();
241 LoadingManager.instance.timeout += 5f;
242 for (int i = 0; i < aFiles.Count; i++)
243 {
244 aFiles[i] = aFiles[i].Replace('/', '\\');
245 }
246 foreach (var file in aFiles)
247 {
248 var current = stopwatch.ElapsedMilliseconds;
249 //Debug.Log($"OnFiles in loop: {file} with ext: {file.Substring(file.LastIndexOf('.') + 1).ToLower()}");
250 TagCloud tc;
251 var log = true;
252 var filetype = file.Substring(file.LastIndexOf('.') + 1).ToLower();
253 switch (filetype)
254 {
255 case "assetbundle":
256 var ab = AssetBundle.LoadFromMemory(File.ReadAllBytes(file));
257 //Debug.Log("AssetBundle.LoadFromMemory DONE!");
259 break;
260 case "png":
261 case "jpg":
262 case "jpeg":
263 case "bmp":
264#if !UNITY_WEBGL
265 if (!File.Exists(Path.Combine(Application.streamingAssetsPath, "pictures", file.Substring(file.LastIndexOf('\\') + 1))))
266 File.Copy(file, Path.Combine(Application.streamingAssetsPath, "pictures", file.Substring(file.LastIndexOf('\\') + 1)));
267#endif
268 var go = new GameObject(file.Substring(file.LastIndexOf('\\') + 1));
269 var ri = go.AddComponent<RawImage>();
270 var canvas = go.AddComponent<Canvas>();
271 go.GetComponent<RectTransform>().sizeDelta = Vector2.one;
272
273#if !UNITY_WEBGL
274 var fileData = File.ReadAllBytes(Path.Combine(Application.streamingAssetsPath, "pictures",
275 file.Substring(file.LastIndexOf('\\') + 1)));
276#else
277 var fileData = File.ReadAllBytes(file.Replace('\\', '/'));
278#endif
279
280#if DANA
281 if (currentPreloader && currentPreloader.HasFileLoaded(go.name, out var picgo))
282 {
283 ri.texture = picgo.GetComponent<RawImage>().texture;
284 }
285 else
286#endif
287 {
289 {
290 var tex = new Texture2D(1, 1);
291 var time = stopwatch.ElapsedMilliseconds;
292 //if (File.Exists(Path.Combine(Application.streamingAssetsPath, "pictures", go.name + ".picdata")))
293 //{
294 // var picdata = File.ReadAllBytes(Path.Combine(Application.streamingAssetsPath, "pictures", go.name + ".picdata"));
295 // var width = BitConverter.ToInt32(picdata, 0);
296 // var height = BitConverter.ToInt32(picdata, 4);
297 // tex.LoadRawTextureData(Macro.Decompress(picdata.Skip(8).ToArray()));
298 //}
299 //else
300 //{
301 tex.LoadImage(fileData);
302 // File.WriteAllBytes(Path.Combine(Application.streamingAssetsPath, "pictures", go.name + ".picdata"), BitConverter.GetBytes(tex.width).Concat(BitConverter.GetBytes(tex.height)).Concat(Macro.Compress(tex.GetRawTextureData())).ToArray());
303 //}
304 Debug.Log($"image load time: {stopwatch.ElapsedMilliseconds - time}ms");
306 ri.texture = GlobalTextureHolder.instance.GetLowRes(go.name);
307 }
308 else
309 {
310 ri.texture = GlobalTextureHolder.instance.GetLowRes(go.name);
311 }
312
313 }
314 GC.Collect();
315 tc = go.AddComponent<TagCloud>();
316 tc.filePath = file;
317 tc.TryLoad();
318
319
320 var uf = go.AddComponent<UploadedFile>();
321 uf.modelData = fileData;
322 uf.fileName = file.Substring(file.LastIndexOf('\\') + 1);
323#if UNITY_WEBGL
324 if (aPos.x != -1)
325 {
326 YesNoPopupManager.instance.ShowPopup("GLOBAL_UPLOAD", "GLOBAL_UPLOAD_TEXT", "GLOBAL", "LOCAL");
327 YesNoPopupManager.instance.InvokeOnNo(() => { uf.global = false; });
328 YesNoPopupManager.instance.InvokeOnYes(() => { uf.global = true; });
329 }
330#endif
331
332 go.AddComponent<RenameObject>();
333
334 prefabBrowser.AddGameObject(go, pb_PrefabBrowser.LoadPanel.Pictures, Path.Combine(Application.streamingAssetsPath, "pictures", file.Substring(file.LastIndexOf('\\') + 1)));
335 go.transform.SetParent(paretnObject.transform, true);
336 break;
337 case "mp4":
338 case "webm":
339#if !UNITY_WEBGL
340 if (!File.Exists(Path.Combine(Application.streamingAssetsPath, "videos", file.Substring(file.LastIndexOf('\\') + 1))))
341 File.Copy(file, Path.Combine(Application.streamingAssetsPath, "videos", file.Substring(file.LastIndexOf('\\') + 1)));
342#endif
343 var vidgo = new GameObject(file.Substring(file.LastIndexOf('\\') + 1));
344 var vp = vidgo.AddComponent<VideoPlayer>();
345#if UNITY_WEBGL
346 vp.url = file.Replace('\\', '/');
347#else
348
349 vp.url = Path.Combine(Application.streamingAssetsPath, "videos", file.Substring(file.LastIndexOf('\\') + 1));
350#endif
351 // "http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4";
352 vp.isLooping = true;
353 vp.playOnAwake = true;
354 var rt = new RenderTexture(512, 512, 0);
355 vidgo.AddComponent<Canvas>();
356 var riv = vidgo.AddComponent<RawImage>();
357 riv.texture = rt;
358 vp.renderMode = VideoRenderMode.RenderTexture;
359 vp.targetTexture = rt;
360
361 tc = vidgo.AddComponent<TagCloud>();
362 tc.filePath = file;
363 tc.TryLoad();
364
365
366 var ufv = vidgo.AddComponent<UploadedFile>();
367 ufv.modelData = File.ReadAllBytes(file.Replace('\\', '/'));
368 ufv.fileName = file.Substring(file.LastIndexOf('\\') + 1);
369#if UNITY_WEBGL
370 if (aPos.x != -1)
371 {
372 YesNoPopupManager.instance.ShowPopup("GLOBAL_UPLOAD", "GLOBAL_UPLOAD_TEXT", "GLOBAL", "LOCAL");
373 YesNoPopupManager.instance.InvokeOnNo(() => { ufv.global = false; });
374 YesNoPopupManager.instance.InvokeOnYes(() => { ufv.global = true; });
375 }
376#endif
377
378 vidgo.AddComponent<RenameObject>();
379
380 vidgo.GetComponent<RectTransform>().sizeDelta = Vector2.one;
382 vidgo.transform.SetParent(paretnObject.transform, true);
383 break;
384
385 //case "gltf":
386 //case "glb":
387 // gltf.LoadUploadedModel(byteArray);
388 // break;
389 //case "stl":
390 //case "3dxml":
391 // stl.LoadUploadedModel(byteArray, file.name);
392 // break;
393 //case "obj":
394 // obj.LoadUploadedModel(byteArray);
395 // break;
396
397 case "mp3":
398 case "wav":
399
400#if !UNITY_WEBGL
401 if (!File.Exists(Path.Combine(Application.streamingAssetsPath, "sounds", file.Substring(file.LastIndexOf('\\') + 1))))
402 File.Copy(file, Path.Combine(Application.streamingAssetsPath, "sounds", file.Substring(file.LastIndexOf('\\') + 1)));
403 var newPath = Path.Combine(Application.streamingAssetsPath, "sounds", file.Substring(file.LastIndexOf('\\') + 1));
404 var so = new GameObject(newPath.Substring(file.LastIndexOf('\\') + 1)); // Instantiate(GameObject.Find("ReferenceHelpUI").GetComponent<ReferenceSaver>().Reference);
405 so.layer = 9;
406 so.AddComponent<NAudioPlayer>().SetFilePath(newPath);
407
408 tc = so.AddComponent<TagCloud>();
409 tc.filePath = file;
410 tc.TryLoad();
411
412 so.AddComponent<RenameObject>();
413
415
416#else
417
418 var so = new GameObject(file.Substring(file.LastIndexOf('\\') + 1)); // Instantiate(GameObject.Find("ReferenceHelpUI").GetComponent<ReferenceSaver>().Reference);
419 so.layer = 9;
420 var naudio = so.AddComponent<NAudioPlayer>();
421 naudio.SetFilePath(file.Replace('\\', '/'));
422
423 tc = so.AddComponent<TagCloud>();
424 tc.filePath = file;
425 tc.TryLoad();
426
427 var ufs = so.AddComponent<UploadedFile>();
428 ufs.modelData = File.ReadAllBytes(file.Replace('\\', '/'));
429 ufs.fileName = file.Substring(file.LastIndexOf('\\') + 1);
430#if UNITY_WEBGL
431 if (aPos.x != -1)
432 {
433 YesNoPopupManager.instance.ShowPopup("GLOBAL_UPLOAD", "GLOBAL_UPLOAD_TEXT", "GLOBAL", "LOCAL");
434 YesNoPopupManager.instance.InvokeOnNo(() =>
435 {
436 ufs.global = false;
437
438 StartCoroutine(NetworkManager.instance.UploadFileToCurrent(ufs.modelData, ufs.fileName, false, (ws) =>
439 {
440 Debug.Log("sound uploaded:" + ws.ToString());
441 naudio.SetFilePath(UrlCombine.Combine(NetworkManager.instance.url, ws.fileSavedURL));
442 pb_PrefabBrowser.instance?.ReloadAll();
443 }, null));
444 });
445 YesNoPopupManager.instance.InvokeOnYes(() =>
446 {
447 ufs.global = true;
448
449 StartCoroutine(NetworkManager.instance.UploadFileToCurrent(ufs.modelData, ufs.fileName, true, (ws) =>
450 {
451 Debug.Log("sound uploaded:" + ws.ToString());
452 naudio.SetFilePath(UrlCombine.Combine(NetworkManager.instance.url, ws.fileSavedURL));
453 pb_PrefabBrowser.instance?.ReloadAll();
454 }, null));
455 });
456
457 }
458#endif
459 so.AddComponent<RenameObject>();
460
462#endif
463 so.transform.SetParent(paretnObject.transform, true);
464
465 break;
466
467 case "3d":
468 case "3ds":
469 case "3mf":
470 case "ac":
471 case "ac3d":
472 case "acc":
473 case "amf":
474 case "amj":
475 case "ase":
476 case "ask":
477 case "b3d":
478 case "blend":
479 case "bvh":
480 case "cob":
481 case "dae":
482 case "dxf":
483 case "enff":
484 case "fbx":
485 case "gltf":
486 case "glb":
487 case "ifc":
488 case "irr":
489 case "irrmesh":
490 case "lwo":
491 case "lws":
492 case "lxo":
493 case "md2":
494 case "md3":
495 case "md5":
496 case "mdc":
497 case "mdl":
498 case "mesh":
499 case "xml":
500 case "mot":
501 case "ms3d":
502 case "ndo":
503 case "nff":
504 case "obj":
505 case "off":
506 case "ogex":
507 case "ply":
508 case "pmx":
509 case "prj":
510 case "q3o":
511 case "q3s":
512 case "raw":
513 case "scn":
514 case "sib":
515 case "smd":
516 case "stl":
517 case "ter":
518 case "uc":
519 case "vta":
520 case "x":
521 case "x3d":
522 case "xgl":
523 case "zgl":
524#if TRILIB_2
525 case "zip":
526#endif
527 //Debug.Log($"in trilib case, has trilib: {trlib != null}");
528 var newPathModel = file;
529 var filename = file.Substring(file.LastIndexOf('\\') + 1);
530#if !UNITY_WEBGL
531 var files = new DirectoryInfo(Application.streamingAssetsPath)
532 .EnumerateFiles(filename, SearchOption.AllDirectories)
533 /*.Select(d => d.FullName)*/.ToList();
534 var samefile = false;
535 foreach (var file1 in files)
536 {
537 if (file1.Length == new DirectoryInfo(Path.GetDirectoryName(file)).EnumerateFiles(Path.GetFileName(file)).First().Length)
538 {
539 samefile = true;
540 break;
541 }
542 }
543
544
545 if (!samefile || !new DirectoryInfo(Application.streamingAssetsPath)
546 .EnumerateFiles(file.Substring(file.LastIndexOf('\\') + 1), SearchOption.AllDirectories)
547 .Select(d => d.FullName).Any())
548 {
549 if (!Directory.Exists(Path.Combine(Application.streamingAssetsPath, "models")))
550 {
551 Directory.CreateDirectory(Path.Combine(Application.streamingAssetsPath, "models"));
552 }
553 if (!File.Exists(Path.Combine(Application.streamingAssetsPath, "models", file.Substring(file.LastIndexOf('\\') + 1))))
554 File.Copy(file, Path.Combine(Application.streamingAssetsPath, "models", file.Substring(file.LastIndexOf('\\') + 1)));
555 newPathModel = Path.Combine(Application.streamingAssetsPath, "models", file.Substring(file.LastIndexOf('\\') + 1));
556 }
557#else
558 newPathModel = newPathModel.Replace('\\', '/');
559#endif
560 //Debug.Log("LoadFromMemory now!");
561#if DANA
562 var modelname = "";
563 try
564 {
565 modelname = newPathModel.Remove(0, newPathModel.LastIndexOf("\\") + 1);
566 }
567 catch (Exception)
568 {
569 modelname = newPathModel;
570 }
571 if (currentPreloader && currentPreloader.HasFileLoaded(modelname, out go))
572 {
573 var newSpawn = Instantiate(go, paretnObject.transform);
574 newSpawn.name = newSpawn.name.Replace("(Clone)", "");
575 var tc3 = newSpawn.AddComponent<TagCloud>();
576 tc3.filePath = newPathModel;
577 tc3.TryLoad();
578
579 ComponentAdder(newSpawn);
580
581 newSpawn.AddComponent<RenameObject>();
582
583 prefabBrowser?.AddGameObject(newSpawn, pb_PrefabBrowser.LoadPanel.Models, newPathModel);
584 }
585 else
586#endif
587 {
588#if DANA
589 if (filetype == "glb" || filetype == "gltf")
590 {
591 GLTFastLoader.instance.Load(File.ReadAllBytes(newPathModel), newPathModel, paretnObject, aPos.x != -1);
592 break;
593 }
594 else
595#endif
596 if (trlib)
597#if UNITY_WEBGL
598 trlib.LoadFromMemory(File.ReadAllBytes(newPathModel), newPathModel, paretnObject, aPos.x != -1);
599#else
600 trlib.LoadFromMemory(File.ReadAllBytes(newPathModel), newPathModel, paretnObject,
601 aPos.x != -1);
602#endif
603 }
604 break;
605 case "mod":
606#if UNITY_WEBGL
607 ModLoader(file.Substring(file.LastIndexOf('\\') + 1), File.ReadAllText(file.Replace('\\', '/')));
608#else
609 ModLoader(file.Substring(file.LastIndexOf('\\') + 1), File.ReadAllText(file));
610#endif
611 log = false;
612 break;
613 case "hlp":
614 log = false;
615 var load = new GameObject(file.Substring(file.LastIndexOf('\\') + 1));
616 var tmp = load.AddComponent<TextMeshPro>();
617#if UNITY_WEBGL
618 var txt = File.ReadAllText(file.Replace('\\', '/'));
619#else
620 var txt = File.ReadAllText(file);
621#endif
622 var color = new Color(Macro.StoF(txt.Split(':')[0]), Macro.StoF(txt.Split(':')[1]), Macro.StoF(txt.Split(':')[2]), Macro.StoF(txt.Split(':')[3]));
623 var bgcolor = new Color(Macro.StoF(txt.Split(':')[4]), Macro.StoF(txt.Split(':')[5]), Macro.StoF(txt.Split(':')[6]), Macro.StoF(txt.Split(':')[7]));
624 tmp.color = color;
625 tmp.text = txt.Remove(0, txt.IndexOf("\n") + 1);
626 tmp.autoSizeTextContainer = true;
627 tmp.extraPadding = true;
628 var c = load.AddComponent<Canvas>();
629 c.renderMode = RenderMode.WorldSpace;
630 //var size = load.GetComponent<MeshRenderer>().bounds; //need to wait 1 frame
631 var mr = load.GetComponent<MeshRenderer>();
632 var bgGo = new GameObject("BG");
633 bgGo.transform.SetParent(load.transform);
634 StartCoroutine(ResizeHelpBG(mr, bgGo, file));
635 var bg = bgGo.AddComponent<Image>();
636 bg.material = GameObject.Find("ReferenceHelpUI").GetComponent<ReferenceSaver>().ReferenceV2 as Material;
637 bg.color = bgcolor;
638
639 tc = load.AddComponent<TagCloud>();
640 tc.filePath = file;
641 tc.TryLoad();
642
643 var uft = load.AddComponent<UploadedFile>();
644 uft.modelData = Encoding.UTF8.GetBytes(txt);
645 uft.fileName = file;
646
647 load.AddComponent<RenameObject>();
648
649 load.transform.localScale = Vector3.one * 0.02f;
650 break;
651 //case "stp":
652 // if (cadLoader)
653 // {
654 // cadLoader.LoadUploadedModel(File.ReadAllBytes(file), file);
655 // }
656 // break;
657 case "tag":
658 case "json":
659 case "env":
660 case "picdata":
661 //just ignore it™
662 log = false;
663 break;
664
665 case "lua":
666 log = false;
667 if (file.Contains("startup.lua"))
668 break;
669 var lua = new GameObject(file.Substring(file.LastIndexOf('\\') + 1));
670 lua.transform.SetParent(paretnObject.transform);
671#if UNITY_WEBGL
672 var txtl = File.ReadAllText(file.Replace('\\', '/'));
673#else
674 var txtl = File.ReadAllText(file);
675#endif
676 var ufl = lua.AddComponent<UploadedFile>();
677 ufl.modelData = Encoding.UTF8.GetBytes(txtl);
678 ufl.fileName = file.Substring(file.LastIndexOf('\\') + 1);
679
681 break;
682
683 case "gtag":
684 GlobalTagManager.instance.LoadData(File.ReadAllBytes(file));
685 break;
686
687 case "qiz":
688 var qiz = new GameObject(file.Substring(file.LastIndexOf('\\') + 1));
689#if UNITY_WEBGL
690 var txtq = File.ReadAllText(file.Replace('\\', '/'));
691#else
692 var txtq = File.ReadAllText(file);
693#endif
694 qiz.transform.SetParent(paretnObject.transform);
695 var ufq = qiz.AddComponent<UploadedFile>();
696 ufq.modelData = Encoding.UTF8.GetBytes(txtq);
697 ufq.fileName = file.Substring(file.LastIndexOf('\\') + 1);
698 break;
699
700 default:
701 log = false;
702 if (file.ToLower() == file.Substring(file.LastIndexOf('.') + 1).ToLower()) //no extension
703 {
704
705#if UNITY_WEBGL
706 var ab2 = AssetBundle.LoadFromMemory(File.ReadAllBytes(file.Replace('\\', '/')));
707#else
708 var ab2 = AssetBundle.LoadFromMemory(File.ReadAllBytes(file));
709#endif
711 break;
712 }
713
714 if (file.EndsWith(".meta"))
715 {
716 break;
717 }
718 Debug.Log(file.Substring(file.LastIndexOf('.') + 1).ToLower() + " no cases to this file");
719 if (aPos.x == -1)
720 return;
721 PopupManager.instance.ShowPopup(Macro.T("UNSUPPORTED_FILE"),
722 Macro.T("UNSUPPORTED_FILE_TEXT"));
723 break;
724 }
725 if (log)
726 Debug.Log($"'{file.Remove(0, file.LastIndexOf("\\") + 1)}' loaded in {stopwatch.ElapsedMilliseconds - current}ms");
727 }
728
729 LoadingManager.instance.HideWindow();
730 if (aPos.x == -1)
731 return;
732 StartLateRebuild(aPos.y > 0);
733 }
734
735 void ComponentAdder(GameObject go)
736 {
737 if (go.GetComponent<MeshFilter>() && !go.GetComponent<Collider>())
738 {
739 var coll = go.AddComponent<MeshCollider>();
740 coll.convex = true;
741 }
742
743 if (go.GetComponent<MeshRenderer>())
744 {
745 var mr = go.GetComponent<MeshRenderer>();
746 foreach (var material in mr.materials)
747 {
748 if (material.mainTexture == null)
749 {
750 material.mainTexture = Resources.Load<Texture>("2k_white");
751 }
752 if (material.HasProperty("_Glossiness"))
753 {
754 var smoothness = material.GetFloat("_Glossiness");
755 material.SetFloat("_Glossiness", Macro.MinMaxClamp(smoothness, 0f, 1f));
756 }
757 if (material.HasProperty("_Metallic"))
758 {
759 var smoothness = material.GetFloat("_Metallic");
760 material.SetFloat("_Metallic", Macro.MinMaxClamp(smoothness, 0f, 1f));
761 }
762 }
763 }
764
765 for (int i = 0; i < go.transform.childCount; i++)
766 {
767 ComponentAdder(go.transform.GetChild(i).gameObject);
768 }
769 }
770
771 [Button]
773 {
774#if TRILIB_2
775 StandaloneFileBrowser.OpenFilePanelAsync("Select a file to upload", null, GetExtensions(), true, (itemList) =>
776 {
777 foreach (var itemWithStream in itemList)
778 {
779 OnFileData(ReadFully(itemWithStream.OpenStream()), itemWithStream.Name, TimeStamp(), newUpload: true);
780 }
781 });
782#endif
783 }
784
785#if TRILIB_2
786
787 private static ExtensionFilter[] GetExtensions()
788 {
789 var extensions = Readers.Extensions;
790 var extensionFilters = new List<ExtensionFilter>();
791 var subExtensions = new List<string>();
792 foreach (var extension in extensions)
793 {
794 extensionFilters.Add(new ExtensionFilter(null, extension));
795 subExtensions.Add(extension);
796 }
797 subExtensions.Add("zip");
798 subExtensions.Add("bmp");
799 subExtensions.Add("jpg");
800 subExtensions.Add("jpeg");
801 subExtensions.Add("png");
802 subExtensions.Add("mp4");
803 subExtensions.Add("mp3");
804 subExtensions.Add("wav");
805 extensionFilters.Add(new ExtensionFilter(null, new[] { "zip" }));
806 extensionFilters.Add(new ExtensionFilter("All Files", new[] { "*" }));
807 extensionFilters.Insert(0, new ExtensionFilter("Accepted Files", subExtensions.ToArray()));
808 return extensionFilters.ToArray();
809 }
810
811 public static byte[] ReadFully(Stream input)
812 {
813 byte[] buffer = new byte[16 * 1024];
814 using (MemoryStream ms = new MemoryStream())
815 {
816 int read;
817 while ((read = input.Read(buffer, 0, buffer.Length)) > 0)
818 {
819 ms.Write(buffer, 0, read);
820 }
821 return ms.ToArray();
822 }
823 }
824
825 private string TimeStamp()
826 {
827 var now = DateTime.Now;
828 //2020-12-07T09:32:13.398Z
829 return $"{now.Year}-{now.Month:D2}-{now.Day:D2}T{now.Hour:D2}:{now.Minute:D2}:{now.Second:D2}.{now.Millisecond:D3}Z";
830 }
831#endif
832
833 public void OnFileData(byte[] fileData, string fileName, string modified, NetworkManager.WSFile wsFile = default, bool global = false, bool newUpload = false)
834 {
835 LoadingManager.instance.SetLoading();
836 LoadingManager.instance.ShowWindow();
837 LoadingManager.instance.timeout += 5f;
838
839 TagCloud tc;
840 switch (fileName.Substring(fileName.LastIndexOf('.') + 1).ToLower())
841 {
842 case "assetbundle":
843 var ab = AssetBundle.LoadFromMemory(fileData);
844 //Debug.Log("AssetBundle.LoadFromMemory DONE!");
846 break;
847 case "png":
848 case "jpg":
849 case "jpeg":
850 case "bmp":
851
852#if !UNITY_WEBGL
853 if (!File.Exists(Path.Combine(Application.streamingAssetsPath, "pictures", fileName)))
854 File.WriteAllBytes(Path.Combine(Application.streamingAssetsPath, "pictures", fileName), fileData);
855#endif
856
857 var go = new GameObject(fileName);
858 var ri = go.AddComponent<RawImage>();
859 var canvas = go.AddComponent<Canvas>();
860 go.GetComponent<RectTransform>().sizeDelta = Vector2.one;
861
863 {
864 var tex = new Texture2D(1, 1);
865 tex.LoadImage(fileData);
867 ri.texture = GlobalTextureHolder.instance.GetLowRes(go.name);
868 }
869 else
870 {
871 ri.texture = GlobalTextureHolder.instance.GetLowRes(go.name);
872 }
873 //var tex = new Texture2D(1, 1);
874 //tex.LoadImage(fileData);
875 //Macro.Resize(tex, 200, 200);
876 //ri.texture = tex;
877 //
878 tc = go.AddComponent<TagCloud>();
879 tc.filePath = fileName;
880 tc.TryLoad();
881
882
883 var uf = go.AddComponent<UploadedFile>();
884 uf.modelData = fileData;
885 uf.fileName = fileName;
886 uf.global = global;
887
888
889 go.AddComponent<RenameObject>();
890
891 if (newUpload)
892 {
893 YesNoPopupManager.instance.ShowPopup("GLOBAL_UPLOAD", "GLOBAL_UPLOAD_TEXT", "GLOBAL", "LOCAL");
894 YesNoPopupManager.instance.InvokeOnNo(() =>
895 {
896 uf.global = false;
898 });
899 YesNoPopupManager.instance.InvokeOnYes(() =>
900 {
901 uf.global = true;
903 });
904 }
905
907 /*Path.Combine(Application.streamingAssetsPath, "pictures", */fileName/*)*/, global);
908 go.transform.SetParent(paretnObject.transform, true);
909 break;
910 case "mp4":
911 case "webm":
912#if !UNITY_WEBGL
913 if (!File.Exists(Path.Combine(Application.streamingAssetsPath, "videos", fileName)))
914 File.WriteAllBytes(Path.Combine(Application.streamingAssetsPath, "videos", fileName), fileData);
915#endif
916 var vidgo = new GameObject(fileName);
917 var vp = vidgo.AddComponent<VideoPlayer>();
918 vp.url = NetworkManager.instance.WSFileToUrl(wsFile);
919 // "http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4";
920 vp.isLooping = true;
921 vp.playOnAwake = true;
922 var rt = new RenderTexture(512, 512, 0);
923 vidgo.AddComponent<Canvas>();
924 var riv = vidgo.AddComponent<RawImage>();
925 riv.texture = rt;
926 vp.renderMode = VideoRenderMode.RenderTexture;
927 vp.targetTexture = rt;
928
929 tc = vidgo.AddComponent<TagCloud>();
930 tc.filePath = fileName;
931 tc.TryLoad();
932
933
934 var ufv = vidgo.AddComponent<UploadedFile>();
935 ufv.modelData = fileData; //TODO
936 ufv.fileName = fileName;
937 ufv.global = global;
938
939 vidgo.AddComponent<RenameObject>();
940
941 if (newUpload)
942 {
943 YesNoPopupManager.instance.ShowPopup("GLOBAL_UPLOAD", "GLOBAL_UPLOAD_TEXT", "GLOBAL", "LOCAL");
944 YesNoPopupManager.instance.InvokeOnNo(() =>
945 {
946 ufv.global = false;
948 });
949 YesNoPopupManager.instance.InvokeOnYes(() =>
950 {
951 ufv.global = true;
953 });
954 }
955
956 vidgo.GetComponent<RectTransform>().sizeDelta = Vector2.one;
957 prefabBrowser.AddGameObject(vidgo, pb_PrefabBrowser.LoadPanel.Videos, global: global, filePath: fileName);
958 vidgo.transform.SetParent(paretnObject.transform, true);
959 break;
960
961 //case "gltf":
962 //case "glb":
963 // gltf.LoadUploadedModel(byteArray);
964 // break;
965 //case "stl":
966 //case "3dxml":
967 // stl.LoadUploadedModel(byteArray, file.name);
968 // break;
969 //case "obj":
970 // obj.LoadUploadedModel(byteArray);
971 // break;
972
973 case "mp3":
974 case "wav":
975#if !UNITY_WEBGL
976 if (!File.Exists(Path.Combine(Application.streamingAssetsPath, "sounds", fileName)))
977 File.WriteAllBytes(Path.Combine(Application.streamingAssetsPath, "sounds", fileName), fileData);
978#endif
979 fileName = Path.GetFileName(fileName);
980 var so = new GameObject(fileName); // Instantiate(GameObject.Find("ReferenceHelpUI").GetComponent<ReferenceSaver>().Reference);
981 so.layer = 9;
982 var naudio = so.AddComponent<NAudioPlayer>();
983 naudio.SetFilePath(NetworkManager.instance.WSFileToUrl(wsFile));
984
985 tc = so.AddComponent<TagCloud>();
986 tc.filePath = fileName;
987 tc.TryLoad();
988
989
990 var ufs = so.AddComponent<UploadedFile>();
991 ufs.modelData = fileData;
992 ufs.fileName = fileName;
993 ufs.global = global;
994
995
996 so.AddComponent<RenameObject>();
997#if UNITY_WEBGL
998 if (newUpload)
999 {
1000 YesNoPopupManager.instance.ShowPopup("GLOBAL_UPLOAD", "GLOBAL_UPLOAD_TEXT", "GLOBAL", "LOCAL");
1001 YesNoPopupManager.instance.InvokeOnNo(() =>
1002 {
1003 ufs.global = false;
1004
1005 StartCoroutine(NetworkManager.instance.UploadFileToCurrent(fileData, fileName, false, (ws) =>
1006 {
1007 Debug.Log("sound uploaded to:" + ws.ToString());
1008 naudio.SetFilePath(UrlCombine.Combine(NetworkManager.instance.url, ws.fileSavedURL));
1009 pb_PrefabBrowser.instance?.ReloadAll();
1010 }, null));
1011 });
1012 YesNoPopupManager.instance.InvokeOnYes(() =>
1013 {
1014 ufs.global = true;
1015 StartCoroutine(NetworkManager.instance.UploadFileToCurrent(fileData, fileName, true, (ws) =>
1016 {
1017 Debug.Log("sound uploaded to:" + ws.ToString());
1018 naudio.SetFilePath(UrlCombine.Combine(NetworkManager.instance.url, ws.fileSavedURL));
1019 pb_PrefabBrowser.instance?.ReloadAll();
1020 }, null));
1021 });
1022 }
1023#endif
1024
1025 prefabBrowser.AddGameObject(so, pb_PrefabBrowser.LoadPanel.Sounds, global: global, filePath: fileName);
1026 so.transform.SetParent(paretnObject.transform, true);
1027
1028 break;
1029
1030 case "3d":
1031 case "3ds":
1032 case "3mf":
1033 case "ac":
1034 case "ac3d":
1035 case "acc":
1036 case "amf":
1037 case "amj":
1038 case "ase":
1039 case "ask":
1040 case "b3d":
1041 case "blend":
1042 case "bvh":
1043 case "cob":
1044 case "dae":
1045 case "dxf":
1046 case "enff":
1047 case "fbx":
1048 case "gltf":
1049 case "glb":
1050 case "ifc":
1051 case "irr":
1052 case "irrmesh":
1053 case "lwo":
1054 case "lws":
1055 case "lxo":
1056 case "md2":
1057 case "md3":
1058 case "md5":
1059 case "mdc":
1060 case "mdl":
1061 case "mesh":
1062 case "xml":
1063 case "mot":
1064 case "ms3d":
1065 case "ndo":
1066 case "nff":
1067 case "obj":
1068 case "off":
1069 case "ogex":
1070 case "ply":
1071 case "pmx":
1072 case "prj":
1073 case "q3o":
1074 case "q3s":
1075 case "raw":
1076 case "scn":
1077 case "sib":
1078 case "smd":
1079 case "stl":
1080 case "ter":
1081 case "uc":
1082 case "vta":
1083 case "x":
1084 case "x3d":
1085 case "xgl":
1086 case "zgl":
1087#if TRILIB_2
1088 case "zip":
1089#endif
1090#if !UNITY_WEBGL
1091 if (!File.Exists(Path.Combine(Application.streamingAssetsPath, "models", fileName)))
1092 File.WriteAllBytes(Path.Combine(Application.streamingAssetsPath, "models", fileName), fileData);
1093#endif
1094 if (trlib)
1095 trlib.LoadFromMemory(fileData, fileName, paretnObject, global: global, singleModel: newUpload);
1096 break;
1097 case "mod":
1098 ModLoader(fileName, Encoding.UTF8.GetString(fileData), global, newUpload);
1099 break;
1100 case "hlp":
1101#if !UNITY_WEBGL
1102 if (!File.Exists(Path.Combine(Application.streamingAssetsPath, "helps", fileName)))
1103 File.WriteAllBytes(Path.Combine(Application.streamingAssetsPath, "helps", fileName), fileData);
1104
1105 Debug.Log($"hlp saver if failed: {File.Exists(Path.Combine(Application.streamingAssetsPath, "helps", fileName))}");
1106#endif
1107 Debug.Log("loading HLP file!");
1108 var load = new GameObject(fileName);
1109 var tmp = load.AddComponent<TextMeshPro>();
1110 var txt = Encoding.UTF8.GetString(fileData);
1111 var color = new Color(Macro.StoF(txt.Split(':')[0]), Macro.StoF(txt.Split(':')[1]),
1112 Macro.StoF(txt.Split(':')[2]), Macro.StoF(txt.Split(':')[3]));
1113 var bgcolor = new Color(Macro.StoF(txt.Split(':')[4]), Macro.StoF(txt.Split(':')[5]),
1114 Macro.StoF(txt.Split(':')[6]), Macro.StoF(txt.Split(':')[7]));
1115 tmp.color = color;
1116 tmp.text = txt.Remove(0, txt.IndexOf("\n") + 1);
1117 tmp.autoSizeTextContainer = true;
1118 tmp.extraPadding = true;
1119 var c = load.AddComponent<Canvas>();
1120 c.renderMode = RenderMode.WorldSpace;
1121 //var size = load.GetComponent<MeshRenderer>().bounds; //need to wait 1 frame
1122 var mr = load.GetComponent<MeshRenderer>();
1123 var bgGo = new GameObject("BG");
1124 bgGo.transform.SetParent(load.transform);
1125 StartCoroutine(ResizeHelpBG(mr, bgGo, "", global));
1126 var bg = bgGo.AddComponent<Image>();
1127 bg.material = GameObject.Find("ReferenceHelpUI").GetComponent<ReferenceSaver>().ReferenceV2 as Material;
1128 bg.color = bgcolor;
1129
1130
1131 var uft = load.AddComponent<UploadedFile>();
1132 uft.modelData = fileData;
1133 uft.fileName = fileName;
1134 uft.global = global;
1135
1136 tc = load.AddComponent<TagCloud>();
1137 tc.filePath = fileName;
1138 tc.TryLoad();
1139
1140 load.transform.localScale = Vector3.one * 0.02f;
1141 Debug.Log($"HLP {fileName} loaded!");
1142 break;
1143 //case "stp":
1144 // if (cadLoader)
1145 // {
1146 // cadLoader.LoadUploadedModel(fileData, fileName);
1147 // }
1148 // break;
1149 case "tag":
1150 case "json":
1151 case "env":
1152 //just ignore it™
1153 break;
1154
1155 case "lua":
1156 if (fileName.Contains("startup.lua"))
1157 break;
1158#if !UNITY_WEBGL
1159 if (!File.Exists(Path.Combine(Application.streamingAssetsPath, "scripts", fileName)))
1160 File.WriteAllBytes(Path.Combine(Application.streamingAssetsPath, "scripts", fileName), fileData);
1161#endif
1162 var lua = new GameObject(fileName);
1163 lua.transform.SetParent(paretnObject.transform);
1164 var ufl = lua.AddComponent<UploadedFile>();
1165 ufl.modelData = fileData;
1166 ufl.fileName = fileName;
1167 ufl.global = global;
1168
1169 prefabBrowser.AddGameObject(lua, pb_PrefabBrowser.LoadPanel.Scripts, global: global, filePath: fileName);
1170 break;
1171
1172
1173 case "gtag":
1174 GlobalTagManager.instance.LoadData(fileData);
1175 break;
1176
1177 case "qiz":
1178#if !UNITY_WEBGL
1179 if (!File.Exists(Path.Combine(Application.streamingAssetsPath, "quizes", fileName)))
1180 File.WriteAllBytes(Path.Combine(Application.streamingAssetsPath, "quizes", fileName), fileData);
1181#endif
1182 var qiz = new GameObject(fileName);
1183 qiz.transform.SetParent(paretnObject.transform);
1184 var ufq = qiz.AddComponent<UploadedFile>();
1185 ufq.modelData = fileData;
1186 ufq.fileName = fileName;
1187 ufq.global = global;
1188 break;
1189
1190 default:
1191
1192 Debug.Log(fileName + " no cases to this file");
1193 PopupManager.instance.ShowPopup(Macro.T("UNSUPPORTED_FILE"),
1194 Macro.T("UNSUPPORTED_FILE_TEXT"));
1195 break;
1196 }
1197
1199 }
1200
1201 public void StartLateRebuild(bool force = false)
1202 {
1203 if (force)
1204 {
1206 return;
1207 }
1208 if (!isLoading || !LoadingManager.instance.MainLoading)
1209 {
1210 if (lateRebuild != null)
1211 StopCoroutine(lateRebuild);
1212 lateRebuild = StartCoroutine(LateRebuild());
1213 }
1214 }
1215
1216 public void SetLoading(bool value) => isLoading = value;
1217
1218 public IEnumerator LateRebuild()
1219 {
1220 if (isLoading/* || LoadingManager.instance.isLoading*/)
1221 {
1222 yield break;
1223 }
1224 LoadingManager.instance.ShowWindow();
1225 yield return new WaitForSeconds(0.11f);
1226 pb_Hierarchy.instance.RebuildInspector();
1227
1228 prefabBrowser.gameObject.SetActive(false);
1229 yield return new WaitForEndOfFrame();
1230 prefabBrowser.gameObject.SetActive(true);
1231
1232 var allrefabbuttno = FindObjectsOfType<pb_PrefabBrowserItemButton>();
1233
1234 foreach (var button in allrefabbuttno)
1235 {
1236 yield return new WaitForEndOfFrame();
1237 button.OnPointerEnter(null);
1238 yield return new WaitForEndOfFrame();
1239 button.OnPointerExit(null);
1240 yield return new WaitForEndOfFrame();
1241 }
1242
1243 while (LoadingManager.instance.MainLoading)
1244 {
1245 yield return null;
1246 }
1247 LoadingManager.instance.HideWindow();
1248 prefabBrowser.scrollbar.value = 1.0f;
1249 }
1250
1251 IEnumerator DownloadImage(string MediaUrl, RawImage ri, GameObject go)
1252 {
1253 UnityWebRequest request = UnityWebRequestTexture.GetTexture(MediaUrl);
1254 yield return request.SendWebRequest();
1255 if (request.isNetworkError || request.isHttpError)
1256 Debug.Log(request.error);
1257 else
1258 ri.texture = ((DownloadHandlerTexture)request.downloadHandler).texture;
1260 }
1261
1262 IEnumerator ResizeHelpBG(MeshRenderer mr, GameObject go, string filepath, bool global = false)
1263 {
1264 yield return new WaitForEndOfFrame();
1265 var rect = go.GetComponent<RectTransform>();
1266 Debug.Log(rect.sizeDelta);
1267 Debug.Log(mr.bounds);
1268 rect.sizeDelta = new Vector2(mr.bounds.size.x / 0.02f, mr.bounds.size.y / 0.02f) * 1.05f;
1269 prefabBrowser.AddGameObject(mr.gameObject, pb_PrefabBrowser.LoadPanel.Helps, filepath, global);
1270 Debug.Log("hlp added to PB! " + mr.gameObject.name);
1271 mr.gameObject.transform.SetParent(paretnObject.transform, true);
1272 }
1273
1274 private void ModLoader(string fileName, string modData, bool global = false, bool newUpload = false)
1275 {
1276 StartCoroutine(LateModLoader(fileName, modData, global, newUpload));
1277 }
1278
1279 private IEnumerator LateModLoader(string fileName, string modData, bool global = false, bool newUpload = false)
1280 {
1281 yield return null;
1282
1283 while (LoadingManager.instance.isLoading)
1284 {
1285 yield return null;
1286 }
1287
1288 var basemodel = paretnObject.transform.Find(fileName.Replace(".mod", ""));
1289 if (!basemodel)
1290 {
1291 Debug.LogError("MOD does not have base model!");
1292 yield break;
1293 }
1294 var moddedModel = Instantiate(basemodel, paretnObject.transform);
1295 moddedModel.name = moddedModel.name.Replace("(Clone)", "") + ".mod";
1296 var meshFilter = moddedModel.GetComponentInChildren<MeshFilter>();
1297 var mesh = meshFilter.mesh;
1298 var vertices = mesh.vertices;
1299 var data = modData.Split('\n');
1300 foreach (var s in data)
1301 {
1302 try
1303 {
1304 var a = s.Split(';');
1305 var i = Convert.ToInt32(a[0]);
1306 var x = Convert.ToSingle(a[1]);
1307 var y = Convert.ToSingle(a[2]);
1308 var z = Convert.ToSingle(a[3]);
1309 vertices[i] = new Vector3(x, y, z);
1310 }
1311 catch (Exception)
1312 {
1313 // ignored
1314 }
1315 }
1316
1317 mesh.vertices = vertices;
1318 mesh.RecalculateNormals();
1319
1320 var mc = meshFilter.gameObject.GetComponent<MeshCollider>();
1321 DestroyImmediate(mc);
1322 mc = meshFilter.gameObject.AddComponent<MeshCollider>();
1323 mc.convex = true;
1324
1325 var tc = moddedModel.GetComponent<TagCloud>();
1326 tc.filePath = fileName;
1327 tc.TryLoad();
1328
1329 var uf = moddedModel.GetComponent<UploadedFile>();
1330 uf.fileName = fileName;
1331 uf.modelData = Encoding.UTF8.GetBytes(modData);
1332
1333
1334#if UNITY_WEBGL
1335 if (newUpload)
1336 {
1337 YesNoPopupManager.instance.ShowPopup("GLOBAL_UPLOAD", "GLOBAL_UPLOAD_TEXT", "GLOBAL", "LOCAL");
1338 YesNoPopupManager.instance.InvokeOnNo(() =>
1339 {
1340 uf.global = false;
1341
1342 prefabBrowser.AddGameObject(moddedModel.gameObject, pb_PrefabBrowser.LoadPanel.Models, fileName, false);
1344 });
1345 YesNoPopupManager.instance.InvokeOnYes(() =>
1346 {
1347 uf.global = true;
1348
1349 prefabBrowser.AddGameObject(moddedModel.gameObject, pb_PrefabBrowser.LoadPanel.Models, fileName, true);
1351 });
1352 }
1353 else
1354#endif
1355 {
1356
1357 prefabBrowser.AddGameObject(moddedModel.gameObject, pb_PrefabBrowser.LoadPanel.Models, fileName, global);
1359 StartCoroutine(pb_PrefabBrowser.instance.RefreshPanel());
1360 }
1361 }
1362
1363 [Button]
1364 void TestLoadImage()
1365 {
1366 OnFiles(new List<string> { @"C:\Users\UnityTeam\Downloads\Hamtaro-HAMTARO.png" }, new POINT(1, 1));
1367 }
1368
1369 [Button]
1370 void TestLoadSound()
1371 {
1372 OnFiles(new List<string> { @"C:\Users\UnityTeam\Desktop\Zipper Case_VS 04.mp3" }, new POINT(1, 1));
1373 }
1374
1375 [Button]
1376 void TestLoadVideo()
1377 {
1378 OnFiles(new List<string> { @"E:\smol.mp4" }, new POINT(1, 1));
1379 }
1380
1381 [Button]
1382 void TestLoadVideo2()
1383 {
1384 OnFiles(new List<string> { @"C:\Users\UnityTeam\Downloads\file_example_MP4.mp4" }, new POINT(1, 1));
1385 }
1386
1387 [Button]
1388 void TestLoadModel()
1389 {
1390 OnFiles(new List<string> { @"D:\GIT\UNITY\vrtanoda\Assets\StreamingAssets\models\TEA.FBX" }, new POINT(1, 1));
1391 }
1392
1393 [Button]
1394 void TestLoadModel2()
1395 {
1396 OnFiles(new List<string> { @"C:\Users\Soma\3D Objects\tooltable_extended_2.fbx" }, new POINT(1, 1));
1397 }
1398
1399 public string DebugLoadThis = "";
1400
1401 [Button]
1402 void LoadThis()
1403 {
1404 OnFiles(new List<string> { DebugLoadThis }, new POINT(0, 1));
1405 }
1406
1407
1408 [Button]
1409 void TestLoadGTags()
1410 {
1411 OnFiles(new List<string> { @"E:\aaaaaa\globalTags.gtag" }, new POINT(0, 0));
1412 }
1413}
UnityEngine.UI.Button Button
Definition: Pointer.cs:7
UnityEngine.Debug Debug
Definition: TanodaServer.cs:19
System.Drawing.Image Image
Definition: TestScript.cs:37
UnityEngine.Color Color
Definition: TestScript.cs:32
void StartLateRebuild(bool force=false)
bool GetUploadedGOFromName(string value, out GameObject retval)
static FileDragAndDrop instance
pb_PrefabBrowser prefabBrowser
void OnFiles(List< string > aFiles, POINT aPos)
bool alreadyLoaded(string aFile)
void SetLoading(bool value)
void OpenFileUploadDialog()
IEnumerator LateRebuild()
IEnumerator ThreadedLoad(List< string > aFiles, bool recursive=false)
void OnFileData(byte[] fileData, string fileName, string modified, NetworkManager.WSFile wsFile=default, bool global=false, bool newUpload=false)
void AddGameObject(GameObject gobject, LoadPanel panel=LoadPanel.None, string filePath="", bool global=false)
static pb_PrefabBrowser instance
static GLTFastLoader instance
GameObject Load(byte[] data, string filename, GameObject wrapper=null, bool singleModel=false, bool global=false)
bool HasTexture(string filename)
void AddTexture(string filename, Texture2D texture)
Texture2D GetLowRes(string filename)
static GlobalTextureHolder instance
Definition: Macro.cs:12
static string T(string key)
Definition: Macro.cs:19
static float MinMaxClamp(float value, float min, float max)
Definition: Macro.cs:337
static float StoF(string value)
Definition: Macro.cs:24
void SetFilePath(string path)
Definition: NAudioPlayer.cs:64
bool HasFileLoaded(string filepath, out GameObject go)
Definition: Preloader.cs:31
void LoadFromMemory(byte[] data, string filename, GameObject wrapper=null, bool singleModel=false, bool global=false)
void TryLoad()
Definition: TagCloud.cs:48
string filePath
Definition: TagCloud.cs:11
byte[] modelData
Definition: UploadedFile.cs:7
string fileName
Definition: UploadedFile.cs:8
Definition: B83.Win32.cs:38