From a9fd87527e250d17b3ccab3dccc54a9f4e3d9518 Mon Sep 17 00:00:00 2001 From: Michel Roux Date: Sun, 28 Jan 2024 02:26:57 +0100 Subject: [PATCH 1/9] feat: add GetPropositionsByPlayer --- Assets/Scripts/DatabaseClasses/Room.cs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/Assets/Scripts/DatabaseClasses/Room.cs b/Assets/Scripts/DatabaseClasses/Room.cs index c9f9830..acf0a27 100644 --- a/Assets/Scripts/DatabaseClasses/Room.cs +++ b/Assets/Scripts/DatabaseClasses/Room.cs @@ -33,6 +33,25 @@ public List GetQuestionList() return new List(questions.Values); } + public List GetPropositionsByPlayer(Player player) + { + List propositions = new(); + + foreach (Question question in GetQuestionList()) + { + foreach (Proposition proposition in new List(question.propositions.Values)) + { + if (proposition.owner.id == player.id) + { + propositions.Add(proposition); + break; + } + } + } + + return propositions; + } + public void setPlayersAreReady(int _state) { currentState = _state; From 608926e0f5ffa5ba6359f2c3fc052cab1fa84976 Mon Sep 17 00:00:00 2001 From: Michel Roux Date: Sun, 28 Jan 2024 02:40:12 +0100 Subject: [PATCH 2/9] feat: starting to work on upload file --- Assets/Scenes/PhoneView.unity | 24 +++++++-- Assets/Scripts/DatabaseClasses/Room.cs | 21 +++++++- Assets/Scripts/GameManager.cs | 15 +++--- Assets/Scripts/QuestionHandler.cs | 74 ++++++++++++++++++++++++++ Assets/Scripts/QuestionHandler.cs.meta | 11 ++++ Assets/Scripts/StorageManager.cs | 2 +- 6 files changed, 132 insertions(+), 15 deletions(-) create mode 100644 Assets/Scripts/QuestionHandler.cs create mode 100644 Assets/Scripts/QuestionHandler.cs.meta diff --git a/Assets/Scenes/PhoneView.unity b/Assets/Scenes/PhoneView.unity index d10c2e9..114fb49 100644 --- a/Assets/Scenes/PhoneView.unity +++ b/Assets/Scenes/PhoneView.unity @@ -3385,13 +3385,14 @@ GameObject: m_Component: - component: {fileID: 1181392806} - component: {fileID: 1181392807} + - component: {fileID: 1181392808} m_Layer: 5 m_Name: TakePictureState m_TagString: Untagged m_Icon: {fileID: 0} m_NavMeshLayer: 0 m_StaticEditorFlags: 0 - m_IsActive: 1 + m_IsActive: 0 --- !u!224 &1181392806 RectTransform: m_ObjectHideFlags: 0 @@ -3434,6 +3435,21 @@ MonoBehaviour: freezeButton: {fileID: 223773138} resumeButton: {fileID: 1114535086} photoBox: {fileID: 1316036600} +--- !u!114 &1181392808 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1181392805} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 02a8e72b27188ad7f8079b04e756e652, type: 3} + m_Name: + m_EditorClassIdentifier: + managers: {fileID: 429358648} + explainText: {fileID: 2139867527} + promptList: {fileID: 11400000, guid: 21907abc84e40403ca34c4fb9ab30b06, type: 2} --- !u!1 &1202782726 GameObject: m_ObjectHideFlags: 0 @@ -6279,9 +6295,9 @@ MonoBehaviour: m_OnClick: m_PersistentCalls: m_Calls: - - m_Target: {fileID: 429358652} - m_TargetAssemblyTypeName: StorageManager, Assembly-CSharp - m_MethodName: UploadPhoto + - m_Target: {fileID: 1181392808} + m_TargetAssemblyTypeName: QuestionHandler, Assembly-CSharp + m_MethodName: OnSubmitButton m_Mode: 1 m_Arguments: m_ObjectArgument: {fileID: 0} diff --git a/Assets/Scripts/DatabaseClasses/Room.cs b/Assets/Scripts/DatabaseClasses/Room.cs index acf0a27..cdccfa9 100644 --- a/Assets/Scripts/DatabaseClasses/Room.cs +++ b/Assets/Scripts/DatabaseClasses/Room.cs @@ -33,6 +33,25 @@ public List GetQuestionList() return new List(questions.Values); } + public List GetQuestionsByPlayer(Player player) + { + List questions = new(); + + foreach (Question question in GetQuestionList()) + { + foreach (Proposition proposition in new List(question.propositions.Values)) + { + if (proposition.owner.id == player.id) + { + questions.Add(question); + break; + } + } + } + + return questions; + } + public List GetPropositionsByPlayer(Player player) { List propositions = new(); @@ -52,7 +71,7 @@ public List GetPropositionsByPlayer(Player player) return propositions; } - public void setPlayersAreReady(int _state) + public void SetPlayersAreReady(int _state) { currentState = _state; } diff --git a/Assets/Scripts/GameManager.cs b/Assets/Scripts/GameManager.cs index d1a9992..766e827 100644 --- a/Assets/Scripts/GameManager.cs +++ b/Assets/Scripts/GameManager.cs @@ -6,7 +6,6 @@ using Newtonsoft.Json; using TMPro; using UnityEngine; -using static UnityEditor.Experimental.AssetDatabaseExperimental.AssetDatabaseCounters; /// /// This is the game state manager on the phone side @@ -74,7 +73,7 @@ private void OnApplicationQuit() private void Update() { - if (myRoom.currentState == (int)GameState.Explanation && endOfExplanationDate != DateTime.MinValue ) + if (myRoom.currentState == (int)GameState.Explanation && endOfExplanationDate != DateTime.MinValue) { TimeSpan duration = endOfExplanationDate - DateTime.Now; counter.text = ((int)duration.TotalSeconds).ToString("D1"); @@ -217,12 +216,12 @@ private void JoinRoom(Action callback_OnRoomJoined) public void StartGame() { // send Start Game - myRoom.setPlayersAreReady(1); + myRoom.SetPlayersAreReady(1); string JSON = JsonUtility.ToJson(myRoom); Debug.Log(JSON); try { - sendCurrentState(GameState.Explanation, () => + SendCurrentState(GameState.Explanation, () => { Debug.Log($"start the game", this); myRoom.currentState = (int)GameState.Explanation; @@ -235,8 +234,6 @@ public void StartGame() { Debug.LogException(ex); } - - } /// @@ -290,10 +287,10 @@ private void OnRoomUpdate(object sender, ValueChangedEventArgs e) { try { - if (e!= null) + if (e != null) { myRoom = JsonConvert.DeserializeObject(e.Snapshot.GetRawJsonValue()); - + } } catch (Exception ex) @@ -362,7 +359,7 @@ private void CheckIfIAmTheFirst(List players) submitStartGame.SetActive(true); } } - public void sendCurrentState(GameState state, Action callback_oncCurrentStateSent) + public void SendCurrentState(GameState state, Action callback_oncCurrentStateSent) { myOnlineRoom.Child("currentState").SetValueAsync((int)state).ContinueWithOnMainThread(task => { diff --git a/Assets/Scripts/QuestionHandler.cs b/Assets/Scripts/QuestionHandler.cs new file mode 100644 index 0000000..c313cc2 --- /dev/null +++ b/Assets/Scripts/QuestionHandler.cs @@ -0,0 +1,74 @@ +using System.Collections.Generic; +using System.Linq; +using TMPro; +using UnityEngine; + +public class QuestionHandler : MonoBehaviour +{ + public GameObject managers; + private GameManager gameManager; + public TextMeshProUGUI explainText; + public PromptList promptList; + private List player2questions; + private int currentQuestion = 0; + + void OnEnable() + { + player2questions = gameManager.myRoom.GetQuestionsByPlayer(gameManager.currentPlayer); + Redraw(++currentQuestion); + } + + void OnDisable() + { + player2questions = null; + } + + void Redraw(int currentQuestion) + { + Prompt prompt = promptList.prompts.Find(x => x.id == player2questions[currentQuestion - 1].promptId); + explainText.SetText(prompt.en); + + CameraManager cameraManager = gameObject.GetComponent(); + cameraManager.WebcamResume(); + } + + string GetQuestionRef(string promptId) + { + return gameManager.myRoom.questions.First(x => x.Value.promptId == promptId).Key; + } + + string GetPropRef(string questionRef, string playerId) + { + return gameManager.myRoom.questions[questionRef].propositions.First(x => x.Value.owner.id == playerId).Key; + } + + public void OnSubmitButton() + { + string questionRef = GetQuestionRef(player2questions[currentQuestion - 1].promptId); + + StorageManager storageManager = managers.GetComponent(); + storageManager.UploadPhoto( + gameManager.myRoom.code, + gameManager.currentPlayer.id, + GetQuestionRef(questionRef), + GetPropRef(questionRef, gameManager.currentPlayer.id)); + + if (currentQuestion < 2) { + Redraw(++currentQuestion); + } else { + gameManager.myRoom.currentState = (int) GameState.PropositionsSent; + } + } + + // Start is called before the first frame update + void Start() + { + + } + + // Update is called once per frame + void Update() + { + + } +} diff --git a/Assets/Scripts/QuestionHandler.cs.meta b/Assets/Scripts/QuestionHandler.cs.meta new file mode 100644 index 0000000..dc2795a --- /dev/null +++ b/Assets/Scripts/QuestionHandler.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 02a8e72b27188ad7f8079b04e756e652 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/StorageManager.cs b/Assets/Scripts/StorageManager.cs index cf1f906..c8921a5 100644 --- a/Assets/Scripts/StorageManager.cs +++ b/Assets/Scripts/StorageManager.cs @@ -33,7 +33,7 @@ void Update() } - public void UploadPhoto() + public void UploadPhoto(string roomCode, string playerId, string questionRef, string propRef) { Texture2D photo = gameObject.GetComponent().GetPhoto(); byte[] photoBytes = ImageConversion.EncodeToJPG(photo); From a19f158828b4b14ad95d2fffc2af284570a6dbc4 Mon Sep 17 00:00:00 2001 From: Morgan - 6 Freedom Date: Sun, 28 Jan 2024 02:40:38 +0100 Subject: [PATCH 3/9] feat: room has now a function to list player and get propositions --- Assets/Scripts/DatabaseClasses/Room.cs | 29 ++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/Assets/Scripts/DatabaseClasses/Room.cs b/Assets/Scripts/DatabaseClasses/Room.cs index c9f9830..a4c66ce 100644 --- a/Assets/Scripts/DatabaseClasses/Room.cs +++ b/Assets/Scripts/DatabaseClasses/Room.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Linq; using Newtonsoft.Json; [Serializable] @@ -28,6 +29,15 @@ public List GetPlayerList() return new List(players.Values); } + /// + /// return the list of player ordered by who joined first + /// + /// + public List GetOrderedPlayerList() + { + return players.Values.OrderBy(x => x.creationDate).ToList(); + } + public List GetQuestionList() { return new List(questions.Values); @@ -37,5 +47,24 @@ public void setPlayersAreReady(int _state) { currentState = _state; } + + public List GetPropositionsByPlayer(Player player) + { + List propositions = new(); + + foreach (Question question in GetQuestionList()) + { + foreach (Proposition proposition in new List(question.propositions.Values)) + { + if (proposition.owner.id == player.id) + { + propositions.Add(proposition); + break; + } + } + } + + return propositions; + } } From 09f06fb7157598e2d44ec8ca74676df87796770c Mon Sep 17 00:00:00 2001 From: Morgan - 6 Freedom Date: Sun, 28 Jan 2024 02:41:16 +0100 Subject: [PATCH 4/9] feat: waiting for all propositions on PC & add some SFX --- .../Audio SFX/camera-flash-sound-effect.mp3 | 3 + .../camera-flash-sound-effect.mp3.meta | 23 +++ Assets/Scripts/RoomManager.cs | 153 ++++++++++++------ 3 files changed, 127 insertions(+), 52 deletions(-) create mode 100644 Assets/Audio SFX/camera-flash-sound-effect.mp3 create mode 100644 Assets/Audio SFX/camera-flash-sound-effect.mp3.meta diff --git a/Assets/Audio SFX/camera-flash-sound-effect.mp3 b/Assets/Audio SFX/camera-flash-sound-effect.mp3 new file mode 100644 index 0000000..5f0933e --- /dev/null +++ b/Assets/Audio SFX/camera-flash-sound-effect.mp3 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:58f18e86e44bfeff7f980abbb29e1050edc4b66f0c3dbda376b224b772ff0b20 +size 33364 diff --git a/Assets/Audio SFX/camera-flash-sound-effect.mp3.meta b/Assets/Audio SFX/camera-flash-sound-effect.mp3.meta new file mode 100644 index 0000000..d4da1a3 --- /dev/null +++ b/Assets/Audio SFX/camera-flash-sound-effect.mp3.meta @@ -0,0 +1,23 @@ +fileFormatVersion: 2 +guid: b4d0bdddc893f476a8eb330e58108608 +AudioImporter: + externalObjects: {} + serializedVersion: 7 + defaultSettings: + serializedVersion: 2 + loadType: 0 + sampleRateSetting: 0 + sampleRateOverride: 44100 + compressionFormat: 1 + quality: 1 + conversionMode: 0 + preloadAudioData: 0 + platformSettingOverrides: {} + forceToMono: 0 + normalize: 1 + loadInBackground: 0 + ambisonic: 0 + 3D: 1 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/RoomManager.cs b/Assets/Scripts/RoomManager.cs index 7ff3c24..164e17f 100644 --- a/Assets/Scripts/RoomManager.cs +++ b/Assets/Scripts/RoomManager.cs @@ -15,9 +15,8 @@ public class RoomManager : MonoBehaviour /// TextMeshPro that show the value of the current rooom code /// public TextMeshProUGUI roomCodeLabel; + public AudioClip playerJoinSFX; public List waitingForPlayersLabels = new List(); - private Dictionary waitingPlayersById = new Dictionary(); - public PromptList promptList; [Header("Explanation Page")] public GameObject explanationPage; @@ -31,10 +30,13 @@ public class RoomManager : MonoBehaviour public TextMeshProUGUI propositionCounter; public float propositionTime = 60; public List waitingForPropositionsLabels = new List(); + private Dictionary propositionLabelsByID = new Dictionary(); private DateTime endOfPropositionDate = DateTime.MinValue; private bool allPlayersHasProposedTwoPictures = false; + private Dictionary propositionsPerPlayers = new Dictionary(); [Header("Other")] + public PromptList promptList; private Room myRoom = null; public float votingTime = 20; @@ -94,13 +96,34 @@ private void Update() TimeSpan duration = endOfPropositionDate - DateTime.Now; propositionCounter.text = ((int)duration.TotalSeconds).ToString("D1"); - foreach (TextMeshProUGUI tmp in waitingForPropositionsLabels) + //foreach labels + foreach (var labelByID in propositionLabelsByID) { - if (tmp.gameObject.activeSelf) + //if the label is connected to a player + if (labelByID.Value.gameObject.activeSelf) { - + //check if this player has send 2 propositions + bool playerHasAnswerBoth = true; + foreach (Proposition p in propositionsPerPlayers[labelByID.Key]) + { + if (string.IsNullOrEmpty(p.photoUrl)) + { + playerHasAnswerBoth = false; + } + } + //if its the case + if (playerHasAnswerBoth) + { + //put player label in green if finished + labelByID.Value.color = Color.green; + } } } + + if (allPlayersHasProposedTwoPictures || duration.TotalMilliseconds <= 0) + { + SendRoomState(GameState.MakeVote); + } } } @@ -111,7 +134,6 @@ private void SendRoomState(GameState _newState) private void ResetAllPlayerLabels() { - waitingPlayersById.Clear(); for (int i = 0; i < waitingForPlayersLabels.Count; i++) { waitingForPlayersLabels[i].text = $"Waiting for P{i + 1}"; @@ -226,11 +248,6 @@ private int GenerateRandomAvailableCode(List _impossibleCodes) return random; } - public void PlayerSendProposition(Proposition _proposition) - { - - } - /// /// Called when the first player clicked "Start" /// @@ -240,53 +257,30 @@ public void HostHasStartedGame() waitingForPlayersPage.SetActive(false); endOfPropositionDate = DateTime.Now.AddSeconds(propositionTime); + propositionLabelsByID.Clear(); + + //display only correct numbers of labels for (int i = 0; i < waitingForPropositionsLabels.Count; i++) { TextMeshProUGUI tmp = waitingForPropositionsLabels[i]; tmp.gameObject.SetActive(i < myRoom.players.Count); } - } + //registers the labels per player ID + List orderedPlayers = myRoom.GetPlayerList().OrderBy(x => x.creationDate).ToList(); + for (int i = 0; i < orderedPlayers.Count; i++) + { + propositionLabelsByID.Add(orderedPlayers[i].id, waitingForPropositionsLabels[i]); + waitingForPlayersLabels[i].text = orderedPlayers[i].name; + } - /// - /// Start the proposition timer - /// - public void StartPropositionTimer() - { + //Register all propositions of each players + foreach (Player p in myRoom.GetOrderedPlayerList()) + { + List propositionsForPlayer = myRoom.GetPropositionsByPlayer(p); + propositionsPerPlayers.Add(p.id, propositionsForPlayer.ToArray()); + } - } - - - /// - /// Automatically called when the proposition timer has finished - /// - public void PropositionTimerFinished() - { - - } - - /// - /// Start the voting timer - /// - public void StartVotingTimer() - { - - } - - - /// - /// Automatically called when the voting timer has finished - /// - public void VotingTimerFinished() - { - - } - - /// - /// Automatically called when a proposition is updated (someone has voted or a picture has been proposed) - /// - public void OnPropositionUpdate() - { } @@ -347,8 +341,14 @@ private void OnRoomUpdate(object sender, ValueChangedEventArgs value) Debug.LogError(value.DatabaseError.Message); return; } + if (value.Snapshot.Value == null) + { + Debug.Log("Trying to update room, but it's empty. Maybe you are exiting the app, so it's ok", this); + return; + } string JSON = value.Snapshot.GetRawJsonValue(); Debug.Log($"your room has been updated :\n{JSON}"); + GameState lastState = (GameState)myRoom.currentState; try { myRoom = JsonConvert.DeserializeObject(JSON); @@ -358,19 +358,50 @@ private void OnRoomUpdate(object sender, ValueChangedEventArgs value) Debug.LogException(ex); } + //this is done only when entering a new state + if (lastState != (GameState)myRoom.currentState) + { + OnNewGameStateStarted(); + } + else + { + //this is done each time something change + switch (myRoom.currentState) + { + case (int)GameState.WaitingForOtherPlayersToJoin: + UpdateConnectedPlayerList(myRoom.GetPlayerList()); + break; + case (int)GameState.Explanation: + break; + case (int)GameState.MakeProposition: + CheckPlayersPropositions(); + break; + default: + break; + } + } + } + + /// + /// Called when we enter in a new game state + /// + private void OnNewGameStateStarted() + { switch (myRoom.currentState) { case (int)GameState.WaitingForOtherPlayersToJoin: - UpdateConnectedPlayerList(myRoom.GetPlayerList()); + Debug.Log("New State : WaitingForOtherPlayersToJoin"); break; case (int)GameState.Explanation: + Debug.Log("New State : Explanation"); waitingForPlayersPage.SetActive(false); explanationPage.SetActive(true); endOfExplanationDate = DateTime.Now.AddSeconds(explanationTime); AudioSource.PlayClipAtPoint(counterSFX, Vector3.zero); break; case (int)GameState.MakeProposition: + Debug.Log("New State : MakeProposition"); HostHasStartedGame(); break; default: @@ -378,19 +409,37 @@ private void OnRoomUpdate(object sender, ValueChangedEventArgs value) } } + /// + /// Will update allPlayersHasProposedTwoPictures to true or false + /// + private void CheckPlayersPropositions() + { + allPlayersHasProposedTwoPictures = true; + + foreach (var propositionsByPlayer in propositionsPerPlayers) + { + foreach (Proposition p in propositionsByPlayer.Value) + { + if (string.IsNullOrEmpty(p.photoUrl)) + allPlayersHasProposedTwoPictures = false; + } + } + } + + /// /// Update the player labels on the WaitingForPlayer page /// /// private void UpdateConnectedPlayerList(List _players) { + AudioSource.PlayClipAtPoint(playerJoinSFX, Vector3.zero); ResetAllPlayerLabels(); Debug.Log($"players count = {_players.Count}"); List orderedPlayers = _players.OrderBy(x => x.creationDate).ToList(); for (int i = 0; i < orderedPlayers.Count; i++) { - waitingPlayersById.Add(orderedPlayers[i].id, waitingForPlayersLabels[i]); Debug.Log($"player {i} = {orderedPlayers[i].name}"); waitingForPlayersLabels[i].text = orderedPlayers[i].name; } From 388048553d86f06932b08f310cbdf921e1a350ea Mon Sep 17 00:00:00 2001 From: Morgan - 6 Freedom Date: Sun, 28 Jan 2024 02:42:03 +0100 Subject: [PATCH 5/9] fix: updateRoom --- Assets/Scripts/DatabaseClasses/Room.cs | 18 ------------------ 1 file changed, 18 deletions(-) diff --git a/Assets/Scripts/DatabaseClasses/Room.cs b/Assets/Scripts/DatabaseClasses/Room.cs index d8c782a..772cab7 100644 --- a/Assets/Scripts/DatabaseClasses/Room.cs +++ b/Assets/Scripts/DatabaseClasses/Room.cs @@ -62,24 +62,6 @@ public List GetQuestionsByPlayer(Player player) return questions; } - public List GetPropositionsByPlayer(Player player) - { - List propositions = new(); - - foreach (Question question in GetQuestionList()) - { - foreach (Proposition proposition in new List(question.propositions.Values)) - { - if (proposition.owner.id == player.id) - { - propositions.Add(proposition); - break; - } - } - } - - return propositions; - } public void SetPlayersAreReady(int _state) { From c0d6aaef98355a753e490ff73167e403d679c888 Mon Sep 17 00:00:00 2001 From: Morgan - 6 Freedom Date: Sun, 28 Jan 2024 02:42:31 +0100 Subject: [PATCH 6/9] fix: missing scene --- Assets/Scenes/ComputerView.unity | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Assets/Scenes/ComputerView.unity b/Assets/Scenes/ComputerView.unity index 561ceb2..7b35f82 100644 --- a/Assets/Scenes/ComputerView.unity +++ b/Assets/Scenes/ComputerView.unity @@ -1369,6 +1369,7 @@ MonoBehaviour: m_EditorClassIdentifier: waitingForPlayersPage: {fileID: 1117928114} roomCodeLabel: {fileID: 1805240027} + playerJoinSFX: {fileID: 8300000, guid: b4d0bdddc893f476a8eb330e58108608, type: 3} waitingForPlayersLabels: - {fileID: 1794849355} - {fileID: 1452182577} @@ -1378,7 +1379,6 @@ MonoBehaviour: - {fileID: 496953434} - {fileID: 2137991537} - {fileID: 340074661} - promptList: {fileID: 0} explanationPage: {fileID: 45150984} explanationCounter: {fileID: 1798182259} explanationTime: 4 @@ -1395,6 +1395,7 @@ MonoBehaviour: - {fileID: 1854893636} - {fileID: 2065109614} - {fileID: 1197279072} + promptList: {fileID: 0} votingTime: 20 --- !u!114 &375256413 MonoBehaviour: From e43ecb338f704bc21a4004a07a902a04ece71d93 Mon Sep 17 00:00:00 2001 From: Michel Roux Date: Sun, 28 Jan 2024 02:48:34 +0100 Subject: [PATCH 7/9] fix: camera issue when no camera --- Assets/Scripts/CameraManager.cs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/Assets/Scripts/CameraManager.cs b/Assets/Scripts/CameraManager.cs index 32f4568..0504a68 100644 --- a/Assets/Scripts/CameraManager.cs +++ b/Assets/Scripts/CameraManager.cs @@ -31,11 +31,14 @@ void Start() // Update is called once per frame void Update() { - if (wTexture) + Texture2D texture = GetPhoto(); + + if (texture) { - photoBox.texture = GetPhoto(); - Resources.UnloadUnusedAssets(); + photoBox.texture = texture; } + + Resources.UnloadUnusedAssets(); } public void WebcamResume() @@ -123,7 +126,7 @@ public Texture2D GetPhoto() return photo; } - if (!wTexture) + if (!wTexture || WebCamTexture.devices.Count() < 1) { return null; } From fc103f8fab059075741d90c7808f6b65bea24ab6 Mon Sep 17 00:00:00 2001 From: Marine Date: Sun, 28 Jan 2024 02:52:40 +0100 Subject: [PATCH 8/9] EndSamePlayer new players --- Assets/Scripts/GameManager.cs | 54 +++++++++++++++++++++++++++++++++-- 1 file changed, 52 insertions(+), 2 deletions(-) diff --git a/Assets/Scripts/GameManager.cs b/Assets/Scripts/GameManager.cs index a291b06..6a5a68c 100644 --- a/Assets/Scripts/GameManager.cs +++ b/Assets/Scripts/GameManager.cs @@ -312,14 +312,31 @@ private void OnRoomUpdate(object sender, ValueChangedEventArgs e) } switch (myRoom.currentState) { + case (int)GameState.EnteringName: + { + if (EndGame.activeInHierarchy) + { + EndGame.SetActive(false); + HomeConnection.SetActive(true); + } + + break; + } case (int)GameState.WaitingForOtherPlayersToJoin: { - CheckIfIAmTheFirst(myRoom.GetPlayerList()); - UpdateDisplayedListUser(myRoom.GetPlayerList()); + if (!HomeConnection.activeInHierarchy) + { + CheckIfIAmTheFirst(myRoom.GetPlayerList()); + UpdateDisplayedListUser(myRoom.GetPlayerList()); + } break; } case (int)GameState.Explanation: { + if (EndGame.activeInHierarchy) + { + EndGame.SetActive(false); + } WaitingRoom.SetActive(false); BeforeStart.SetActive(true); endOfExplanationDate = DateTime.Now.AddSeconds(3); @@ -390,6 +407,39 @@ public void OnClickSubmitSignIn() string roomCode = roomCodeField.text; PlayerValidateNameAndServerRoom(playerName, roomCode); } + + public void onClickSamePlayers() + { + myRoom.currentState = (int)GameState.Explanation; + myRoom.currentQuestion = 2; + myRoom.questions = null; + string json = JsonUtility.ToJson(myRoom); + + myOnlineRoom.SetRawJsonValueAsync(json).ContinueWithOnMainThread(task => + { + if (task.IsFaulted) + { + Debug.LogException(task.Exception); + } + }); + + } + public void onClickNewPlayers() + { + myRoom.currentState = (int)GameState.EnteringName; + myRoom.currentQuestion = 0; + myRoom.questions = null; + myRoom.players = null; + string json = JsonUtility.ToJson(myRoom); + + myOnlineRoom.SetRawJsonValueAsync(json).ContinueWithOnMainThread(task => + { + if (task.IsFaulted) + { + Debug.LogException(task.Exception); + } + }); + } } public enum GameState From 4b86bf43b5a39855248d4081eb54e6fbe727b514 Mon Sep 17 00:00:00 2001 From: Michel Roux Date: Sun, 28 Jan 2024 02:53:11 +0100 Subject: [PATCH 9/9] fix: Forgot to initialize gamemanager --- Assets/Scripts/QuestionHandler.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Assets/Scripts/QuestionHandler.cs b/Assets/Scripts/QuestionHandler.cs index c313cc2..bd9edc5 100644 --- a/Assets/Scripts/QuestionHandler.cs +++ b/Assets/Scripts/QuestionHandler.cs @@ -63,7 +63,7 @@ public void OnSubmitButton() // Start is called before the first frame update void Start() { - + gameManager = managers.GetComponent(); } // Update is called once per frame