feat(storagemanager): correctly convert GS url to http url
This commit is contained in:
parent
c952783c36
commit
878a8d18fa
@ -28,44 +28,23 @@ public void Initialize(Proposition _proposition)
|
|||||||
DisplayPicture(proposition.photoUrl);
|
DisplayPicture(proposition.photoUrl);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void DisplayPicture(string _url)
|
/// <summary>
|
||||||
|
/// Url is Google bucket URL. We
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="_gsUrl"></param>
|
||||||
|
private void DisplayPicture(string _gsUrl)
|
||||||
{
|
{
|
||||||
Debug.Log($"Downloading {_url}");
|
Debug.Log($"Google Storage URL : {_gsUrl}");
|
||||||
|
StorageManager.ConvertGoogleStorageURLToHttpsUrl(_gsUrl, _url =>
|
||||||
StorageReference imageRef = FirebaseStorage.DefaultInstance.GetReferenceFromUrl(_url);
|
|
||||||
imageRef.GetDownloadUrlAsync().ContinueWithOnMainThread(task =>
|
|
||||||
{
|
{
|
||||||
if (task.IsFaulted || task.IsCanceled)
|
StartCoroutine(StorageManager.DownloadImage_Coroutine(_url, _texture =>
|
||||||
{
|
{
|
||||||
Debug.LogException(task.Exception);
|
Debug.Log("Set texture in the raw image");
|
||||||
}
|
picture.texture = _texture;
|
||||||
else
|
}));
|
||||||
{
|
|
||||||
Debug.Log("Download URL: " + task.Result);
|
|
||||||
StartCoroutine(DownloadImage(task.Result.AbsolutePath, _texture =>
|
|
||||||
{
|
|
||||||
Debug.Log("Set texture in the raw image");
|
|
||||||
picture.texture = _texture;
|
|
||||||
}));
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private IEnumerator DownloadImage(string _url, Action<Texture> 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<Player> _newVoters)
|
public void UpdateVoters(List<Player> _newVoters)
|
||||||
{
|
{
|
||||||
Debug.Log($"There are some new voters for {proposition.owner}'s proposition", this);
|
Debug.Log($"There are some new voters for {proposition.owner}'s proposition", this);
|
||||||
@ -80,4 +59,15 @@ public void UpdateVoters(List<Player> _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);
|
||||||
|
}));
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -27,11 +27,14 @@ void OnEnable()
|
|||||||
|
|
||||||
for (int i = 0; i < 2; i++)
|
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);
|
StartCoroutine(StorageManager.DownloadImage_Coroutine(_httpURL, (Texture texture) =>
|
||||||
btns[i].sprite = sprite;
|
{
|
||||||
}));
|
Sprite sprite = Sprite.Create(texture as Texture2D, new Rect(0, 0, texture.width, texture.height), Vector2.zero);
|
||||||
|
btns[i].sprite = sprite;
|
||||||
|
}));
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,8 +1,11 @@
|
|||||||
using Firebase.Database;
|
using Firebase.Database;
|
||||||
|
using Firebase.Extensions;
|
||||||
using Firebase.Storage;
|
using Firebase.Storage;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections;
|
using System.Collections;
|
||||||
|
using System.Security.Policy;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using UnityEditor;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using UnityEngine.Networking;
|
using UnityEngine.Networking;
|
||||||
|
|
||||||
@ -68,7 +71,7 @@ public void UploadPhoto(string roomCode, string playerId, int question, int prop
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public IEnumerator DownloadImage(string _url, Action<Texture> callback_OnTextureDownloaded)
|
public static IEnumerator DownloadImage_Coroutine(string _url, Action<Texture> callback_OnTextureDownloaded)
|
||||||
{
|
{
|
||||||
UnityWebRequest request = UnityWebRequestTexture.GetTexture(_url);
|
UnityWebRequest request = UnityWebRequestTexture.GetTexture(_url);
|
||||||
yield return request.SendWebRequest();
|
yield return request.SendWebRequest();
|
||||||
@ -82,4 +85,22 @@ public IEnumerator DownloadImage(string _url, Action<Texture> callback_OnTexture
|
|||||||
callback_OnTextureDownloaded?.Invoke(((DownloadHandlerTexture)request.downloadHandler).texture);
|
callback_OnTextureDownloaded?.Invoke(((DownloadHandlerTexture)request.downloadHandler).texture);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void ConvertGoogleStorageURLToHttpsUrl(string _gsURL, Action<string> 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());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user