Désoler, j'aurais besoin d'un peu d'aide.
J'ai un problème de re-connexion a une salle avec google play services.
C'est à dire que la première connexion fonctionne parfaitement, mais pas la deuxième.
Est-ce que c'est un problème qui parle a quelqu'un?
Je joins la classe communication.
Merci!
Code : Tout sélectionner
public class GameComs : MonoBehaviour, RealTimeMultiplayerListener
{
private static GameComs theOnlyOneGameComs;
private GameObject go;
private GameStatus gs;
private bool inPlayGamesServices;
public string etatConnexion = "offLine";
public string etatLocalGame="onMenu";
// Use this for initialization
void Start()
{
if (theOnlyOneGameComs != null)
{
Destroy(this.gameObject);
return;
}
theOnlyOneGameComs = this;
GameObject.DontDestroyOnLoad(this.gameObject);
go = GameObject.Find("GameStatus");
gs = go.GetComponent<GameStatus>();
// Initialize Play Games Configuration and Activate it.
PlayGamesClientConfiguration config = new PlayGamesClientConfiguration.Builder()
.RequestServerAuthCode(false /*forceRefresh*/)
.Build();
PlayGamesPlatform.InitializeInstance(config);
PlayGamesPlatform.Activate();
Debug.LogFormat("GameComs: Play Games Configuration initialized");
}
public static RealTimeMultiplayerListener Instance => theOnlyOneGameComs;
public void Update()
{if (gs.IAOnline == 1)
{
if (!checkAuthGooglePlay())
{
etatConnexion = "offLine";
}
else
{
etatConnexion = "connectedToPlayGamesServices";
}
if (checkInRoom())
{
etatConnexion = "onRoomConnected";
if (string.Compare(etatLocalGame,"leftTheGame") == 0)
{
PlayGamesPlatform.Instance.RealTime.LeaveRoom();
}
}
else
{
etatLocalGame = "onMenu";
}
}
}
public void signOut()
{
PlayGamesPlatform.Instance.SignOut();
}
public bool checkAuthGooglePlay()
{
return UnityEngine.Social.localUser.authenticated;
}
public bool checkInRoom()
{
return PlayGamesPlatform.Instance.RealTime.IsRoomConnected();
}
public void SignInWithPlayGames()
{
// Initialize Firebase Auth
Firebase.Auth.FirebaseAuth auth = Firebase.Auth.FirebaseAuth.DefaultInstance;
// Sign In and Get a server auth code.
UnityEngine.Social.localUser.Authenticate((bool success) => {
if (!success)
{
Debug.LogError("GameComs: Failed to Sign into Play Games Services.");
return;
}
else
{
etatConnexion = "connectedToPlayGamesServices";
}
inPlayGamesServices = false;
string authCode = PlayGamesPlatform.Instance.GetServerAuthCode();
if (string.IsNullOrEmpty(authCode))
{
Debug.LogError("GameComs: Signed into Play Games Services but failed to get the server auth code.");
return;
}
Debug.LogFormat("GameComs: Auth code is: {0}", authCode);
// Use Server Auth Code to make a credential
Firebase.Auth.Credential credential = Firebase.Auth.PlayGamesAuthProvider.GetCredential(authCode);
// Sign In to Firebase with the credential
auth.SignInWithCredentialAsync(credential).ContinueWith(task => {
if (task.IsCanceled)
{
Debug.LogError("GameComs was canceled.");
return;
}
if (task.IsFaulted)
{
Debug.LogError("GameComs encountered an error: " + task.Exception);
return;
}
Firebase.Auth.FirebaseUser newUser = task.Result;
Debug.LogFormat("GameComs: User signed in successfully: {0} ({1})", newUser.DisplayName, newUser.UserId);
});
});
}
public void quickGame()
{
etatLocalGame = "startingGame";
const int MinOpponents = 1, MaxOpponents = 1;
const int GameVariant = 0;
PlayGamesPlatform.Instance.RealTime.CreateQuickGame(MinOpponents, MaxOpponents,
GameVariant, Instance);
}
public void whithInvitationScreen()
{
etatLocalGame = "startingGame";
const int MinOpponents = 1, MaxOpponents = 1;
const int GameVariant = 0;
PlayGamesPlatform.Instance.RealTime.CreateWithInvitationScreen(MinOpponents, MaxOpponents,
GameVariant, Instance);
}
public void showInvitationInbox()
{
PlayGamesPlatform.Instance.RealTime.AcceptFromInbox(Instance);
}
public void sendMessage(string type, string mess)
{
string m = type + ":" + mess;
byte[] message = System.Text.Encoding.ASCII.GetBytes(m);
bool reliable = true;
PlayGamesPlatform.Instance.RealTime.SendMessageToAll(reliable, message);
}
private int myRandomValForFirctPlayer;
public void getBeginner()
{
System.Random rnd = new System.Random();
myRandomValForFirctPlayer = rnd.Next(0, 100);
sendMessage("R", myRandomValForFirctPlayer.ToString());
}
public void sendSelected(string name)
{
sendMessage("S", "1/" + name);
}
public void sendUnselected(String name)
{
sendMessage("S", "0/" + name);
}
public void sendAction()
{
sendMessage("A", null);
}
public void sendConced()
{
sendMessage("C", null);
}
public void sendNext()
{
sendMessage("N", null);
}
public void sendQuit()
{
sendMessage("Q", null);
etatLocalGame = "leftTheGame";
}
private void receivedMessage(string type, string mess)
{
switch (type)
{
case "R":
{
int oppVal = int.Parse(mess);
if (myRandomValForFirctPlayer > oppVal){gs.PlayerStarter = 1; gs.ToHuman = false; break;}
if(myRandomValForFirctPlayer < oppVal) { gs.PlayerStarter = 2; gs.ToHuman = true; break; }
getBeginner();
break;
}
case "S":
{
string[] messSplited = mess.Split('/');
PlanetModelScript pms = gs.getScript(gs.getPos(messSplited[1]));
if (messSplited[0] == "1"){ pms.select();}
if(messSplited[0] == "0") { pms.unSelect();}
break;
}
case "A":
{
gs.castSelected(1);
break;
}
case "N":
{
gs.StopCoroutines();
SceneManager.LoadScene("game");
break;
}
case "C":
{
gs.saveEndGame(0, false);
gs.endGame();
break;
}
case "Q":
{
gs.saveEndGame(0, false);
gs.gameVicStatus = "vic";
gs.endGame();
break;
}
}
}
public void OnRoomSetupProgress(float percent)
{
etatLocalGame = "startingGame";
if (percent >= 20f)
{
etatConnexion = "onWaitingRoom";
PlayGamesPlatform.Instance.RealTime.ShowWaitingRoomUI();
}
}
public void OnRoomConnected(bool success)
{
if (success)
{
etatLocalGame = "inGame";
etatConnexion = "onRoomConnected";
SceneManager.LoadScene("game");
}
else
{
etatLocalGame = "onMenu";
etatConnexion = "failToRoomConnected";
}
}
public void OnLeftRoom()
{
etatLocalGame = "onMenu";
}
public void OnParticipantLeft(Participant participant)
{
}
public void OnPeersConnected(string[] participantIds)
{
throw new System.NotImplementedException();
}
public void OnPeersDisconnected(string[] participantIds)
{
throw new System.NotImplementedException();
}
public void OnRealTimeMessageReceived(bool isReliable, string senderId, byte[] data)
{
string[] splitedData = System.Text.Encoding.ASCII.GetString(data).Split(':');
receivedMessage(splitedData[0], splitedData[1]);
}
}