diff --git a/Assets/Scenes/PhoneView.unity b/Assets/Scenes/PhoneView.unity index 35da6ac..b71104a 100644 --- a/Assets/Scenes/PhoneView.unity +++ b/Assets/Scenes/PhoneView.unity @@ -924,7 +924,6 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 3b41deef4ebd372d5a18eabdb00cfbb4, type: 3} m_Name: m_EditorClassIdentifier: - PicturePlayer: {fileID: 1316036595} Canvas: {fileID: 1202782726} --- !u!1 &436596783 GameObject: @@ -3523,6 +3522,7 @@ MonoBehaviour: submitNewPlayer: {fileID: 1158329299} listPlayersUI: {fileID: 1891690322} submitStartGame: {fileID: 638947073} + counter: {fileID: 1383251891} HomeConnection: {fileID: 2027556831} WaitingRoom: {fileID: 1590939977} BeforeStart: {fileID: 563000513} @@ -4098,7 +4098,7 @@ GameObject: m_Icon: {fileID: 0} m_NavMeshLayer: 0 m_StaticEditorFlags: 0 - m_IsActive: 0 + m_IsActive: 1 --- !u!224 &1383251890 RectTransform: m_ObjectHideFlags: 0 diff --git a/Assets/Scripts/DatabaseClasses/Player.cs b/Assets/Scripts/DatabaseClasses/Player.cs index 5bb47c7..95d58bc 100644 --- a/Assets/Scripts/DatabaseClasses/Player.cs +++ b/Assets/Scripts/DatabaseClasses/Player.cs @@ -9,10 +9,10 @@ public class Player { public string name; public string id; - public float creationDate; + public double creationDate; [JsonConstructor] - public Player(string _name, string _id, float _creationDate) + public Player(string _name, string _id, double _creationDate) { name = _name; id = _id; @@ -23,7 +23,7 @@ public Player(string _name, string _id, float _creationDate) public Player(string _name) { id = Guid.NewGuid().ToString(); - creationDate = Time.time; + creationDate = DateTime.Now.ToOADate(); SetName(_name); } diff --git a/Assets/Scripts/GameManager.cs b/Assets/Scripts/GameManager.cs index c04453e..bbb065f 100644 --- a/Assets/Scripts/GameManager.cs +++ b/Assets/Scripts/GameManager.cs @@ -6,6 +6,7 @@ using Newtonsoft.Json; using TMPro; using UnityEngine; +using static UnityEditor.Experimental.AssetDatabaseExperimental.AssetDatabaseCounters; /// /// This is the game state manager on the phone side @@ -30,6 +31,9 @@ public class GameManager : MonoBehaviour public TextMeshProUGUI listPlayersUI; public GameObject submitStartGame; + [Header("Explanation Component")] + public TextMeshProUGUI counter; + [Header("Pages")] public GameObject HomeConnection; public GameObject WaitingRoom; @@ -42,6 +46,7 @@ public class GameManager : MonoBehaviour private DatabaseReference realtimeDB; public Room myRoom; private DatabaseReference myOnlineRoom; + private DateTime endOfExplanationDate = DateTime.MinValue; private void Awake() { @@ -66,6 +71,20 @@ private void OnApplicationQuit() }); } + private void Update() + { + if (myRoom.currentState == (int)GameState.Explanation && endOfExplanationDate != DateTime.MinValue ) + { + TimeSpan duration = endOfExplanationDate - DateTime.Now; + counter.text = ((int)duration.TotalSeconds).ToString("D1"); + + if (duration.TotalMilliseconds <= 0) + { + Debug.Log("It's time to make proposition !"); + } + } + } + private void Initialize() { @@ -117,11 +136,11 @@ public void PlayerValidateNameAndServerRoom(string _name, string _code) else { myOnlineRoom = realtimeDB.Child("rooms").Child(_code); + //subscribe to it + myOnlineRoom.ValueChanged += OnRoomUpdate; //if room exists, join it JoinRoom(() => { - //then subscribe to it - myOnlineRoom.ValueChanged += OnRoomUpdate; myRoom.currentState = (int)GameState.WaitingForOtherPlayersToJoin; players.Add(currentPlayer); @@ -270,7 +289,11 @@ private void OnRoomUpdate(object sender, ValueChangedEventArgs e) { try { - myRoom = JsonConvert.DeserializeObject(e.Snapshot.GetRawJsonValue()); + if (e!= null) + { + myRoom = JsonConvert.DeserializeObject(e.Snapshot.GetRawJsonValue()); + + } } catch (Exception ex) { @@ -289,7 +312,10 @@ private void OnRoomUpdate(object sender, ValueChangedEventArgs e) } case (int)GameState.Explanation: { - + WaitingRoom.SetActive(false); + BeforeStart.SetActive(true); + endOfExplanationDate = DateTime.Now.AddSeconds(3); + break; } case (int)GameState.MakeProposition: