Snaparazzi/Assets/Scripts/PropositionHandler.cs

46 lines
1.5 KiB
C#
Raw Normal View History

2024-01-28 21:42:02 +00:00
using Firebase.Database;
using Newtonsoft.Json;
2024-01-28 16:34:11 +00:00
using System.Collections.Generic;
using System.Linq;
2024-01-28 21:42:02 +00:00
using TMPro;
2024-01-28 16:34:11 +00:00
using UnityEngine;
using UnityEngine.UI;
2024-01-28 21:42:02 +00:00
public class PropositionHandler : MonoBehaviour
2024-01-28 16:34:11 +00:00
{
public GameManager gameManager;
public StorageManager storageManager;
2024-01-28 21:42:02 +00:00
public TextMeshProUGUI promptLabel;
public PromptList prompts;
2024-01-28 16:34:11 +00:00
public Image[] btns;
2024-01-28 21:42:02 +00:00
public void ShowQuestion(Question currentQuestion)
2024-01-28 16:34:11 +00:00
{
2024-01-28 21:42:02 +00:00
List<Proposition> props = currentQuestion.propositions.Values.ToList();
string enPrompt = prompts.GetPromptById(currentQuestion.promptId).en;
promptLabel.text = enPrompt;
Debug.Log($"Showing Question ({currentQuestion.index}) : {enPrompt}");
2024-01-28 16:35:11 +00:00
for (int i = 0; i < 2; i++)
{
2024-01-29 20:01:09 +00:00
int index = i; // Capture la valeur de i pour cette it<69>ration
if(props[i].photoUrl == null)
{
Debug.Log("One player did not send a proposition !", this);
}
else
2024-01-28 16:35:11 +00:00
{
StorageManager.ConvertGoogleStorageURLToHttpsUrl(props[i].photoUrl, _httpURL =>
{
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[index].sprite = sprite; // Utilise l'index local au lieu de i
}));
});
}
2024-01-28 16:34:11 +00:00
}
2024-01-29 20:01:09 +00:00
2024-01-28 16:34:11 +00:00
}
}