diff --git a/Assets/Scripts/PropositionFrame.cs b/Assets/Scripts/PropositionFrame.cs index f03cd2a..42caa2f 100644 --- a/Assets/Scripts/PropositionFrame.cs +++ b/Assets/Scripts/PropositionFrame.cs @@ -28,44 +28,23 @@ public void Initialize(Proposition _proposition) DisplayPicture(proposition.photoUrl); } - private void DisplayPicture(string _url) + /// + /// Url is Google bucket URL. We + /// + /// + private void DisplayPicture(string _gsUrl) { - Debug.Log($"Downloading {_url}"); - - StorageReference imageRef = FirebaseStorage.DefaultInstance.GetReferenceFromUrl(_url); - imageRef.GetDownloadUrlAsync().ContinueWithOnMainThread(task => + Debug.Log($"Google Storage URL : {_gsUrl}"); + StorageManager.ConvertGoogleStorageURLToHttpsUrl(_gsUrl, _url => { - if (task.IsFaulted || task.IsCanceled) + StartCoroutine(StorageManager.DownloadImage_Coroutine(_url, _texture => { - Debug.LogException(task.Exception); - } - else - { - Debug.Log("Download URL: " + task.Result); - StartCoroutine(DownloadImage(task.Result.AbsolutePath, _texture => - { - Debug.Log("Set texture in the raw image"); - picture.texture = _texture; - })); - } + Debug.Log("Set texture in the raw image"); + picture.texture = _texture; + })); }); } - private IEnumerator DownloadImage(string _url, Action callback_OnTextureDownloaded) - { - UnityWebRequest request = UnityWebRequestTexture.GetTexture(_url); - yield return request.SendWebRequest(); - - if (request.result != UnityWebRequest.Result.Success) - { - Debug.LogError(request.error); - } - else - { - callback_OnTextureDownloaded?.Invoke(((DownloadHandlerTexture)request.downloadHandler).texture); - } - } - public void UpdateVoters(List _newVoters) { Debug.Log($"There are some new voters for {proposition.owner}'s proposition", this); @@ -80,4 +59,15 @@ public void UpdateVoters(List _newVoters) } } } + + [ContextMenu("Debug Download image")] + private void Debug_DownloadImage() + { + StartCoroutine(DownloadImage("https://firebasestorage.googleapis.com/v0/b/ggj2024-5cb41.appspot.com/o/0278%2F63ae32b0-8371-4a7a-84a0-e1a97328fc09%2F10a5127b-12d4-48ca-b94c-1cb920a43529.png?alt=media&token=d7e53d8a-d5b4-40f9-847d-224ed2d683dc", + texture => + { + Debug.Log(texture.dimension); + })); + + } } diff --git a/Assets/Scripts/PropositionHandler.cs b/Assets/Scripts/PropositionHandler.cs index 40a66b1..17778e2 100644 --- a/Assets/Scripts/PropositionHandler.cs +++ b/Assets/Scripts/PropositionHandler.cs @@ -27,11 +27,14 @@ void OnEnable() for (int i = 0; i < 2; i++) { - StartCoroutine(storageManager.DownloadImage(props[i].photoUrl, (Texture texture) => + StorageManager.ConvertGoogleStorageURLToHttpsUrl(props[i].photoUrl, _httpURL => { - Sprite sprite = Sprite.Create(texture as Texture2D, new Rect(0, 0, texture.width, texture.height), Vector2.zero); - btns[i].sprite = sprite; - })); + StartCoroutine(StorageManager.DownloadImage_Coroutine(_httpURL, (Texture texture) => + { + Sprite sprite = Sprite.Create(texture as Texture2D, new Rect(0, 0, texture.width, texture.height), Vector2.zero); + btns[i].sprite = sprite; + })); + }); } } diff --git a/Assets/Scripts/StorageManager.cs b/Assets/Scripts/StorageManager.cs index ec76fc3..fb02a5e 100644 --- a/Assets/Scripts/StorageManager.cs +++ b/Assets/Scripts/StorageManager.cs @@ -1,8 +1,11 @@ using Firebase.Database; +using Firebase.Extensions; using Firebase.Storage; using System; using System.Collections; +using System.Security.Policy; using System.Threading.Tasks; +using UnityEditor; using UnityEngine; using UnityEngine.Networking; @@ -68,7 +71,7 @@ public void UploadPhoto(string roomCode, string playerId, int question, int prop }); } - public IEnumerator DownloadImage(string _url, Action callback_OnTextureDownloaded) + public static IEnumerator DownloadImage_Coroutine(string _url, Action callback_OnTextureDownloaded) { UnityWebRequest request = UnityWebRequestTexture.GetTexture(_url); yield return request.SendWebRequest(); @@ -82,4 +85,22 @@ public IEnumerator DownloadImage(string _url, Action callback_OnTexture callback_OnTextureDownloaded?.Invoke(((DownloadHandlerTexture)request.downloadHandler).texture); } } + + public static void ConvertGoogleStorageURLToHttpsUrl(string _gsURL, Action callback_OnURLFound) + { + StorageReference imageRef = FirebaseStorage.DefaultInstance.GetReferenceFromUrl(_gsURL); + imageRef.GetDownloadUrlAsync().ContinueWithOnMainThread(task => + { + if (task.IsFaulted || task.IsCanceled) + { + Debug.LogException(task.Exception); + } + else + { + Debug.Log("Image HTTPS URL: " + task.Result); + callback_OnURLFound?.Invoke(task.Result.ToString()); + } + }); + + } }