// Issues a score challenge to the given (optional) players for the leaderboard. Results in the challengeIssuedSuccessfullyEvent/challengeNotIssuedEvent firing. public static void issueScoreChallenge(System.Int64 score, System.Int64 context, string leaderboardId, string[] playerIds = null, string message = "") { if (Application.platform == RuntimePlatform.IPhonePlayer || (int)Application.platform == 31) { _gameCenterIssueScoreChallenge(score, context, leaderboardId, Json.encode(playerIds), message); } }
// Shows the share sheet with the given items. Items can be text, urls or full and proper paths to sharable files public static void shareItems(string[] items) { if (Application.platform == RuntimePlatform.IPhonePlayer) { _sharingShareItems(Json.encode(items), null); } }
// Issues an achievement challenge to the given (optional) players for the leaderboard. Results in the challengeIssuedSuccessfullyEvent/challengeNotIssuedEvent firing. public static void issueAchievementChallenge(string identifier, string[] playerIds = null, string message = "") { if (Application.platform == RuntimePlatform.IPhonePlayer || (int)Application.platform == 31) { _gameCenterIssueAchievementChallenge(identifier, Json.encode(playerIds), message); } }
// Finishes a turn-based match. The last client to update a match is responsible for calling finish on that match. // Important! See the note above in the "Important note about finishing a match" section for more information. public static void finishMatchWithData(string matchId, byte[] matchData, List <GPGTurnBasedParticipantResult> results) { if (Application.platform == RuntimePlatform.Android) { _plugin.Call("finishMatchWithData", matchId, matchData, Json.encode(results)); } }
// Shows the share sheet with the given items with a list of excludedActivityTypes. See Apple's docs for more information on excludedActivityTypes. public static void shareItems(string[] items, string[] excludedActivityTypes) { if (Application.platform == RuntimePlatform.IPhonePlayer) { _sharingShareItems(Json.encode(items), Json.encode(excludedActivityTypes)); } }
// Fetches all the accounts of the given AccountType. Results in the accessGrantedForAccountsWithUsernamesEvent or accessDeniedToAccountsEvent firing. public static void fetchAccountsWithAccountType(AccountType accountType, Dictionary <string, object> options) { var account = "com.apple." + accountType.ToString().ToLower(); if (Application.platform == RuntimePlatform.IPhonePlayer) { _sharingFetchAccountsWithAccountType(account, Json.encode(options ?? new Dictionary <string, object>())); } }
/// <summary> /// WARNING: Please do not do this on device! It is very, very easy to hack any on device receipt validation! This should be done on a secure server! /// useSandboxServers should be true when accessing the iTunes sandbox servers. password is the Shared Secret available in iTunes Connect. Returns a /// null StoreKitAppReceipt on request failure. /// </summary> public static IEnumerator validateReceipt(bool useSandboxServers, string password = null, Action <StoreKitAppReceipt> completionHandler = null) { var receiptPath = getAppStoreReceiptLocation().Replace("file://", string.Empty); if (!System.IO.File.Exists(receiptPath)) { Debug.LogError("Receipt file does not exist on disk. Try refreshing the receipt first to ensure it is present."); if (completionHandler != null) { completionHandler(null); } yield break; } var receiptData = System.IO.File.ReadAllBytes(receiptPath); var receiptBase64 = System.Convert.ToBase64String(receiptData); // form the JSON for the request var dict = new Dictionary <string, object>(); dict.Add("receipt-data", receiptBase64); if (password != null) { dict.Add("password", password); } var json = Json.encode(dict); var postBytes = System.Text.ASCIIEncoding.UTF8.GetBytes(json); // use the proper URL based on if we are hitting the sandbox or not var www = new WWW(useSandboxServers ? "https://sandbox.itunes.apple.com/verifyReceipt" : "https://buy.itunes.apple.com/verifyReceipt", postBytes); yield return(www); if (www.error == null) { // why must we dump the JSON to disk to get it to parse properly? Who knows. var receiptJsonFile = System.IO.Path.Combine(Application.persistentDataPath, "receipt.json"); System.IO.File.WriteAllText(receiptJsonFile, www.text); var receipt = Json.decode <StoreKitAppReceipt>(System.IO.File.ReadAllText(receiptJsonFile)); System.IO.File.Delete(receiptJsonFile); if (completionHandler != null) { completionHandler(receipt); } } else { Debug.LogError(www.error); if (completionHandler != null) { completionHandler(null); } } }
/// <summary> /// Schedules a notification to fire. Use the fields in the AndroidNotificationConfiguration object to configure the notification. When dealing with grouped notifications /// the groupKey must match for all notifications and you must set one notification to be the summary notification (AndroidNotificationConfiguration.isGroupSummary /// must be true). The extraData will be returned with the notificationReceivedEvent and the int returned (requestCode) can be used to cancel the notification. /// If AndroidNotificationConfiguration.cancelsNotificationId is set when the notification fires it will call cancelNotification with that notification Id. /// </summary> public static int scheduleNotification(AndroidNotificationConfiguration config) { if (Application.platform != RuntimePlatform.Android) { return(-1); } config.build(); return(_plugin.Call <int>("scheduleNotification", Json.encode(config))); }
// Schedules a notification to fire. Use the fields in the AndroidNotificationConfiguration object to configure the notification. When dealing with grouped notifications // the groupKey must match for all notifications and you must set one notification to be the summary notification (AndroidNotificationConfiguration.isGroupSummary // must be true). The extraData will be returned with the notificationReceivedEvent and the int returned (requestCode) can be used to cancel the notification. // If AndroidNotificationConfiguration.cancelsNotificationId is set when the notification fires it will call cancelNotification with that notification Id. public static int scheduleNotification(AndroidNotificationConfiguration config) { if (Application.platform != RuntimePlatform.Android) { return(-1); } config.build(); //return _plugin.Call<int>( "scheduleNotification", config.secondsFromNow, config.title, config.subtitle, config.tickerText, config.extraData, config.smallIcon, config.largeIcon, config.requestCode, config.color, config.groupKey, config.isGroupSummary ); return(_plugin.Call <int>("scheduleNotification", Json.encode(config))); }
public static void showGameRequestDialog(FacebookGameRequestContent content) { if (Application.platform != RuntimePlatform.Android) { return; } FacebookAndroid._facebookPlugin.Call("showGameRequestDialog", new object[] { Json.encode(content) }); }
public void graphRequestBatch(IEnumerable <FacebookBatchRequest> requests, Action <string, object> completionHandler) { Dictionary <string, object> dictionary = new Dictionary <string, object>(); List <Dictionary <string, object> > list = new List <Dictionary <string, object> >(); foreach (FacebookBatchRequest current in requests) { list.Add(current.requestDictionary()); } dictionary.Add("batch", Json.encode(list)); base.surrogateMonobehaviour.StartCoroutine(this.send(string.Empty, HTTPVerb.POST, dictionary, completionHandler)); }
public void graphRequestBatch(IEnumerable <FacebookBatchRequest> requests, Action <string, object> completionHandler) { var parameters = new Dictionary <string, object>(); var requestList = new List <Dictionary <string, object> >(); foreach (var r in requests) { requestList.Add(r.requestDictionary()); } parameters.Add("batch", Json.encode(requestList)); surrogateMonobehaviour.StartCoroutine(send(string.Empty, HTTPVerb.POST, parameters, completionHandler)); }
public override string ToString() { if (_containsOnlyMessage) { return($"[P31Error]: {message}"); } try { string input = Json.encode(this); return($"[P31Error]: {JsonFormatter.prettyPrint(input)}"); } catch (Exception) { return($"[P31Error]: {message}"); } }
// Logs an event with optional parameters public static void logEvent(string eventName, Dictionary <string, object> parameters = null) { if (Application.platform != RuntimePlatform.Android) { return; } if (parameters != null) { _facebookPlugin.Call("logEventWithParameters", eventName, Json.encode(parameters)); } else { _facebookPlugin.Call("logEvent", eventName); } }
// Logs an event, valueToSum and optional parameters public static void logEvent(string eventName, double valueToSum, Dictionary <string, object> parameters = null) { if (Application.platform != RuntimePlatform.IPhonePlayer) { return; } if (parameters != null) { _facebookLogEventAndValueToSumWithParameters(eventName, valueToSum, Json.encode(parameters)); } else { _facebookLogEventAndValueToSum(eventName, valueToSum); } }
// Registers the deviceToken with GameThrive. Note that a GameThrive app ID is required to use GameThrive. public static IEnumerator registerDeviceWithGameThrive(string gameThriveAppId, string deviceToken, Dictionary <string, string> additionalParameters = null, Action <WWW> completionHandler = null) { var url = string.Format("https://gamethrive.com/api/v1/players"); var parameters = new Dictionary <string, string>(); parameters.Add("device_type", "0"); parameters.Add("app_id", gameThriveAppId); parameters.Add("identifier", deviceToken); if (additionalParameters != null) { foreach (var key in additionalParameters.Keys) { parameters.Add(key, additionalParameters[key]); } } var json = Json.encode(parameters); var bytes = System.Text.Encoding.UTF8.GetBytes(json); #if UNITY_4_5 || UNITY_4_6 || UNITY_4_7 || UNITY_5_0 || UNITY_5_1 var headers = new Dictionary <string, string>(); #else //var headers = new Hashtable(); var headers = new Dictionary <string, string>(); #endif headers.Add("Content-Type", "application/json"); using (var www = new WWW(url, bytes, headers)) { yield return(www); if (completionHandler != null) { completionHandler(www); } } }
public static void logEvent(string eventName, double valueToSum, Dictionary <string, object> parameters = null) { if (Application.platform != RuntimePlatform.Android) { return; } if (parameters != null) { FacebookAndroid._facebookPlugin.Call("logEventAndValueToSumWithParameters", new object[] { eventName, valueToSum, Json.encode(parameters) }); } else { FacebookAndroid._facebookPlugin.Call("logEventAndValueToSum", new object[] { eventName, valueToSum }); } }
public override string ToString() { return(JsonFormatter.prettyPrint(Json.encode(this)) ?? string.Empty); }
// Performs a request using the specified AccountType and username (retrieved from fetchAccountsWithAccountType). Each service has it's own API format for the url so refer // to their documentation directly for details on the url and parameters. Calling this reaults in the requestSucceeded/FailedEvent event firing. public static void performRequest(AccountType accountType, string username, string url, SharingRequestMethod requestMethod = SharingRequestMethod.Get, Dictionary <string, string> parameters = null) { var account = "com.apple." + accountType.ToString().ToLower(); if (Application.platform == RuntimePlatform.IPhonePlayer) { _sharingPerformRequest(account, username, url, requestMethod.ToString().ToLower(), Json.encode(parameters ?? new Dictionary <string, string>())); } }
public static string toJson(this IList obj) { return(Json.encode(obj)); }
public static void logObject(object obj) { string json = Json.encode(obj); prettyPrintJson(json); }
public static string toJson(this IDictionary obj) { return(Json.encode(obj)); }