// Handle detecting incoming invitations. public void UpdateInvitation() { if (InvitationManager.Instance == null) { return; } // if an invitation arrived, switch to the "invitation incoming" GUI // or directly to the game, if the invitation came from the notification Invitation inv = InvitationManager.Instance.Invitation; if (inv != null) { if (InvitationManager.Instance.ShouldAutoAccept) { // jump straight into the game, since the user already indicated // they want to accept the invitation! InvitationManager.Instance.Clear(); RaceManager.AcceptInvitation(inv.InvitationId); NavigationUtil.ShowPlayingPanel(); } else { // show the "incoming invitation" screen NavigationUtil.ShowInvitationPanel(); } } }
// Use this for initialization void Start() { mAuthCallback = (bool success) => { Debug.Log("In Auth callback, success = " + success); mSigningIn = false; if (success) { NavigationUtil.ShowMainMenu(); } else { Debug.Log("Auth failed!!"); } }; // enable debug logs (note: we do this because this is a sample; // on your production app, you probably don't want this turned // on by default, as it will fill the user's logs with debug info). var config = new PlayGamesClientConfiguration.Builder() .WithInvitationDelegate(InvitationManager.Instance.OnInvitationReceived) .Build(); PlayGamesPlatform.InitializeInstance(config); PlayGamesPlatform.DebugLogEnabled = true; // try silent authentication if (mAuthOnStart) { Authorize(true); } }
// Handler script for the decline button. public void OnDecline() { if (processed) { return; } processed = true; InvitationManager.Instance.DeclineInvitation(); NavigationUtil.ShowMainMenu(); }
// Update is called once per frame void Update() { HandleStatusUpdate(); UpdateInvitation(); if (RaceManager.Instance == null) { return; } switch (RaceManager.Instance.State) { case RaceManager.RaceState.SettingUp: if (statusText != null) { //reset the timer, we can stay here for a long time. mStatusMsg = null; ShowStatus("Waiting for opponents...", false); } break; case RaceManager.RaceState.SetupFailed: ShowStatus("Game setup failed", true); RaceManager.Instance.CleanUp(); processed = false; break; case RaceManager.RaceState.Aborted: ShowStatus("Race Aborted.", true); RaceManager.Instance.CleanUp(); processed = false; break; case RaceManager.RaceState.Finished: // really should not see this on the main menu page, // so go to playing panel to display the final outcome of the race. NavigationUtil.ShowPlayingPanel(); processed = false; break; case RaceManager.RaceState.Playing: NavigationUtil.ShowPlayingPanel(); processed = false; break; default: Debug.Log("RaceManager.Instance.State = " + RaceManager.Instance.State); break; } }
// Update is called once per frame void Update() { inv = (inv != null) ? inv : InvitationManager.Instance.Invitation; if (inv == null && !processed) { Debug.Log("No Invite -- back to main"); NavigationUtil.ShowMainMenu(); return; } if (inviterName == null) { inviterName = (inv.Inviter == null || inv.Inviter.DisplayName == null) ? "Someone" : inv.Inviter.DisplayName; message.text = inviterName + " is challenging you to a quiz race!"; } if (RaceManager.Instance != null) { switch (RaceManager.Instance.State) { case RaceManager.RaceState.Aborted: Debug.Log("Aborted -- back to main"); NavigationUtil.ShowMainMenu(); break; case RaceManager.RaceState.Finished: Debug.Log("Finished-- back to main"); NavigationUtil.ShowMainMenu(); break; case RaceManager.RaceState.Playing: NavigationUtil.ShowPlayingPanel(); break; case RaceManager.RaceState.SettingUp: message.text = "Setting up Race..."; break; case RaceManager.RaceState.SetupFailed: Debug.Log("Failed -- back to main"); NavigationUtil.ShowMainMenu(); break; } } }
//Handler for the signout button. public void OnSignoutClicked() { if (RaceManager.Instance != null) { RaceManager.Instance.CleanUp(); } Debug.Log("Signing out..."); if (PlayGamesPlatform.Instance != null) { PlayGamesPlatform.Instance.SignOut(); } else { Debug.Log("PG Instance is null!"); } NavigationUtil.ShowGameMenu(); }
//Handles resetting the gamepad state then navigating to the main menu. void ShowMainMenu() { EnableGamepad(false); NavigationUtil.ShowMainMenu(); }