Example #1
0
        private IEnumerator DownloadIntoOrLoadWebPFromFolderRoutine(string folderPath, MonoBehaviour context, string url, Image image, Action onSuccess = null, Action <string> onError = null)
        {
            yield return(new WaitForEndOfFrame());

            string filePath = ImageDownloader.GetImageFilePathFromUrl(url, folderPath);

            if (!Directory.Exists(folderPath))
            {
                Directory.CreateDirectory(folderPath);
            }
            if (File.Exists(filePath))
            {
                LoadTextureFromWebP(File.ReadAllBytes(filePath));
                onSuccess?.Invoke();
            }
            else
            {
                WWWUtils.LoadBinaryFromWWW(this, url, bytes => {
                    LoadTextureFromWebP(bytes);
                    File.WriteAllBytes(filePath, bytes);
                    onSuccess?.Invoke();
                });
            }
        }