From 4e2ce97cd26d5171d6a1390deb46abe35a177363 Mon Sep 17 00:00:00 2001 From: Michel Roux Date: Sun, 28 Jan 2024 17:34:11 +0100 Subject: [PATCH] feat: download image on proposition --- Assets/Scripts/DatabaseClasses/Room.cs | 4 +-- Assets/Scripts/PropositionHandler.cs | 40 +++++++++++++++++++++++ Assets/Scripts/PropositionHandler.cs.meta | 11 +++++++ 3 files changed, 53 insertions(+), 2 deletions(-) create mode 100644 Assets/Scripts/PropositionHandler.cs create mode 100644 Assets/Scripts/PropositionHandler.cs.meta diff --git a/Assets/Scripts/DatabaseClasses/Room.cs b/Assets/Scripts/DatabaseClasses/Room.cs index 5ba913d..7834fde 100644 --- a/Assets/Scripts/DatabaseClasses/Room.cs +++ b/Assets/Scripts/DatabaseClasses/Room.cs @@ -13,7 +13,7 @@ public class Room [JsonConverter(typeof(ArrayToDictionaryConverter))] public Dictionary questions; public Dictionary players; - public string currentQuestionId; + public int currentQuestionId; public double creationDate; public int currentState; @@ -23,7 +23,7 @@ public Room(string _code) creationDate = DateTime.Now.ToOADate(); players = new Dictionary(); questions = new Dictionary(); - currentQuestionId = ""; + currentQuestionId = 0; currentState = 1; //default by PC } diff --git a/Assets/Scripts/PropositionHandler.cs b/Assets/Scripts/PropositionHandler.cs new file mode 100644 index 0000000..759adcf --- /dev/null +++ b/Assets/Scripts/PropositionHandler.cs @@ -0,0 +1,40 @@ +using System.Collections.Generic; +using System.Linq; +using UnityEngine; +using UnityEngine.UI; + +public class PropositionDownload : MonoBehaviour +{ + public GameManager gameManager; + public StorageManager storageManager; + public Image[] btns; + + // Start is called before the first frame update + void Start() + { + + } + + // Update is called once per frame + void Update() + { + + } + + void OnEnable() + { + List props = gameManager.myRoom.questions[gameManager.myRoom.currentQuestionId].propositions.Values.ToList(); + + for (int i = 0; i < 2; i++) { + storageManager.DownloadImage(props[i].photoUrl, (Texture texture) => { + Sprite sprite = Sprite.Create(texture as Texture2D, new Rect(0, 0, texture.width, texture.height), Vector2.zero); + btns[i].sprite = sprite; + }); + } + } + + void OnDisable() + { + + } +} diff --git a/Assets/Scripts/PropositionHandler.cs.meta b/Assets/Scripts/PropositionHandler.cs.meta new file mode 100644 index 0000000..b0fad22 --- /dev/null +++ b/Assets/Scripts/PropositionHandler.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 02c0fa5c3e6cb4ce29942d8cb857076e +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: