-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSampleLoadFromUrlsOrStorage.cs
More file actions
81 lines (72 loc) · 2.23 KB
/
SampleLoadFromUrlsOrStorage.cs
File metadata and controls
81 lines (72 loc) · 2.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
using System;
using System.Collections;
using System.Collections.Generic;
using System.Threading;
using Cysharp.Threading.Tasks;
using UnityEngine;
using UnityEngine.UI;
using UnityTextureLoader.Cache;
namespace UnityTextureLoader
{
public class SampleLoadFromUrlsOrStorage : MonoBehaviour
{
// tips and tricks google drive : https://www.labnol.org/internet/direct-links-for-google-drive/28356/
// google drive https://drive.google.com/uc?export=download&id=1GDbwdE3HVIqjQbNB9MpZFNhQgpBMWagW
// https://drive.google.com/uc?export=download&id=11_DnGOzADaKjB4_LTDLY5hjUOp_tnV-c
// google drive https://docs.google.com/document/d/DOC_FILE_ID/export?format=doc
// amazon https://s3.amazonaws.com/omeka-net/59415/archive/files/519627986585e21157376c430ab085d6.png?AWSAccessKeyId=AKIAI3ATG3OSQLO5HGKA&Expires=1625097600&Signature=ZTHZlYJlXmJqLR4hyiU6sT0TtWQ%3D
[SerializeField] private List<string> urls = new List<string>();
[SerializeField] private bool LoadPack = false;
[SerializeField] private bool ClearCache = false;
[SerializeField] private List<RawImage> arrayOfImages = new List<RawImage>();
[NonSerialized] private LoadTextureAsync _currentLoader = null;
private CancellationTokenSource Source = null;
private void OnValidate()
{
if (!Application.isPlaying)
{
return;
}
if (LoadPack)
{
LoadPack = false;
ClearImages();
LoadAllImages().Forget();
}
if (ClearCache)
{
ClearCache = false;
ClearImages();
}
}
private void OnDisable()
{
Source?.Dispose();
Source = new CancellationTokenSource();
}
private void ClearImages()
{
foreach (var rawImage in arrayOfImages)
{
rawImage.texture.SafeDestroy();
}
}
private async UniTaskVoid LoadAllImages()
{
if (_currentLoader == null)
{
_currentLoader = new LoadTextureAsync();
var loader = new MrtkDiskCacheProvider();
loader.SetInitialCachePath("testLoadAsyncFolder");
_currentLoader.SetDiskLoader(loader);
}
Source = new CancellationTokenSource();
for (int i = 0; i < urls.Count; i++)
{
var texture = await _currentLoader.LoadTexture(Texture2D.redTexture, urls[i], null, Source.Token);
await UniTask.SwitchToMainThread();
arrayOfImages[i].texture = texture;
}
}
}
}