Represents an invitation to a multiplayer game. The invitation may be for a turn-based or real-time game.
        // 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;
                }
            }
        }
 public void Clear()
 {
     mInvitation = null;
     mShouldAutoAccept = false;
 }
 public void OnInvitationReceived(Invitation inv, bool shouldAutoAccept)
 {
     mInvitation = inv;
     mShouldAutoAccept = shouldAutoAccept;
 }
Пример #4
0
 public void InvitationReceived(GooglePlayGames.BasicApi.Multiplayer.Invitation invitation, bool yesOrNo)
 {
     Debug.Log("Tou have been invited on a game of MOOOOOOLES");
 }
 private void OnInvitationReceived(Invitation invitation, bool fromNotification)
 {
     string inviterName = invitation.Inviter != null ? invitation.Inviter.DisplayName : "(null)";
     Status = "!!! Got invitation " + (fromNotification ? " (from notification):" : ":") +
     " from " + inviterName + ", id " + invitation.InvitationId;
     mLastInvitationId = invitation.InvitationId;
 }
		private static void PushNotificationCallback(bool isRealTime,
		                                             string invitationId,
		                                             string inviterId, 
		                                             string inviterName, 
		                                             int variant)
		{
			Logger.d("IOSClient.PushotificationCallback isRealTime=" + isRealTime + ", invitationId=" + invitationId 
			         + " inviterId=" + inviterId + " inviterName= " + inviterName + " variant=" + variant);

			Invitation.InvType invitationType = (isRealTime) ? Invitation.InvType.RealTime : Invitation.InvType.TurnBased;
			Participant inviter = new Participant (inviterName, inviterId, Participant.ParticipantStatus.Unknown, null, false);
			Invitation incomingInvite = new Invitation (invitationType, invitationId, inviter, variant);
			// For now, we're going to always going to make this false.
			sInvitationDelegate.Invoke (incomingInvite, false);
		}
 public void GetAllInvitations(Action<Invitation[]> callback)
 {
     mTurnBasedManager.GetAllTurnbasedMatches(allMatches =>
         {
             Invitation[] invites = new Invitation[allMatches.InvitationCount()];
             int i=0;
             foreach (var invitation in allMatches.Invitations())
             {
                 invites[i++] = invitation.AsInvitation();
             }
             callback(invites);
         });
 }
 private Invitation ConvertInvitation(AndroidJavaObject invObj) {
     Logger.d("Converting Android invitation to our Invitation object.");
     string invitationId = invObj.Call<string>("getInvitationId");
     int invType = invObj.Call<int>("getInvitationType");
     Participant inviter;
     using (AndroidJavaObject inviterObj = invObj.Call<AndroidJavaObject>("getInviter")) {
         inviter = JavaUtil.ConvertParticipant(inviterObj);
     }
     int variant = invObj.Call<int>("getVariant");
     Invitation.InvType type;
     
     switch (invType) {
     case JavaConsts.INVITATION_TYPE_REAL_TIME:
         type = Invitation.InvType.RealTime;
         break;
     case JavaConsts.INVITATION_TYPE_TURN_BASED:
         type = Invitation.InvType.TurnBased;
         break;
     default:
         Logger.e("Unknown invitation type " + invType);
         type = Invitation.InvType.Unknown;
         break;
     }
     
     Invitation result = new Invitation(type, invitationId, inviter, variant);
     Logger.d("Converted invitation: " + result.ToString());
     return result;
 }
 private void CheckForConnectionExtras() {
     // check to see if we have a pending invitation in our gamehelper
     Logger.d("AndroidClient: CheckInvitationFromNotification.");
     Logger.d("AndroidClient: looking for invitation in our GameHelper.");
     Invitation invFromNotif = null;
     AndroidJavaObject invObj = mGHManager.GetInvitation();
     AndroidJavaObject matchObj = mGHManager.GetTurnBasedMatch();
     
     mGHManager.ClearInvitationAndTurnBasedMatch();
     
     if (invObj != null) {
         Logger.d("Found invitation in GameHelper. Converting.");
         invFromNotif = ConvertInvitation(invObj);
         Logger.d("Found invitation in our GameHelper: " + invFromNotif);
     } else {
         Logger.d("No invitation in our GameHelper. Trying SignInHelperManager.");
         AndroidJavaClass cls = JavaUtil.GetClass(JavaConsts.SignInHelperManagerClass);
         using (AndroidJavaObject inst = cls.CallStatic<AndroidJavaObject>("getInstance")) {
             if (inst.Call<bool>("hasInvitation")) {
                 invFromNotif = ConvertInvitation(inst.Call<AndroidJavaObject>("getInvitation"));
                 Logger.d("Found invitation in SignInHelperManager: " + invFromNotif);
                 inst.Call("forgetInvitation");
             } else {
                 Logger.d("No invitation in SignInHelperManager either.");
             }
         }
     }
     
     TurnBasedMatch match = null;
     if (matchObj != null) {
         Logger.d("Found match in GameHelper. Converting.");
         match = JavaUtil.ConvertMatch(mUserId, matchObj);
         Logger.d("Match from GameHelper: " + match);
     } else {
         Logger.d("No match in our GameHelper. Trying SignInHelperManager.");
         AndroidJavaClass cls = JavaUtil.GetClass(JavaConsts.SignInHelperManagerClass);
         using (AndroidJavaObject inst = cls.CallStatic<AndroidJavaObject>("getInstance")) {
             if (inst.Call<bool>("hasTurnBasedMatch")) {
                 match = JavaUtil.ConvertMatch(mUserId, 
                         inst.Call<AndroidJavaObject>("getTurnBasedMatch"));
                 Logger.d("Found match in SignInHelperManager: " + match);
                 inst.Call("forgetTurnBasedMatch");
             } else {
                 Logger.d("No match in SignInHelperManager either.");
             }
         }
     }
     
     // if we got an invitation from the notification, invoke the delegate
     if (invFromNotif != null) {
         if (mInvitationDelegate != null) {
             Logger.d("Invoking invitation received delegate to deal with invitation " + 
                      " from notification.");
             PlayGamesHelperObject.RunOnGameThread(() => {
                 if (mInvitationDelegate != null) {
                     mInvitationDelegate.Invoke(invFromNotif, true);
                 }
             });
         } else {
             Logger.d("No delegate to handle invitation from notification; queueing.");
             mInvitationFromNotification = invFromNotif;
         }
     }
     
     // if we got a turn-based match, hand it over to the TBMP client who will know
     // better what to do with it
     if (match != null) {
         mTbmpClient.HandleMatchFromNotification(match);
     }
 }
 internal void ClearInvitationIfFromNotification(string invitationId) {
     Logger.d("AndroidClient.ClearInvitationIfFromNotification: " + invitationId);
     if (mInvitationFromNotification != null && 
         mInvitationFromNotification.InvitationId.Equals(invitationId)) {
         Logger.d("Clearing invitation from notification: " + invitationId);
         mInvitationFromNotification = null;
     }
 }
 // called from game thread
 public void RegisterInvitationDelegate(InvitationReceivedDelegate deleg) {
     Logger.d("AndroidClient.RegisterInvitationDelegate");
     if (deleg == null) {
         Logger.w("AndroidClient.RegisterInvitationDelegate called w/ null argument.");
         return;
     }
     mInvitationDelegate = deleg;
     
     // install invitation listener, if we don't have one yet
     if (!mRegisteredInvitationListener) {
         Logger.d("Registering an invitation listener.");
         RegisterInvitationListener();
     }
     
     if (mInvitationFromNotification != null) {
         Logger.d("Delivering pending invitation from notification now.");
         Invitation inv = mInvitationFromNotification;
         mInvitationFromNotification = null;
         PlayGamesHelperObject.RunOnGameThread(() => {
             if (mInvitationDelegate != null) {
                 mInvitationDelegate.Invoke(inv, true);
             }
         });
     }
 }