From 8519964e0623b92e373cf5fd06f9ce2df9737249 Mon Sep 17 00:00:00 2001 From: Marine Date: Sat, 27 Jan 2024 23:50:57 +0100 Subject: [PATCH 1/4] update current state + sendExplanation --- Assets/Scripts/GameManager.cs | 86 +++++++++++++++++++++++------------ 1 file changed, 58 insertions(+), 28 deletions(-) diff --git a/Assets/Scripts/GameManager.cs b/Assets/Scripts/GameManager.cs index b711e5a..814a219 100644 --- a/Assets/Scripts/GameManager.cs +++ b/Assets/Scripts/GameManager.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Linq; using Firebase.Database; using Firebase.Extensions; using Newtonsoft.Json; @@ -11,9 +12,7 @@ /// public class GameManager : MonoBehaviour { - private GameState currentState; private List players = new(); - private bool isFirst = false; public Player currentPlayer = null; public Question currentQuestion = null; @@ -58,15 +57,13 @@ private void Start() } private void OnApplicationQuit() { - myOnlineRoom.Child("players").Child(currentPlayer.id).RemoveValueAsync(); - Debug.Log($"delete player {currentPlayer.name}"); - myRoom = null; + myOnlineRoom.Child("players").Child(currentPlayer.id).RemoveValueAsync().ContinueWithOnMainThread(task => + { + Debug.Log($"delete player {currentPlayer.name}"); + myOnlineRoom.ValueChanged -= OnRoomUpdate; + }); } - public GameState GetCurrentState() - { - return currentState; - } private void Initialize() { @@ -125,7 +122,7 @@ public void PlayerValidateNameAndServerRoom(string _name, string _code) { //then subscribe to it myOnlineRoom.ValueChanged += OnRoomUpdate; - currentState = GameState.WaitingForOtherPlayersToJoin; + myRoom.currentState = (int)GameState.WaitingForOtherPlayersToJoin; players.Add(currentPlayer); WaitingRoom.SetActive(true); @@ -203,19 +200,13 @@ public void StartGame() Debug.Log(JSON); try { - myOnlineRoom.Child("currentState").SetValueAsync(2).ContinueWithOnMainThread(task => + sendCurrentState(GameState.Explanation, () => { - if (task.IsFaulted) - { - Debug.LogException(task.Exception); - } - else - { - Debug.Log($"start the game", this); - currentState = GameState.Explanation; - WaitingRoom.SetActive(false); - BeforeStart.SetActive(true); - } + Debug.Log($"start the game", this); + myRoom.currentState = (int)GameState.Explanation; + WaitingRoom.SetActive(false); + BeforeStart.SetActive(true); + }); } catch (Exception ex) @@ -233,7 +224,7 @@ public void StartGame() /// The prompt to display public void MakeAProposition(Prompt _prompt) { - currentState = GameState.MakeProposition; + //currentState = GameState.MakeProposition; } /// @@ -283,13 +274,30 @@ private void OnRoomUpdate(object sender, ValueChangedEventArgs e) { Debug.LogException(ex); } - - switch (currentState) + if(myRoom == null) { + return; + } + switch (myRoom.currentState) { - case GameState.WaitingForOtherPlayersToJoin: + case (int)GameState.WaitingForOtherPlayersToJoin: { CheckIfIAmTheFirst(myRoom.GetPlayerList()); UpdateDisplayedListUser(myRoom.GetPlayerList()); + break; + } + case (int)GameState.Explanation: + { + + break; + } + case (int)GameState.MakeProposition: + { + if (BeforeStart.activeInHierarchy) + { + BeforeStart.SetActive(false); + TakePicture.SetActive(true); + } + break; } } @@ -307,16 +315,38 @@ private void UpdateDisplayedListUser(List players) private void CheckIfIAmTheFirst(List players) { + bool isFirst = false; if (players.Count > 1) { + IOrderedEnumerable sortedList = players.OrderBy(x=>x.creationDate); + + if(sortedList.Last().id == currentPlayer.id) + { + isFirst = true; + } } - else + + if (isFirst) { - + submitStartGame.SetActive(true); } } + public void sendCurrentState(GameState state,Action callback_oncCurrentStateSent) + { + myOnlineRoom.Child("currentState").SetValueAsync((int)state).ContinueWithOnMainThread(task => + { + if (task.IsFaulted) + { + Debug.LogException(task.Exception); + } + else + { + callback_oncCurrentStateSent?.Invoke(); + } + }); ; + } public void OnClickSubmitSignIn() { From ad324a1ed4f83a93f54fa5878c7bfd2e1b894cb0 Mon Sep 17 00:00:00 2001 From: Otaku9999 Date: Sun, 28 Jan 2024 00:03:13 +0100 Subject: [PATCH 2/4] End music --- Assets/Music.meta | 8 ++++++++ Assets/Music/Ending.mp3 | 3 +++ Assets/Music/Ending.mp3.meta | 23 +++++++++++++++++++++++ Assets/Music/Menu.mp3 | 3 +++ Assets/Music/Menu.mp3.meta | 23 +++++++++++++++++++++++ Assets/Music/Taking picture.mp3 | 3 +++ Assets/Music/Taking picture.mp3.meta | 23 +++++++++++++++++++++++ 7 files changed, 86 insertions(+) create mode 100644 Assets/Music.meta create mode 100644 Assets/Music/Ending.mp3 create mode 100644 Assets/Music/Ending.mp3.meta create mode 100644 Assets/Music/Menu.mp3 create mode 100644 Assets/Music/Menu.mp3.meta create mode 100644 Assets/Music/Taking picture.mp3 create mode 100644 Assets/Music/Taking picture.mp3.meta diff --git a/Assets/Music.meta b/Assets/Music.meta new file mode 100644 index 0000000..a6bc371 --- /dev/null +++ b/Assets/Music.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 23eaa774a3a7d434183a4c336d52891f +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Music/Ending.mp3 b/Assets/Music/Ending.mp3 new file mode 100644 index 0000000..7a2f9a5 --- /dev/null +++ b/Assets/Music/Ending.mp3 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:71a004520c6ebb46f1966c6d35d4bb25853e303a88c111315010fb35b6ad2953 +size 7008143 diff --git a/Assets/Music/Ending.mp3.meta b/Assets/Music/Ending.mp3.meta new file mode 100644 index 0000000..ae2380c --- /dev/null +++ b/Assets/Music/Ending.mp3.meta @@ -0,0 +1,23 @@ +fileFormatVersion: 2 +guid: e1135788bf319bd42b6ca512976f9028 +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/Music/Menu.mp3 b/Assets/Music/Menu.mp3 new file mode 100644 index 0000000..74c2184 --- /dev/null +++ b/Assets/Music/Menu.mp3 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:d4fdb901d2d6e7627073d7645dd97658b0e819afac9fbb01f8de09e8591fce4c +size 5630543 diff --git a/Assets/Music/Menu.mp3.meta b/Assets/Music/Menu.mp3.meta new file mode 100644 index 0000000..f8d41cc --- /dev/null +++ b/Assets/Music/Menu.mp3.meta @@ -0,0 +1,23 @@ +fileFormatVersion: 2 +guid: 7ac3efdb5c840704aafbf19188b3e61e +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/Music/Taking picture.mp3 b/Assets/Music/Taking picture.mp3 new file mode 100644 index 0000000..602e992 --- /dev/null +++ b/Assets/Music/Taking picture.mp3 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:ee4f9285dac6a7b0925aed9cbb8314b44d4a996fa255a5100f138df2db0f97ed +size 2427023 diff --git a/Assets/Music/Taking picture.mp3.meta b/Assets/Music/Taking picture.mp3.meta new file mode 100644 index 0000000..6a4e838 --- /dev/null +++ b/Assets/Music/Taking picture.mp3.meta @@ -0,0 +1,23 @@ +fileFormatVersion: 2 +guid: 0e86c0433979a2d4c884b368808d3cdf +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: From 8c5e7767d0b4d5dd7e9d14b7bd3362a294628aab Mon Sep 17 00:00:00 2001 From: Morgan - 6 Freedom Date: Sun, 28 Jan 2024 00:06:23 +0100 Subject: [PATCH 3/4] (fix): explanation page is working --- Assets/Scenes/ComputerView.unity | 6 +++--- Assets/Scripts/DatabaseClasses/Room.cs | 2 +- Assets/Scripts/GameManager.cs | 11 +++++------ Assets/Scripts/RoomManager.cs | 8 ++++++-- 4 files changed, 15 insertions(+), 12 deletions(-) diff --git a/Assets/Scenes/ComputerView.unity b/Assets/Scenes/ComputerView.unity index 26942e1..61f2147 100644 --- a/Assets/Scenes/ComputerView.unity +++ b/Assets/Scenes/ComputerView.unity @@ -38,7 +38,7 @@ RenderSettings: m_ReflectionIntensity: 1 m_CustomReflection: {fileID: 0} m_Sun: {fileID: 705507994} - m_IndirectSpecularColor: {r: 0.18028378, g: 0.22571412, b: 0.30692285, a: 1} + m_IndirectSpecularColor: {r: 0.18018535, g: 0.22559482, b: 0.30677685, a: 1} m_UseRadianceAmbientProbe: 0 --- !u!157 &3 LightmapSettings: @@ -1376,8 +1376,8 @@ MonoBehaviour: - {fileID: 2137991537} - {fileID: 340074661} promptList: {fileID: 0} - explanationPage: {fileID: 0} - counter: {fileID: 0} + explanationPage: {fileID: 45150984} + counter: {fileID: 1798182259} waitingForPropositionsPage: {fileID: 1730465902} waitingForPropositionsLabels: - {fileID: 972471162} diff --git a/Assets/Scripts/DatabaseClasses/Room.cs b/Assets/Scripts/DatabaseClasses/Room.cs index 9742598..c9f9830 100644 --- a/Assets/Scripts/DatabaseClasses/Room.cs +++ b/Assets/Scripts/DatabaseClasses/Room.cs @@ -20,7 +20,7 @@ public Room(string _code) players = new Dictionary(); questions = new Dictionary(); currentQuestion = 0; - currentState = 0; + currentState = 1; //default by PC } public List GetPlayerList() diff --git a/Assets/Scripts/GameManager.cs b/Assets/Scripts/GameManager.cs index 437117b..cbebfea 100644 --- a/Assets/Scripts/GameManager.cs +++ b/Assets/Scripts/GameManager.cs @@ -133,7 +133,7 @@ public void PlayerValidateNameAndServerRoom(string _name, string _code) List list = new List(); list.Add(currentPlayer); - UpdateDisplayedListUser(list) ; + UpdateDisplayedListUser(list); }); } }); @@ -222,7 +222,7 @@ public void StartGame() Debug.LogException(ex); } - + } /// @@ -303,7 +303,7 @@ private void UpdateDisplayedListUser(List players) listPlayersUI.text += "\n" + players[i].name; } } - + private void CheckIfIAmTheFirst(List players) { if (players.Count > 1) @@ -312,7 +312,7 @@ private void CheckIfIAmTheFirst(List players) } else { - + } } @@ -334,8 +334,7 @@ public enum GameState PropositionsSent = 4, MakeVote = 5, VoteSent = 6, - Score = 7, - Ending = 8 + Score = 7 } diff --git a/Assets/Scripts/RoomManager.cs b/Assets/Scripts/RoomManager.cs index 7a7314e..3ec8f47 100644 --- a/Assets/Scripts/RoomManager.cs +++ b/Assets/Scripts/RoomManager.cs @@ -57,6 +57,10 @@ private void Awake() private void Start() { + explanationPage.SetActive(false); + waitingForPropositionsPage.SetActive(false); + waitingForPlayersPage.SetActive(true); + propositionCurrentTime = propositionTime; votingCurrentTime = votingTime; ResetAllPlayerLabels(); @@ -70,7 +74,7 @@ private void Update() if (myRoom.currentState == (int)GameState.Explanation && endOfExplanationDate != DateTime.MinValue) { TimeSpan duration = endOfExplanationDate - DateTime.Now; - counter.text = duration.TotalSeconds.ToString("D1"); + counter.text = ((int)duration.TotalSeconds).ToString("D1"); if (duration.TotalMilliseconds <= 0) { @@ -335,7 +339,7 @@ private void OnRoomUpdate(object sender, ValueChangedEventArgs value) case (int)GameState.Explanation: waitingForPlayersPage.SetActive(false); explanationPage.SetActive(true); - endOfExplanationDate = DateTime.Now.AddSeconds(30); + endOfExplanationDate = DateTime.Now.AddSeconds(3); break; case (int)GameState.MakeProposition: HostStartGame(); From 140652da8229003c4d989147c7cd9c071aa1568f Mon Sep 17 00:00:00 2001 From: Marine Date: Sun, 28 Jan 2024 00:06:41 +0100 Subject: [PATCH 4/4] Go to make picture room --- Assets/Scenes/PhoneView.unity | 17 +++++------------ Assets/Scripts/GameManager.cs | 13 ++++++++----- 2 files changed, 13 insertions(+), 17 deletions(-) diff --git a/Assets/Scenes/PhoneView.unity b/Assets/Scenes/PhoneView.unity index ca999a1..53940a7 100644 --- a/Assets/Scenes/PhoneView.unity +++ b/Assets/Scenes/PhoneView.unity @@ -231,6 +231,9 @@ MonoBehaviour: waitingForPlayersPage: {fileID: 0} roomCodeLabel: {fileID: 0} waitingForPlayersLabels: [] + promptList: {fileID: 0} + explanationPage: {fileID: 0} + counter: {fileID: 0} waitingForPropositionsPage: {fileID: 0} waitingForPropositionsLabels: [] propositionTime: 60 @@ -3334,7 +3337,7 @@ GameObject: m_Icon: {fileID: 0} m_NavMeshLayer: 0 m_StaticEditorFlags: 0 - m_IsActive: 1 + m_IsActive: 0 --- !u!224 &1181392806 RectTransform: m_ObjectHideFlags: 0 @@ -3480,16 +3483,6 @@ MonoBehaviour: name: id: creationDate: 0 - currentQuestion: - promptId: - propositions: - photoUrl: - owner: - name: - id: - creationDate: 0 - voters: [] - creationDate: 0 explanationTime: 4 roomCodeField: {fileID: 2023851070} roomError: {fileID: 991600093} @@ -4089,7 +4082,7 @@ GameObject: m_Icon: {fileID: 0} m_NavMeshLayer: 0 m_StaticEditorFlags: 0 - m_IsActive: 1 + m_IsActive: 0 --- !u!224 &1383251890 RectTransform: m_ObjectHideFlags: 0 diff --git a/Assets/Scripts/GameManager.cs b/Assets/Scripts/GameManager.cs index 26eb97b..ce43dd9 100644 --- a/Assets/Scripts/GameManager.cs +++ b/Assets/Scripts/GameManager.cs @@ -59,7 +59,10 @@ private void OnApplicationQuit() myOnlineRoom.Child("players").Child(currentPlayer.id).RemoveValueAsync().ContinueWithOnMainThread(task => { Debug.Log($"delete player {currentPlayer.name}"); - myOnlineRoom.ValueChanged -= OnRoomUpdate; + if(myOnlineRoom!= null) + { + myOnlineRoom.ValueChanged -= OnRoomUpdate; + } }); } @@ -88,7 +91,6 @@ public void PlayerValidateNameAndServerRoom(string _name, string _code) nameError.text = "You have to put a valid name"; nameError.gameObject.SetActive(true); - //TODO : MARINE : use the error label to explain to the user that they have forget to put a name return; } @@ -98,7 +100,6 @@ public void PlayerValidateNameAndServerRoom(string _name, string _code) roomError.text = "You have to put a room code"; roomError.gameObject.SetActive(true); - //TODO : MARINE : use the error label to explain to the user that they have forget to put a room code return; } @@ -127,8 +128,10 @@ public void PlayerValidateNameAndServerRoom(string _name, string _code) WaitingRoom.SetActive(true); HomeConnection.SetActive(false); - List list = new List(); - list.Add(currentPlayer); + List list = new List + { + currentPlayer + }; UpdateDisplayedListUser(list) ; });