fix: phoneView change state

This commit is contained in:
Marine 2024-01-28 00:59:12 +01:00
parent 97860e4232
commit b59ab36b7d
3 changed files with 35 additions and 9 deletions

View File

@ -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

View File

@ -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);
}

View File

@ -6,6 +6,7 @@
using Newtonsoft.Json;
using TMPro;
using UnityEngine;
using static UnityEditor.Experimental.AssetDatabaseExperimental.AssetDatabaseCounters;
/// <summary>
/// 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<Room>(e.Snapshot.GetRawJsonValue());
if (e!= null)
{
myRoom = JsonConvert.DeserializeObject<Room>(e.Snapshot.GetRawJsonValue());
}
}
catch (Exception ex)
{
@ -289,6 +312,9 @@ private void OnRoomUpdate(object sender, ValueChangedEventArgs e)
}
case (int)GameState.Explanation:
{
WaitingRoom.SetActive(false);
BeforeStart.SetActive(true);
endOfExplanationDate = DateTime.Now.AddSeconds(3);
break;
}