void stopTimer() { timerStart = false; timer = timer * 1000; finalTime = Mathf.RoundToInt(timer); KongregateAPI.SubmitData("Time Score", finalTime); }
private static void doBuyPremium(Upgrade item) { if (KongregateAPI.instance.isLoaded) { KongregateAPI.doPurchase(item.saveName); } }
public IOSAnalytics(KongregateAPI api) : base(api) { if (!KongregateAPI.Settings.DeferAnalytics) { Start(); } }
public void Start() { if (instance == null) { instance = this; } else if (instance != this) { Destroy(gameObject); return; } DontDestroyOnLoad(gameObject); //gameObject.name = "KongregateAPI"; #pragma warning disable CS0618 // Type or member is obsolete /*Application.ExternalEval( * @"console.log('initializing Kong API'); * if(typeof(kongregateUnitySupport) != 'undefined'){ * console.log('success!'); * kongregateUnitySupport.initAPI('Main Camera', 'OnKongregateAPILoaded'); * };" * );*/ Application.ExternalEval( @"console.log('initializing Kong API'); if(typeof(parent.kongregateUnitySupport) != 'undefined'){ console.log('success!'); parent.kongregateUnitySupport.initAPI('Main Camera', 'OnKongregateAPILoaded'); };" ); #pragma warning restore CS0618 // Type or member is obsolete }
void OnReceiptVerificationComplete() { Debug.Log("OnReceiptVerificationComplete"); KongregateAPI kongregate = KongregateAPI.GetAPI(); // we keep a list of transactions here so that we don't run into race conditions Dictionary <string, object> stillInVerification = new Dictionary <string, object> (); foreach (var transactionId in mTransactionsInVerification.Keys) { string status = kongregate.Mtx.ReceiptVerificationStatus(transactionId); if (status != KongregateAPI.RECEIPT_VERIFICATION_STATUS_PROCESSING) { Debug.Log("Verification for " + transactionId + " is " + status); #if UNITY_IPHONE if (status == KongregateAPI.RECEIPT_VERIFICATION_STATUS_VALID) { StoreKitTransaction transaction = (StoreKitTransaction)mTransactionsInVerification[transactionId]; KongregateAPI.GetAPI().Analytics.FinishPurchase(KongregateAPI.PURCHASE_SUCCESS, transactionId, getPurchaseFields()); // Below is an alternative iOS FinishPurchase() call. This version may be used if your plugin // does not make the transaction Id available or finishes the transaction before passing control // back to Unity. FinishPurchase() is preferred because purchase details may be pulled directly from // the transaction. // KongregateAPI.GetAPI().Analytics.FinishPurchaseWithProductId(KongregateAPI.PURCHASE_SUCCESS, // transaction.productIdentifier, transaction.base64EncodedTransactionReceipt, getPurchaseFields()); } else if (status == KongregateAPI.RECEIPT_VERIFICATION_STATUS_INVALID) { KongregateAPI.GetAPI().Analytics.FinishPurchase(KongregateAPI.PURCHASE_RECEIPT_FAIL, transactionId, getPurchaseFields()); } // call to finish the transaction regardless of it we are valid or not StoreKitBinding.finishPendingTransaction(transactionId); #elif UNITY_ANDROID GooglePurchase transaction = (GooglePurchase)mTransactionsInVerification [transactionId]; if (status == KongregateAPI.RECEIPT_VERIFICATION_STATUS_VALID) { KongregateAPI.GetAPI().Analytics.FinishPurchase(KongregateAPI.PURCHASE_SUCCESS, transaction.originalJson, getPurchaseFields(), transaction.signature); } else if (status == KongregateAPI.RECEIPT_VERIFICATION_STATUS_INVALID) { KongregateAPI.GetAPI().Analytics.FinishPurchase(KongregateAPI.PURCHASE_RECEIPT_FAIL, transaction.originalJson, getPurchaseFields()); } // call to finish transaction regardless of it we are valid or not GoogleIAB.consumeProduct(transaction.productId); #endif mPurchaseReady = true; } else { Debug.Log("Still waiting on verification for " + transactionId); stillInVerification [transactionId] = mTransactionsInVerification [transactionId]; } } mTransactionsInVerification = stillInVerification; }
//Submits score to Kongregate public static void submit() { #if UNITY_WEBPLAYER KongregateAPI.Submit("High Score", CurrentScore); #else getTopHighScores(); #endif }
public AndroidAnalytics(KongregateAPI api, IAndroidWrapper androidApi) : base(api) { this.androidApi = androidApi; if (!KongregateAPI.Settings.DeferAnalytics) { Start(); } }
// ================================================================================================================ // PUBLIC INTERFACE ----------------------------------------------------------------------------------------------- public static KongregateAPI Create() { // Create a game object with a reference to the API GameObject newGameObject = new GameObject("KongregateAPIObject-" + (Time.realtimeSinceStartup)); KongregateAPI instance = newGameObject.AddComponent <KongregateAPI>(); return(instance); }
// Use this for initialization void Start() { //initialize external API if (KongregateAPI.isUsingKongregate && !KongregateAPI.isKongregateLoaded) { GameObject.Find("Main Menu").GetComponent <MainMenu>().isUsingExternalAPI = true; KongregateAPI.Initialize(); } }
// Demonstrate how to retrieve Swrve resources void DemoSwrveResources() { // the following resources should be configured in teh Swrve dashboard Debug.Log("Got Swrve resources: " + KongregateAPI.GetAPI().Analytics.GetResourceNames()); Debug.Log("abtest string value: " + KongregateAPI.GetAPI().Analytics.GetResourceAsString("test_resource", "string_attr", "n/a")); Debug.Log(" abtest int value: " + KongregateAPI.GetAPI().Analytics.GetResourceAsInt("test_resource", "int_attr", 0)); Debug.Log(" abtest float value: " + KongregateAPI.GetAPI().Analytics.GetResourceAsFloat("test_resource", "float_attr", 0)); Debug.Log(" abtest bool value: " + KongregateAPI.GetAPI().Analytics.GetResourceAsBool("test_resource", "bool_attr", false)); }
/** * Handle the KONGREGATE_EVENT_SWRVE_RESOURCES_UPDATES update which is fired by the Swrve SDK when * resources setup for A/B testing are ready to be loaded. */ void OnSwrveResourcesUpdated() { // A handful of accessors are supported to retrieve resources and values Debug.Log("Got Swrve resources: " + KongregateAPI.GetAPI().Analytics.GetResourceNames()); Debug.Log("abtest string value: " + KongregateAPI.GetAPI().Analytics.GetResourceAsString("test_resource", "string_attr", "n/a")); Debug.Log(" abtest int value: " + KongregateAPI.GetAPI().Analytics.GetResourceAsInt("test_resource", "int_attr", 0)); Debug.Log(" abtest float value: " + KongregateAPI.GetAPI().Analytics.GetResourceAsFloat("test_resource", "float_attr", 0)); Debug.Log(" abtest bool value: " + KongregateAPI.GetAPI().Analytics.GetResourceAsBool("test_resource", "bool_attr", false)); }
// Individual achievement private static bool isGameCompleted() { if (SaveGame.numDaysCompleted == SaveGame.numTotalDays) { KongregateAPI.ReportGameCompleted(); GameObject.FindObjectOfType <GameManager>().gameService.ReportGameCompleted(); return(true); } return(false); }
// Use this for initialization void Start() { KongregateManager.eventUserChanged += OnUserChanged; KongregateManager.eventGameAuthChanged += OnGameAuthChanged; KongregateManager.eventUserInventory += OnUserInventory; KongregateManager.eventReady += () => { // request the user's items KongregateAPI.GetAPI().Mtx.RequestUserItemList(); }; }
// "Add" type stat private static int CalculateStarCount() { int r = SaveGame.numStarsAcquired; if (r > 0) { KongregateAPI.ReportStarCount(r); GameObject.FindObjectOfType <GameManager>().gameService.ReportStarCount(r); } return(r); }
void Start() { if (_instance != null) { Destroy(gameObject); return; } _instance = this; DontDestroyOnLoad(this); Connect(); }
// Individual achievements per week private static bool isWeekPerfected(int week) { if (SaveGame.numStarsAcquiredPerWeek[week] == SaveGame.numStarsPossiblePerWeek[week]) { // note: week is 0 based KongregateAPI.ReportWeekPerfected(week); GameObject.FindObjectOfType <GameManager>().gameService.ReportWeekPerfected(week); return(true); } return(false); }
void OnGUI() { KongregateAPI kongregate = KongregateAPI.GetAPI(); if (!kongregate.IsReady()) { // don't display purchase UI until Kongregate is ready return; } KongDemoHelper.PrepareGUI(); // if our button is not hidden, we need to draw it Rect kButtonRect = new Rect(10, 10, 100, 100); // draw the K button if (GUI.Button(kButtonRect, _kongButtonTexture)) { Debug.Log("You clicked the Kong button!"); kongregate.Mobile.OpenKongregateWindow(); } if (_notificationCountTexture) { GUI.Label(new Rect(90, 20, 50, 50), _notificationCountTexture, KongDemoHelper.labelStyle); } // add buttons for the deep links Rect deepLinkButtonsRect = new Rect(kButtonRect.x, kButtonRect.x + kButtonRect.height + 20, 300, 200); Rect targetIdLabelRect = new Rect(deepLinkButtonsRect.x, deepLinkButtonsRect.y + deepLinkButtonsRect.height + 20, 100, 50); Rect targetIdTextRect = new Rect(targetIdLabelRect.x + targetIdLabelRect.width, targetIdLabelRect.y, 100, 50); GUI.Label(targetIdLabelRect, "TargetId:", KongDemoHelper.labelStyle); _targetIdText = GUI.TextField(targetIdTextRect, _targetIdText, KongDemoHelper.textFieldStyle); int deepLinkClick = GUI.SelectionGrid(deepLinkButtonsRect, -1, _deepLinkTargets, 2, KongDemoHelper.buttonStyle); if (deepLinkClick >= 0) { KongregateAPI.GetAPI().Mobile.OpenKongregateWindow(_deepLinkTargets [deepLinkClick], _targetIdText); } // add guild chat button Rect guildChatRect = new Rect(kButtonRect.x + kButtonRect.width + 20, kButtonRect.y + 20, 200, 50); GUIStyle guildChatStyle = new GUIStyle(KongDemoHelper.buttonStyle); if (_unreadGuildChat) { guildChatStyle.fontStyle = FontStyle.Bold; guildChatStyle.normal.textColor = Color.red; } if (GUI.Button(guildChatRect, "Guild Chat", guildChatStyle)) { KongregateAPI.GetAPI().Mobile.OpenKongregateWindow(Mobile.TARGET_GUILD_CHAT); } }
// Use this for initialization void Start() { playing = false; DontDestroyOnLoad(gameObject); GameObject kongregateAPIObject = GameObject.Find("KongregateAPI"); if (kongregateAPIObject != null) { kongAPI = kongregateAPIObject.GetComponent <KongregateAPI>(); } }
// Use this for initialization void Start() { Cursor.visible = true; RoundNumber.text = "" + PlayerPrefs.GetInt("Player Score"); if (PlayerPrefs.GetInt("Player Score") > PlayerPrefs.GetInt("High Score")) { PlayerPrefs.SetInt("High Score", PlayerPrefs.GetInt("Player Score")); } HSNo.text = "" + PlayerPrefs.GetInt("High Score"); KongregateAPI.SubmitStatistic("High Score", PlayerPrefs.GetInt("High Score")); PlayerPrefs.Save(); }
void BuyProductID(string productId) { Dictionary <string, object> purchaseFields = new Dictionary <string, object>() { { "type", "Gold Pack" } }; // If the stores throw an unexpected exception, use try..catch to protect my logic here. try { // If Purchasing has been initialized ... if (IsInitialized()) { // ... look up the Product reference with the general product identifier and the Purchasing system's products collection. Product product = mStoreController.products.WithID(productId); // If the look up found a product for this device's store and that product is ready to be sold ... if (product != null && product.availableToPurchase) { // Notify Kongregate a purchase is starting KongregateAPI.GetAPI().Analytics.StartPurchase(product.definition.storeSpecificId, 1, purchaseFields); Debug.Log(string.Format("Purchasing product asychronously: '{0}'", product.definition.storeSpecificId));// ... buy the product. Expect a response either through ProcessPurchase or OnPurchaseFailed asynchronously. mStoreController.InitiatePurchase(product); } // Otherwise ... else { // ... report the product look-up failure situation Debug.Log("BuyProductID: FAIL. Not purchasing product, either is not found or is not available for purchase"); KongregateAPI.GetAPI().Analytics.FinishPurchase(KongregateAPI.PURCHASE_FAIL, "product not found or available", purchaseFields); } } // Otherwise ... else { // ... report the fact Purchasing has not succeeded initializing yet. Consider waiting longer or retrying initiailization. Debug.Log("BuyProductID FAIL. Not initialized."); KongregateAPI.GetAPI().Analytics.FinishPurchase(KongregateAPI.PURCHASE_FAIL, "purchasing not initialized", purchaseFields); } } // Complete the unexpected exception handling ... catch (Exception e) { // ... by reporting any unexpected exception for later diagnosis. Debug.Log("BuyProductID: FAIL. Exception during purchase. " + e); KongregateAPI.GetAPI().Analytics.FinishPurchase(KongregateAPI.PURCHASE_FAIL, e.Message, purchaseFields); } }
public PurchaseProcessingResult ProcessPurchase(PurchaseEventArgs args) { // A consumable product has been purchased by this user. if (String.Equals(args.purchasedProduct.definition.id, kProductIDConsumable, StringComparison.Ordinal)) { Debug.Log(string.Format("ProcessPurchase: PASS. Product: '{0}'", args.purchasedProduct.definition.id));//If the consumable item has been successfully purchased, add 100 coins to the player's in-game score. // The code below demonstrates how to use Kongregate's Receipt Validation // API. Only do this step if you're server does not have it's own receipt validation. // See OnReceiptVerificationComplete() for what to do after the receipt is validated // either on your server or through our API. #if UNITY_ANDROID // parse the receipt json, orderID and data signature Dictionary <string, object> receipt = Json.Deserialize(args.purchasedProduct.receipt) as Dictionary <string, object>; Dictionary <string, object> payload = Json.Deserialize(receipt["Payload"] as string) as Dictionary <string, object>; Dictionary <string, object> json = Kongregate.Json.Deserialize(payload["json"] as string) as Dictionary <string, object>; string googleReceiptJSON = payload["json"] as string; string googleSignature = payload["signature"] as string; string orderId = json.ContainsKey("orderId") ? json["orderId"] as string : string.Empty; // for Android we key the purchase using the orderID which is later used to retrieve // the verification status. mPendingPurchases[orderId] = args.purchasedProduct; // ...and start the receipt validation request. KongregateAPI.GetAPI().Mtx.VerifyGoogleReceipt(googleReceiptJSON, googleSignature); #elif UNITY_IPHONE // for iOS we key purchases on the the transactionID which is later used to retrieve // verification status mPendingPurchases[args.purchasedProduct.transactionID] = args.purchasedProduct; // for iOS, simply pass the transaction ID to our API KongregateAPI.GetAPI().Mtx.VerifyTransactionId(args.purchasedProduct.transactionID); #endif // return pending so the transaction is not completed until after we validate the receipt return(PurchaseProcessingResult.Pending); } else { Debug.Log(string.Format("ProcessPurchase: FAIL. Unrecognized product: '{0}'", args.purchasedProduct.definition.id)); KongregateAPI.GetAPI().Analytics.FinishPurchase(KongregateAPI.PURCHASE_FAIL, "Unrecognized product", new Dictionary <string, object>() { { "type", "Gold Pack" } }); // return complete to finish the transaction return(PurchaseProcessingResult.Complete); } }
// Individual achievement private static bool isGamePerfected() { for (int i = 0; i < SaveGame.numStarsPossiblePerWeek.Count; i++) { if (SaveGame.numStarsAcquiredPerWeek[i] != SaveGame.numStarsPossiblePerWeek[i]) { return(false); } } KongregateAPI.ReportGamePerfected(); GameObject.FindObjectOfType <GameManager>().gameService.ReportGamePerfected(); return(true); }
void SetupAnalyticsCallbacks() { // The following listeners can only be set after Initialize is invoked, though it is not necessary // to wait for the ready event. KongregateAPI kongregate = KongregateAPI.GetAPI(); // Set the callback that will include fields sent with all events kongregate.Analytics.SetCommonPropsCallback(CommonPropsCallback); // NOTE: if deferred analytics is enabled, you may only SetSwrveButtonListener after Analytics.Start() // is invoked kongregate.Analytics.SetSwrveButtonListener(gameObject.name, "HandleSwrveAction"); }
// Use this for initialization void Start() { Sounds = GameObject.FindGameObjectWithTag("Sound").GetComponent <SoundScript>(); Sounds.Win.Play(); PlayerPrefs.SetInt("Player Score", Sounds.Score); if (PlayerPrefs.GetInt("Player Score") > PlayerPrefs.GetInt("High Score")) { PlayerPrefs.SetInt("High Score", Sounds.Score); } Score.text = "High Score: " + PlayerPrefs.GetInt("High Score"); PScore.text = "You Scored " + PlayerPrefs.GetInt("Player Score"); KongregateAPI.SubmitStatistic("High Score", PlayerPrefs.GetInt("High Score")); }
// Demonstrates how to update game user data in SWRVE. void DemoUpdateGameUserData() { // you may specify game user data as either a dictonary of string values Dictionary <string, object> gameUserProps = new Dictionary <string, object>() { { "user_prop_1", "one" }, { "user_prop_2", "two" } }; KongregateAPI.GetAPI().Analytics.GameUserUpdate(gameUserProps); // or a json string KongregateAPI.GetAPI().Analytics.GameUserUpdate("{ \"json_prop_1\" : \"json_value_1\", \"json_prop_2\" : \"json_value_2\" }"); }
// Individual achievements per week private static bool isWeekCompleted(int week) { for (int i = 0; i < 5; i++) { if (SaveGame.GetHasCompletedAllRoundsInDay(i + (week * 5)) == false) { return(false); } } // note: week is 0 based KongregateAPI.ReportWeekCompleted(week); GameObject.FindObjectOfType <GameManager>().gameService.ReportWeekCompleted(week); return(true); }
// Use this for initialization void Awake() { KongregateAPI kongregate = KongregateAPI.GetAPI(); if (kongregate != null) { SetupAnalyticsCallbacks(); } else { KongregateManager.eventInitializing += SetupAnalyticsCallbacks; } KongregateManager.eventSwrveResourceUpdate += OnSwrveResourcesUpdated; }
// Use this for initialization void Start() { GameObject gameControllerObject = GameObject.FindWithTag("GameController"); if (gameControllerObject != null) { gameController = gameControllerObject.GetComponent <GameController>(); } scoreCounter = gameController.timeCounter; star3 = gameController.timeToGet3Stars; star2 = gameController.timeToGet2Stars; star1 = gameController.timeToGet1Stars; if (scoreCounter > star3) { animator.SetInteger("starCounter", 3); starsEarned = 3; } else if (scoreCounter > star2) { animator.SetInteger("starCounter", 2); starsEarned = 2; } else if (scoreCounter > star1) { animator.SetInteger("starCounter", 1); starsEarned = 1; } int tempScore = PlayerPrefs.GetInt("Score Level" + gameController.level, 0); if (tempScore < scoreCounter) { PlayerPrefs.SetInt("Score Level" + gameController.level, scoreCounter); if (PlayerPrefs.GetInt("Star Count Level" + gameController.level, 0) < starsEarned) { PlayerPrefs.SetInt("Star Count Level" + gameController.level, starsEarned); if (GameObject.Find("Kongregate API") != null) { KongregateAPI Kong = GameObject.FindGameObjectWithTag("KongregateAPI").GetComponent <KongregateAPI>(); if (Kong.Connected) { Kong.Submit("Star Count Level" + gameController.level, starsEarned); } } } } }
} // OnGUI void UpdateNotificationCount() { // Draw the notification icon, if needed. Not currently supported by native rendering int notificationCount = KongregateAPI.GetAPI().Services.GetNotificationCount(); if (notificationCount > 0) { mNotificationCountTexture = (Texture2D)Resources.Load("Kongregate/notification_" + Math.Min(notificationCount, 9), typeof(Texture2D)); } else { mNotificationCountTexture = null; } Debug.Log("has unread guild messages: " + KongregateAPI.GetAPI().Services.HasUnreadGuildMessages()); }
void OnGUI() { KongregateAPI kongregate = KongregateAPI.GetAPI(); if (!kongregate.IsReady()) { // don't display purchase UI until Kongregate is ready return; } KongDemoHelper.PrepareGUI(); if (GUI.Button(new Rect(1280 / 2 - 150, 150, 300, 40), "Send Custom play_ends Events", KongDemoHelper.buttonStyle)) { SendCustomEvents(); } }
/// <summary> /// Connect to Kongregate's API service. /// </summary> public static void Connect(KongregateAPI APIInstance) { if (APIInstance == null) { Debug.LogWarning("Attempting to connect with a null KongregateAPI instance."); return; } if (Instance == null) { Instance = APIInstance; } if (!Connected) { Application.ExternalEval( "if(typeof(kongregateUnitySupport) != 'undefined') {" + "kongregateUnitySupport.initAPI('" + Instance.gameObject.name + "', 'OnKongregateAPILoaded');" + "}" ); } else Debug.LogWarning("You are attempting to connect to Kongregate's API multiple times. You only need to connect once."); }
// Use this for initialization void Start() { s_mgr = this; DontDestroyOnLoad(gameObject); }