// 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();
            }
        }
    }
    // 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;
            }
        }
    }