Beispiel #1
0
    /**
     * Setting the rich presence
     */
    void SetPresence()
    {
        var options = new RichPresenceOptions();

        // Only Destination API Name is required
        options.SetApiName(DestinationAPINames[DestinationIndex]);

        // Override the deeplink message if you like, otherwise it will use the one found in the destination
        if (!string.IsNullOrEmpty(DeeplinkMessageOverride))
        {
            options.SetDeeplinkMessageOverride(DeeplinkMessageOverride);
        }

        if (!string.IsNullOrEmpty(InstanceID))
        {
            options.SetInstanceId(InstanceID);
        }

        // Set is Joinable to let other players deeplink and join this user via the presence
        options.SetIsJoinable(IsJoinable);

        // Set if the user is idle
        options.SetIsIdle(IsIdle);

        // Used when displaying the current to max capacity on the user's presence
        options.SetCurrentCapacity(CurrentCapacity);
        options.SetMaxCapacity(MaxCapacity);

        // Used to display how long since this start / when will this end
        options.SetStartTime(StartTime);
        options.SetEndTime(EndTime);

        // Used to display extra info like the capacity, start/end times, or looking for a match
        options.SetExtraContext(ExtraContext);
        UpdateConsole("Setting Rich Presence to " + DestinationAPINames[DestinationIndex] + " ...");

        // Here we are setting the rich presence then fetching it after we successfully set it
        RichPresence.Set(options).OnComplete(message => {
            if (message.IsError)
            {
                UpdateConsole(message.GetError().Message);
                ApplicationLifecycle.LogDeeplinkResult(TrackingID, LaunchResult.FailedOtherReason);
            }
            else
            {
                ApplicationLifecycle.LogDeeplinkResult(TrackingID, LaunchResult.Success);
                // Note that Users.GetLoggedInUser() does not do a server fetch and will
                // not get an updated presence status
                Users.Get(LoggedInUserID).OnComplete(message2 =>
                {
                    if (message2.IsError)
                    {
                        UpdateConsole("Success! But rich presence is unknown!");
                    }
                    else
                    {
                        UpdateConsole("Rich Presence set to:\n" + message2.Data.Presence + "\n" + message2.Data.PresenceDeeplinkMessage + "\n" + message2.Data.PresenceDestinationApiName);
                    }
                });
            }
        });
    }