diff --git a/Assets/Scenes/PhoneView.unity b/Assets/Scenes/PhoneView.unity index 09b328c..59f9fe3 100644 --- a/Assets/Scenes/PhoneView.unity +++ b/Assets/Scenes/PhoneView.unity @@ -3470,6 +3470,9 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 27a435387a7644784a6fc6ae538b68e5, type: 3} m_Name: m_EditorClassIdentifier: + currentPlayer: + name: + id: explanationTime: 4 roomCodeField: {fileID: 2023851070} roomError: {fileID: 991600093} @@ -3485,6 +3488,12 @@ MonoBehaviour: VotePicture: {fileID: 531335861} WaitingOtherPlayers: {fileID: 2095389711} EndGame: {fileID: 1850164816} + myRoom: + code: + questions: [] + players: [] + currentQuestion: 0 + creationDate: 0 --- !u!1 &1224049644 GameObject: m_ObjectHideFlags: 0 @@ -6173,6 +6182,7 @@ GameObject: - component: {fileID: 2010012970} - component: {fileID: 2010012969} - component: {fileID: 2010012968} + - component: {fileID: 2010012971} m_Layer: 5 m_Name: SubmitBtn m_TagString: Untagged @@ -6243,7 +6253,19 @@ MonoBehaviour: m_TargetGraphic: {fileID: 2010012969} m_OnClick: m_PersistentCalls: - m_Calls: [] + m_Calls: + - m_Target: {fileID: 2010012971} + m_TargetAssemblyTypeName: StorageManager, Assembly-CSharp + m_MethodName: SaveFile + m_Mode: 1 + m_Arguments: + m_ObjectArgument: {fileID: 0} + m_ObjectArgumentAssemblyTypeName: UnityEngine.Object, UnityEngine + m_IntArgument: 0 + m_FloatArgument: 0 + m_StringArgument: + m_BoolArgument: 0 + m_CallState: 2 --- !u!114 &2010012969 MonoBehaviour: m_ObjectHideFlags: 0 @@ -6282,6 +6304,20 @@ CanvasRenderer: m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 2010012966} m_CullTransparentMesh: 1 +--- !u!114 &2010012971 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 2010012966} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 3b41deef4ebd372d5a18eabdb00cfbb4, type: 3} + m_Name: + m_EditorClassIdentifier: + PicturePlayer: {fileID: 1316036595} + Canvas: {fileID: 1202782726} --- !u!1 &2023851068 GameObject: m_ObjectHideFlags: 0 diff --git a/Assets/Scripts/DatabaseClasses/Player.cs b/Assets/Scripts/DatabaseClasses/Player.cs index d03d3a8..31b4643 100644 --- a/Assets/Scripts/DatabaseClasses/Player.cs +++ b/Assets/Scripts/DatabaseClasses/Player.cs @@ -1,8 +1,7 @@ -using System.Collections; -using System.Collections.Generic; +using System; using System.Text.RegularExpressions; -[System.Serializable] +[Serializable] public class Player { public string name; @@ -10,7 +9,7 @@ public class Player public Player(string _name) { - id = System.Guid.NewGuid().ToString(); + id = Guid.NewGuid().ToString(); name = _name; } @@ -30,7 +29,7 @@ private string SanitizeString(string input) // Limitez la longueur à 16 caractères maximum if (sanitized.Length > 16) { - sanitized = sanitized.Substring(0, 16); + sanitized = sanitized[..16]; } return sanitized; diff --git a/Assets/Scripts/DatabaseClasses/Prompt.cs b/Assets/Scripts/DatabaseClasses/Prompt.cs index c19c6e2..8f2d14e 100644 --- a/Assets/Scripts/DatabaseClasses/Prompt.cs +++ b/Assets/Scripts/DatabaseClasses/Prompt.cs @@ -1,9 +1,8 @@ -using System.Collections; -using System.Collections.Generic; using Firebase.Firestore; +using System; using UnityEngine; -[System.Serializable, FirestoreData] +[Serializable, FirestoreData] public class Prompt { [field: SerializeField] diff --git a/Assets/Scripts/DatabaseClasses/Proposition.cs b/Assets/Scripts/DatabaseClasses/Proposition.cs index 74d5059..0c77c35 100644 --- a/Assets/Scripts/DatabaseClasses/Proposition.cs +++ b/Assets/Scripts/DatabaseClasses/Proposition.cs @@ -1,8 +1,6 @@ -using System.Collections; -using System.Collections.Generic; -using UnityEngine; +using System; -[System.Serializable] +[Serializable] public class Proposition { public string photoUrl; diff --git a/Assets/Scripts/DatabaseClasses/Question.cs b/Assets/Scripts/DatabaseClasses/Question.cs index 5bc2f3e..1d7346e 100644 --- a/Assets/Scripts/DatabaseClasses/Question.cs +++ b/Assets/Scripts/DatabaseClasses/Question.cs @@ -1,9 +1,6 @@ using System; -using System.Collections; -using System.Collections.Generic; -using UnityEngine; -[System.Serializable] +[Serializable] public class Question { public string promptId; diff --git a/Assets/Scripts/DatabaseClasses/Room.cs b/Assets/Scripts/DatabaseClasses/Room.cs index 27e43a2..34b9c4f 100644 --- a/Assets/Scripts/DatabaseClasses/Room.cs +++ b/Assets/Scripts/DatabaseClasses/Room.cs @@ -1,7 +1,7 @@ +using System; using System.Collections.Generic; -using UnityEngine; -[System.Serializable] +[Serializable] public class Room { public string code; @@ -13,10 +13,10 @@ public class Room public Room(string _code) { - this.code = _code; - this.creationDate = System.DateTime.Now.ToOADate(); - this.players = new List(); - this.questions = new List(); - this.currentQuestion = 0; + code = _code; + creationDate = DateTime.Now.ToOADate(); + players = new List(); + questions = new List(); + currentQuestion = 0; } } diff --git a/Assets/Scripts/FirebaseInitializer.cs b/Assets/Scripts/FirebaseInitializer.cs index afeeed5..305554f 100644 --- a/Assets/Scripts/FirebaseInitializer.cs +++ b/Assets/Scripts/FirebaseInitializer.cs @@ -1,7 +1,7 @@ using Firebase; -using System.Collections; -using UnityEngine; +using Firebase.Auth; using System; +using UnityEngine; using UnityEngine.Android; public class FirebaseInitializer : MonoBehaviour @@ -41,7 +41,7 @@ void Start() // Update is called once per frame void Authenticate() { - Firebase.Auth.FirebaseAuth auth = Firebase.Auth.FirebaseAuth.DefaultInstance; + FirebaseAuth auth = FirebaseAuth.DefaultInstance; auth.SignInAnonymouslyAsync().ContinueWith(task => { @@ -56,7 +56,7 @@ void Authenticate() return; } - Firebase.Auth.AuthResult result = task.Result; + AuthResult result = task.Result; Debug.Log($"User signed in successfully: {result.User.UserId}"); onFirebaseReady?.Invoke(); diff --git a/Assets/Scripts/GameManager.cs b/Assets/Scripts/GameManager.cs index 156e872..83334b3 100644 --- a/Assets/Scripts/GameManager.cs +++ b/Assets/Scripts/GameManager.cs @@ -15,7 +15,7 @@ public class GameManager : MonoBehaviour { private GameState currentState; private List players = new List(); - private Player currentPlayer= null; + public Player currentPlayer = null; @@ -37,25 +37,18 @@ public class GameManager : MonoBehaviour [Header("Pages")] - [SerializeField] public GameObject HomeConnection; - [SerializeField] public GameObject WaitingRoom; - [SerializeField] public GameObject BeforeStart; - [SerializeField] public GameObject TakePicture; - [SerializeField] public GameObject VotePicture; - [SerializeField] public GameObject WaitingOtherPlayers; - [SerializeField] public GameObject EndGame; private DatabaseReference realtimeDB; - private Room myRoom; + public Room myRoom; private DatabaseReference myOnlineRoom; private void Awake() diff --git a/Assets/Scripts/Menu.cs b/Assets/Scripts/Menu.cs index 29673b0..7685145 100644 --- a/Assets/Scripts/Menu.cs +++ b/Assets/Scripts/Menu.cs @@ -1,5 +1,3 @@ -using System.Collections; -using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; @@ -14,6 +12,6 @@ void Start() // Update is called once per frame void Update() { - + } } diff --git a/Assets/Scripts/PhoneLoop.cs b/Assets/Scripts/PhoneLoop.cs index 0580aec..33f8a9d 100644 --- a/Assets/Scripts/PhoneLoop.cs +++ b/Assets/Scripts/PhoneLoop.cs @@ -1,25 +1,13 @@ -using System.Collections; -using System.Collections.Generic; -using Unity.VisualScripting; using UnityEngine; public class PhoneLoop : MonoBehaviour { - - - [SerializeField] public GameObject homeConnection; - [SerializeField] public GameObject WaitingRoom; - [SerializeField] public GameObject BeforeStart; - [SerializeField] public GameObject TakePicture; - [SerializeField] public GameObject VotePicture; - [SerializeField] public GameObject WaitingOtherPlayers; - [SerializeField] public GameObject EndGame; // Start is called before the first frame update @@ -31,7 +19,7 @@ void Start() // Update is called once per frame void Update() { - + } void ShowWaititngRoom() @@ -82,20 +70,14 @@ void ShowVotePicture() void ShowEndGame() { - WaitingOtherPlayers.SetActive(false) ; + WaitingOtherPlayers.SetActive(false); EndGame.SetActive(true); } - - [ContextMenu("Fake Player Connection")] private void FakePlayerConnection() { - + } - - - - } diff --git a/Assets/Scripts/PromptList.cs b/Assets/Scripts/PromptList.cs index 5458c89..2c2bb13 100644 --- a/Assets/Scripts/PromptList.cs +++ b/Assets/Scripts/PromptList.cs @@ -5,8 +5,7 @@ [CreateAssetMenu(fileName = "PromptList", menuName = "ScriptableObjects/Prompt List", order = 1)] public class PromptList : ScriptableObject { - public List prompts = new List(); - + public List prompts = new(); /// /// Create a new entry with a unique ID @@ -14,8 +13,10 @@ public class PromptList : ScriptableObject [ContextMenu("Create Entry")] private void CreateEntry() { - Prompt temp = new Prompt(); - temp.id = System.Guid.NewGuid().ToString(); + Prompt temp = new() + { + id = Guid.NewGuid().ToString() + }; prompts.Add(temp); } } diff --git a/Assets/Scripts/PromptListLoader.cs b/Assets/Scripts/PromptListLoader.cs index 68209eb..8f4d619 100644 --- a/Assets/Scripts/PromptListLoader.cs +++ b/Assets/Scripts/PromptListLoader.cs @@ -1,9 +1,7 @@ -using System.Collections; -using System.Collections.Generic; -using UnityEngine; +using Firebase.Extensions; using Firebase.Firestore; using System; -using Firebase.Extensions; +using UnityEngine; /// /// This class will download or upload the prompts from/to the Firestore @@ -145,7 +143,7 @@ private void AddPromptToFirestore(Prompt _prompt = null) [ContextMenu("Generate Random Id")] private void GenerateRandomId() { - addPrompt.id = System.Guid.NewGuid().ToString(); + addPrompt.id = Guid.NewGuid().ToString(); } } diff --git a/Assets/Scripts/RoomManager.cs b/Assets/Scripts/RoomManager.cs index acaafd8..971d21d 100644 --- a/Assets/Scripts/RoomManager.cs +++ b/Assets/Scripts/RoomManager.cs @@ -1,11 +1,9 @@ -using System.Collections; -using System.Collections.Generic; -using Firebase; using Firebase.Database; using Firebase.Extensions; +using System; +using System.Collections.Generic; using TMPro; using UnityEngine; -using System; public class RoomManager : MonoBehaviour { diff --git a/Assets/Scripts/StorageManager.cs b/Assets/Scripts/StorageManager.cs new file mode 100644 index 0000000..289ed34 --- /dev/null +++ b/Assets/Scripts/StorageManager.cs @@ -0,0 +1,64 @@ +using Firebase.Storage; +using System; +using System.Threading.Tasks; +using UnityEngine; + +public class StorageManager : MonoBehaviour +{ + public GameObject PicturePlayer; + public GameObject Canvas; + private FirebaseStorage storage; + + void Awake() + { + FirebaseInitializer.Instance.onFirebaseReady += Initialize; + } + + void Initialize() + { + FirebaseInitializer.Instance.onFirebaseReady -= Initialize; + storage = FirebaseStorage.DefaultInstance; + } + + // Start is called before the first frame update + void Start() + { + + } + + // Update is called once per frame + void Update() + { + + } + + public void UploadPhoto() + { + Texture2D photo = PicturePlayer.GetComponent().GetPhoto(); + byte[] photoBytes = ImageConversion.EncodeToJPG(photo); + + GameManager game = Canvas.GetComponent(); + string imageUuid = Guid.NewGuid().ToString(); + + StorageReference storageRef = storage.GetReferenceFromUrl("gs://ggj2024-5cb41.appspot.com"); + StorageReference imageRef = storageRef.Child(game.myRoom.code).Child(game.currentPlayer.id).Child($"{imageUuid}.jpg"); + + imageRef.PutBytesAsync(photoBytes).ContinueWith((Task task) => + { + if (task.IsFaulted || task.IsCanceled) + { + Debug.Log(task.Exception.ToString()); + // Uh-oh, an error occurred! + } + else + { + // Metadata contains file metadata such as size, content-type, and md5hash. + StorageMetadata metadata = task.Result; + string md5Hash = metadata.Md5Hash; + Debug.Log("Finished uploading..."); + Debug.Log("md5 hash = " + md5Hash); + } + }); + + } +} diff --git a/Assets/Scripts/StorageManager.cs.meta b/Assets/Scripts/StorageManager.cs.meta new file mode 100644 index 0000000..f6e5179 --- /dev/null +++ b/Assets/Scripts/StorageManager.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 3b41deef4ebd372d5a18eabdb00cfbb4 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: