This commit is contained in:
Morgan - 6 Freedom 2024-01-28 01:03:24 +01:00
commit e876034c80
3 changed files with 70 additions and 7 deletions

View File

@ -3534,6 +3534,43 @@ RectTransform:
m_AnchoredPosition: {x: 0, y: 0} m_AnchoredPosition: {x: 0, y: 0}
m_SizeDelta: {x: 0, y: 0} m_SizeDelta: {x: 0, y: 0}
m_Pivot: {x: 0, y: 0} m_Pivot: {x: 0, y: 0}
--- !u!114 &1202782732
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1202782726}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 27a435387a7644784a6fc6ae538b68e5, type: 3}
m_Name:
m_EditorClassIdentifier:
currentPlayer:
name:
id:
creationDate: 0
explanationTime: 4
roomCodeField: {fileID: 2023851070}
roomError: {fileID: 991600093}
playerNameField: {fileID: 1163479463}
nameError: {fileID: 1224049646}
submitNewPlayer: {fileID: 1158329299}
listPlayersUI: {fileID: 1891690322}
submitStartGame: {fileID: 638947073}
counter: {fileID: 1383251891}
HomeConnection: {fileID: 2027556831}
WaitingRoom: {fileID: 1590939977}
BeforeStart: {fileID: 563000513}
TakePicture: {fileID: 1181392805}
VotePicture: {fileID: 531335861}
WaitingOtherPlayers: {fileID: 2095389711}
EndGame: {fileID: 1850164816}
myRoom:
code:
currentQuestion: 0
creationDate: 0
currentState: 0
--- !u!1 &1224049644 --- !u!1 &1224049644
GameObject: GameObject:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@ -4097,7 +4134,7 @@ GameObject:
m_Icon: {fileID: 0} m_Icon: {fileID: 0}
m_NavMeshLayer: 0 m_NavMeshLayer: 0
m_StaticEditorFlags: 0 m_StaticEditorFlags: 0
m_IsActive: 0 m_IsActive: 1
--- !u!224 &1383251890 --- !u!224 &1383251890
RectTransform: RectTransform:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0

View File

@ -9,10 +9,10 @@ public class Player
{ {
public string name; public string name;
public string id; public string id;
public float creationDate; public double creationDate;
[JsonConstructor] [JsonConstructor]
public Player(string _name, string _id, float _creationDate) public Player(string _name, string _id, double _creationDate)
{ {
name = _name; name = _name;
id = _id; id = _id;
@ -23,7 +23,7 @@ public Player(string _name, string _id, float _creationDate)
public Player(string _name) public Player(string _name)
{ {
id = Guid.NewGuid().ToString(); id = Guid.NewGuid().ToString();
creationDate = Time.time; creationDate = DateTime.Now.ToOADate();
SetName(_name); SetName(_name);
} }

View File

@ -6,6 +6,7 @@
using Newtonsoft.Json; using Newtonsoft.Json;
using TMPro; using TMPro;
using UnityEngine; using UnityEngine;
using static UnityEditor.Experimental.AssetDatabaseExperimental.AssetDatabaseCounters;
/// <summary> /// <summary>
/// This is the game state manager on the phone side /// This is the game state manager on the phone side
@ -30,6 +31,9 @@ public class GameManager : MonoBehaviour
public TextMeshProUGUI listPlayersUI; public TextMeshProUGUI listPlayersUI;
public GameObject submitStartGame; public GameObject submitStartGame;
[Header("Explanation Component")]
public TextMeshProUGUI counter;
[Header("Pages")] [Header("Pages")]
public GameObject HomeConnection; public GameObject HomeConnection;
public GameObject WaitingRoom; public GameObject WaitingRoom;
@ -42,6 +46,7 @@ public class GameManager : MonoBehaviour
private DatabaseReference realtimeDB; private DatabaseReference realtimeDB;
public Room myRoom; public Room myRoom;
private DatabaseReference myOnlineRoom; private DatabaseReference myOnlineRoom;
private DateTime endOfExplanationDate = DateTime.MinValue;
private void Awake() private void Awake()
{ {
@ -67,6 +72,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() private void Initialize()
{ {
@ -118,11 +137,11 @@ public void PlayerValidateNameAndServerRoom(string _name, string _code)
else else
{ {
myOnlineRoom = realtimeDB.Child("rooms").Child(_code); myOnlineRoom = realtimeDB.Child("rooms").Child(_code);
//subscribe to it
myOnlineRoom.ValueChanged += OnRoomUpdate;
//if room exists, join it //if room exists, join it
JoinRoom(() => JoinRoom(() =>
{ {
//then subscribe to it
myOnlineRoom.ValueChanged += OnRoomUpdate;
myRoom.currentState = (int)GameState.WaitingForOtherPlayersToJoin; myRoom.currentState = (int)GameState.WaitingForOtherPlayersToJoin;
players.Add(currentPlayer); players.Add(currentPlayer);
@ -271,7 +290,11 @@ private void OnRoomUpdate(object sender, ValueChangedEventArgs e)
{ {
try try
{ {
myRoom = JsonConvert.DeserializeObject<Room>(e.Snapshot.GetRawJsonValue()); if (e!= null)
{
myRoom = JsonConvert.DeserializeObject<Room>(e.Snapshot.GetRawJsonValue());
}
} }
catch (Exception ex) catch (Exception ex)
{ {
@ -291,6 +314,9 @@ private void OnRoomUpdate(object sender, ValueChangedEventArgs e)
} }
case (int)GameState.Explanation: case (int)GameState.Explanation:
{ {
WaitingRoom.SetActive(false);
BeforeStart.SetActive(true);
endOfExplanationDate = DateTime.Now.AddSeconds(3);
break; break;
} }