correct user connect room
This commit is contained in:
parent
609ec22957
commit
3ed3dc31dd
@ -214,7 +214,7 @@ GameObject:
|
||||
m_Icon: {fileID: 0}
|
||||
m_NavMeshLayer: 0
|
||||
m_StaticEditorFlags: 0
|
||||
m_IsActive: 1
|
||||
m_IsActive: 0
|
||||
--- !u!114 &157909814
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
|
@ -102,6 +102,7 @@ public void PlayerValidateNameAndServerRoom(string _name, string _code)
|
||||
//TODO : MARINE : use the error label to explain to the user that they have forget to put a room code
|
||||
return;
|
||||
}
|
||||
currentPlayer = new Player(_name);
|
||||
|
||||
//check if the room exists, if not display an error message
|
||||
CheckIfRoomExists(_code, room =>
|
||||
@ -114,13 +115,23 @@ public void PlayerValidateNameAndServerRoom(string _name, string _code)
|
||||
}
|
||||
else
|
||||
{
|
||||
myOnlineRoom = realtimeDB.Child("rooms").Child(_code);
|
||||
Debug.Log("Before join room");
|
||||
//if room exists, join it
|
||||
JoinRoom(() =>
|
||||
{
|
||||
//then subscribe to it
|
||||
myOnlineRoom = realtimeDB.Child("rooms").Child(_code);
|
||||
|
||||
myOnlineRoom.ChildChanged += OnRoomUpdate;
|
||||
Debug.Log($"room {myRoom.code} exists, I subscribe to it");
|
||||
currentState = GameState.WaitingForOtherPlayersToJoin;
|
||||
players.Add(currentPlayer);
|
||||
|
||||
WaitingRoom.SetActive(true);
|
||||
HomeConnection.SetActive(false);
|
||||
|
||||
UpdateDisplayedListUser();
|
||||
|
||||
|
||||
});
|
||||
}
|
||||
});
|
||||
@ -160,18 +171,27 @@ private void JoinRoom(Action callback_OnRoomJoined)
|
||||
{
|
||||
|
||||
string JSON = JsonUtility.ToJson(currentPlayer);
|
||||
myOnlineRoom.Child("players").Child(currentPlayer.id).SetRawJsonValueAsync(JSON).ContinueWithOnMainThread(task =>
|
||||
Debug.Log(JSON);
|
||||
try
|
||||
{
|
||||
if (task.IsFaulted)
|
||||
myOnlineRoom.Child("players").Child(currentPlayer.id).SetRawJsonValueAsync(JSON).ContinueWithOnMainThread(task =>
|
||||
{
|
||||
Debug.LogException(task.Exception);
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.Log($"{currentPlayer.name} has been added to the room", this);
|
||||
callback_OnRoomJoined?.Invoke();
|
||||
}
|
||||
});
|
||||
if (task.IsFaulted)
|
||||
{
|
||||
Debug.LogException(task.Exception);
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.Log($"{currentPlayer.name} has been added to the room", this);
|
||||
callback_OnRoomJoined?.Invoke();
|
||||
}
|
||||
});
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Debug.LogException(ex);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -246,8 +266,7 @@ private void OnRoomUpdate(object sender, ChildChangedEventArgs e)
|
||||
{
|
||||
case GameState.WaitingForOtherPlayersToJoin:
|
||||
{
|
||||
WaitingRoom.SetActive(true);
|
||||
HomeConnection.SetActive(false);
|
||||
|
||||
|
||||
// players = new list en fonction de ce qu'envoie fangh
|
||||
UpdateDisplayedListUser();
|
||||
@ -310,7 +329,7 @@ public void OnClickSubmitSignIn()
|
||||
{
|
||||
string playerName = playerNameField.text;
|
||||
string roomCode = roomCodeField.text;
|
||||
|
||||
Debug.Log("click btn");
|
||||
PlayerValidateNameAndServerRoom(playerName, roomCode);
|
||||
}
|
||||
}
|
||||
|
@ -101,14 +101,23 @@ public void CreateNewRoom()
|
||||
{
|
||||
Room newRoom = new Room(GenerateRandomAvailableCode(codes).ToString("D4"));
|
||||
currentRoom = newRoom;
|
||||
string JSON = JsonUtility.ToJson(newRoom);
|
||||
realtimeDB.Child("rooms").Child(newRoom.code).SetRawJsonValueAsync(JSON).ContinueWithOnMainThread(task =>
|
||||
|
||||
try
|
||||
{
|
||||
Debug.Log($"room {currentRoom.code} has been created on the server");
|
||||
realtimeDB.Child("rooms").Child(newRoom.code).Child("players").ChildAdded += PlayerConnect;
|
||||
//TODO MARINE : uncomment and reference the correct game object
|
||||
//roomCodeLabel.text = currentRoom.code;
|
||||
});
|
||||
string JSON = JsonUtility.ToJson(newRoom);
|
||||
|
||||
realtimeDB.Child("rooms").Child(newRoom.code).SetRawJsonValueAsync(JSON).ContinueWithOnMainThread(task =>
|
||||
{
|
||||
Debug.Log($"room {currentRoom.code} has been created on the server");
|
||||
realtimeDB.Child("rooms").Child(newRoom.code).Child("players").ChildAdded += PlayerConnect;
|
||||
//TODO MARINE : uncomment and reference the correct game object
|
||||
//roomCodeLabel.text = currentRoom.code;
|
||||
});
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Debug.LogException(e);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user