diff --git a/Assets/ScriptableObjects/PromptList.asset b/Assets/ScriptableObjects/PromptList.asset index 5cbe679..c957b6f 100644 --- a/Assets/ScriptableObjects/PromptList.asset +++ b/Assets/ScriptableObjects/PromptList.asset @@ -13,15 +13,6 @@ MonoBehaviour: m_Name: PromptList m_EditorClassIdentifier: prompts: - - k__BackingField: acb689ed-a57a-4463-bb6e-098b4896e930 - k__BackingField: mooi - k__BackingField: moi - - k__BackingField: 9cc1b2c7-3af0-475c-8d25-6f5913b19843 - k__BackingField: lui - k__BackingField: lui - - k__BackingField: 48017744-4552-487a-817a-abd5d03bbbc0 - k__BackingField: elle - k__BackingField: elle - k__BackingField: cef08696-352b-4003-85ff-2864996e9949 k__BackingField: Jacque chirac k__BackingField: Jacque chirac @@ -105,3 +96,72 @@ MonoBehaviour: - k__BackingField: 598d0c4f-da47-4182-946c-c4704f9c8f0b k__BackingField: La meilleure boisson k__BackingField: The best drink + - k__BackingField: 0e2b168f-eed0-42b3-9e38-3f6f8f2c211b + k__BackingField: Le film de votre vie + k__BackingField: The movie of your life + - k__BackingField: a30a6454-8bea-4229-845a-0ccef95bf25e + k__BackingField: Un jambon + k__BackingField: Ham + - k__BackingField: 5c684958-ae10-4976-bbc0-70d254c6435f + k__BackingField: Une main verte + k__BackingField: A green thumb + - k__BackingField: 8a952db4-c57b-45b8-a0ec-557674718e2a + k__BackingField: "Le jeu vid\xE9o le plus fou" + k__BackingField: The craziest video game + - k__BackingField: 7940c8df-2a56-4496-9efe-7989db697de9 + k__BackingField: Une autre personne que vous + k__BackingField: Someone other than you + - k__BackingField: 81d001fc-8994-481a-9947-db9308511525 + k__BackingField: Une personne importante de votre ville + k__BackingField: An important person in your city + - k__BackingField: 147c2764-a387-4d5a-949b-1c503f12dc6f + k__BackingField: Un paparazzi + k__BackingField: A paparazzi + - k__BackingField: 50631f22-4f9a-4b1a-92e7-b1b54f60e343 + k__BackingField: Un Nounours + k__BackingField: A Teddy + - k__BackingField: 7ca824e6-68ea-43aa-ab2d-7b7222d60f8d + k__BackingField: La couleur bleu + k__BackingField: The color blue + - k__BackingField: a42bdbb3-ebbe-471c-ae3f-b4e394d48fce + k__BackingField: "Un ch\xE2teau de papier WC" + k__BackingField: A toilet paper castle + - k__BackingField: fcd81532-591a-4f20-8afd-8baa9a626ef7 + k__BackingField: Un roi + k__BackingField: A king + - k__BackingField: a9f5ddb7-21d8-4d44-aa05-d747bb780cab + k__BackingField: Le nouveau Miyazaki + k__BackingField: The new Miyazaki + - k__BackingField: cc3900c7-e3a5-497c-a0a6-36c747c531eb + k__BackingField: Un objet artistique + k__BackingField: An artistic object + - k__BackingField: df0008cc-7e9d-49bd-84aa-902feaeb2122 + k__BackingField: "Une relique du pass\xE9" + k__BackingField: A relic of the past + - k__BackingField: be0aa5e4-5c23-4e7e-b076-0e65edb1db86 + k__BackingField: "\xC9voque le sport" + k__BackingField: Talk about sport + - k__BackingField: 42bdb0ce-d4cb-45a6-b622-7a6a01873332 + k__BackingField: MDR + k__BackingField: LOL + - k__BackingField: ee634bbd-983b-4963-a71f-1a3f3532b5db + k__BackingField: Un personnage Disney + k__BackingField: A Disney character + - k__BackingField: e4bbb02b-40f2-4670-8e9c-0d7e844f5fd4 + k__BackingField: "Le d\xE9but de la fin" + k__BackingField: The beginning of the end + - k__BackingField: 66c374cf-d23b-4398-9835-9acca24016f9 + k__BackingField: Le concept de l'amour + k__BackingField: The concept of love + - k__BackingField: 4ff9fb67-bce3-4e7e-be07-87fb27f3f6f2 + k__BackingField: "Une contrefa\xE7on" + k__BackingField: A counterfeit + - k__BackingField: 31a7f875-97ac-416c-956f-f0984cdc2701 + k__BackingField: Mario + k__BackingField: Mario + - k__BackingField: 9d00221b-7a14-47fe-b4dc-404984fee729 + k__BackingField: Naviguer sur internet + k__BackingField: Surf the Internet + - k__BackingField: 70f8b286-b245-45b9-a850-ac2e14bf9cef + k__BackingField: Votre plus belle grimace + k__BackingField: Your best grimace diff --git a/Assets/Scripts/CameraManager.cs b/Assets/Scripts/CameraManager.cs index ac1db37..7651941 100644 --- a/Assets/Scripts/CameraManager.cs +++ b/Assets/Scripts/CameraManager.cs @@ -8,11 +8,12 @@ public class CameraManager : MonoBehaviour public WebCamDevice wDevice; public Button freezeButton; public Button resumeButton; + private Texture2D photo; // Start is called before the first frame update void Start() { - wDevice = WebCamTexture.devices.First(x => x.isFrontFacing == false); + wDevice = WebCamTexture.devices.FirstOrDefault(x => x.isFrontFacing == false); wTexture = new WebCamTexture(wDevice.name); WebcamResume(); } @@ -20,16 +21,14 @@ void Start() // Update is called once per frame void Update() { - Texture2D cropped = CropTexture(wTexture); - Texture2D rotated = RotateTexture(cropped, !wDevice.isFrontFacing); - - gameObject.GetComponent().texture = rotated; - gameObject.GetComponent().material.mainTexture = rotated; + gameObject.GetComponent().texture = photo ? photo : GetPhoto(); + Resources.UnloadUnusedAssets(); } public void WebcamResume() { wTexture.Play(); + photo = null; freezeButton.gameObject.SetActive(true); resumeButton.gameObject.SetActive(false); } @@ -50,6 +49,7 @@ public void WebcamChange() public void WebcamStop() { + photo = GetPhoto(); wTexture.Stop(); freezeButton.gameObject.SetActive(false); resumeButton.gameObject.SetActive(true); @@ -76,7 +76,6 @@ Texture2D RotateTexture(Texture2D originalTexture, bool clockwise) Texture2D rotatedTexture = new(h, w); rotatedTexture.SetPixels32(rotated); - rotatedTexture.Apply(); return rotatedTexture; } @@ -100,8 +99,16 @@ Texture2D CropTexture(WebCamTexture originalTexture) Texture2D croppedTexture = new(size, size); croppedTexture.SetPixels(originalTexture.GetPixels(x, y, size, size)); - croppedTexture.Apply(); return croppedTexture; } + + Texture2D GetPhoto() + { + Texture2D cropped = CropTexture(wTexture); + Texture2D rotated = RotateTexture(cropped, !wDevice.isFrontFacing); + rotated.Apply(); + + return rotated; + } } diff --git a/Assets/Scripts/DatabaseClasses/Player.cs b/Assets/Scripts/DatabaseClasses/Player.cs index 853673c..d03d3a8 100644 --- a/Assets/Scripts/DatabaseClasses/Player.cs +++ b/Assets/Scripts/DatabaseClasses/Player.cs @@ -8,6 +8,12 @@ public class Player public string name; public string id; + public Player(string _name) + { + id = System.Guid.NewGuid().ToString(); + name = _name; + } + /// /// Will sanitize the text and set it for the player /// diff --git a/Assets/Scripts/GameManager.cs b/Assets/Scripts/GameManager.cs index 4970b4f..9ea9973 100644 --- a/Assets/Scripts/GameManager.cs +++ b/Assets/Scripts/GameManager.cs @@ -56,6 +56,7 @@ public class GameManager : MonoBehaviour private DatabaseReference realtimeDB; private Room myRoom; + private DatabaseReference myOnlineRoom; private void Awake() { @@ -88,8 +89,49 @@ private void Initialize() /// public void PlayerValidateNameAndServerRoom(string _name, string _code) { + if (string.IsNullOrEmpty(_name)) + { + Debug.LogError("Player name is empty", this); + //TODO : MARINE : use the error label to explain to the user that they have forget to put a name + return; + } + + if (string.IsNullOrEmpty(_code)) + { + Debug.LogError("Room code is empty", this); + //TODO : MARINE : use the error label to explain to the user that they have forget to put a room code + return; + } + //check if the room exists, if not display an error message - realtimeDB.Child("rooms").Child(_code).GetValueAsync().ContinueWithOnMainThread(task => + CheckIfRoomExists(_code, room => + { + if (room == null) + { + Debug.LogError("The room doesn't exists"); + roomError.text = "Error: the room doesn't exists"; + roomError.gameObject.SetActive(true); + } + else + { + //if room exists, join it + JoinRoom(() => + { + //then subscribe to it + myOnlineRoom = realtimeDB.Child("rooms").Child(_code); + myOnlineRoom.ChildChanged += OnRoomUpdate; + Debug.Log($"room {myRoom.code} exists, I subscribe to it"); + }); + } + }); + + + + } + + private void CheckIfRoomExists(string _roomCode, Action callback_Room) + { + realtimeDB.Child("rooms").Child(_roomCode).GetValueAsync().ContinueWithOnMainThread(task => { if (task.IsFaulted) { @@ -100,23 +142,38 @@ public void PlayerValidateNameAndServerRoom(string _name, string _code) DataSnapshot snapshot = task.Result; if (snapshot == null) { - Debug.LogError("The room doesn't exists"); - roomError.text = "Error: the room doesn't exists"; - roomError.gameObject.SetActive(true); + callback_Room?.Invoke(null); } else { - myRoom = JsonUtility.FromJson(snapshot.GetRawJsonValue()); - - currentPlayer.SetName(name); - currentPlayer.id = "1"; - realtimeDB.Child("rooms").Child(_code).ChildChanged += OnRoomUpdate; + callback_Room?.Invoke(JsonUtility.FromJson(snapshot.GetRawJsonValue())); } } }); + } - + /// + /// Add this player to the room + /// + private void JoinRoom(Action callback_OnRoomJoined) + { + //TODO marine : uncomment aftter merge + /* + string JSON = JsonUtility.ToJson(currentPlayer); + myOnlineRoom.Child("players").Child(currentPlayer.id).SetRawJsonValueAsync(JSON).ContinueWithOnMainThread(task => + { + if (task.IsFaulted) + { + Debug.LogException(task.Exception); + } + else + { + Debug.Log($"{currentPlayer.name} has been added to the room", this); + callback_OnRoomJoined?.Invoke(); + } + }); + */ } /// @@ -142,7 +199,7 @@ public void MakeAProposition(Prompt _prompt) { currentState = GameState.MakeProposition; - + } /// diff --git a/Packages/manifest.json b/Packages/manifest.json index e2a4c60..91b486a 100644 --- a/Packages/manifest.json +++ b/Packages/manifest.json @@ -2,6 +2,7 @@ "dependencies": { "com.unity.collab-proxy": "2.2.0", "com.unity.feature.development": "1.0.1", + "com.unity.memoryprofiler": "1.1.0", "com.unity.textmeshpro": "3.0.6", "com.unity.timeline": "1.7.6", "com.unity.toolchain.linux-x86_64": "2.0.6", diff --git a/Packages/packages-lock.json b/Packages/packages-lock.json index 5fbe1a9..4ce32a3 100644 --- a/Packages/packages-lock.json +++ b/Packages/packages-lock.json @@ -60,6 +60,15 @@ "dependencies": {}, "url": "https://packages.unity.com" }, + "com.unity.memoryprofiler": { + "version": "1.1.0", + "depth": 0, + "source": "registry", + "dependencies": { + "com.unity.editorcoroutines": "1.0.0" + }, + "url": "https://packages.unity.com" + }, "com.unity.performance.profile-analyzer": { "version": "1.2.2", "depth": 1,