void OnGUI() { beginColumn(); if (GUILayout.Button("Initialize Facebook")) { FacebookAndroid.init(); } if (GUILayout.Button("Set Login Behavior to SUPPRESS_SSO")) { FacebookAndroid.setSessionLoginBehavior(FacebookSessionLoginBehavior.SUPPRESS_SSO); } if (GUILayout.Button("Login")) { FacebookAndroid.loginWithReadPermissions(new string[] { "email", "user_birthday" }); } if (GUILayout.Button("Reauthorize with Publish Permissions")) { FacebookAndroid.reauthorizeWithPublishPermissions(new string[] { "publish_actions", "manage_friendlists" }, FacebookSessionDefaultAudience.Everyone); } if (GUILayout.Button("Logout")) { FacebookAndroid.logout(); } if (GUILayout.Button("Is Session Valid?")) { var isSessionValid = FacebookAndroid.isSessionValid(); Debug.Log("Is session valid?: " + isSessionValid); } if (GUILayout.Button("Get Session Token")) { var token = FacebookAndroid.getAccessToken(); Debug.Log("session token: " + token); } if (GUILayout.Button("Get Granted Permissions")) { var permissions = FacebookAndroid.getSessionPermissions(); Debug.Log("granted permissions: " + permissions.Count); Prime31.Utils.logObject(permissions); } endColumn(true); if (GUILayout.Button("Post Image")) { var pathToImage = Application.persistentDataPath + "/" + screenshotFilename; var bytes = System.IO.File.ReadAllBytes(pathToImage); Facebook.instance.postImage(bytes, "im an image posted from Android", completionHandler); } if (GUILayout.Button("Graph Request (me)")) { Facebook.instance.graphRequest("me", completionHandler); } if (GUILayout.Button("Post Message")) { Facebook.instance.postMessage("im posting this from Unity: " + Time.deltaTime, completionHandler); } if (GUILayout.Button("Post Message & Extras")) { Facebook.instance.postMessageWithLinkAndLinkToImage("link post from Unity: " + Time.deltaTime, "http://prime31.com", "prime[31]", "http://prime31.com/assets/images/prime31logo.png", "Prime31 Logo", completionHandler); } if (GUILayout.Button("Show Share Dialog")) { var parameters = new Dictionary <string, object> { { "link", "http://prime31.com" }, { "name", "link name goes here" }, { "picture", "http://prime31.com/assets/images/prime31logo.png" }, { "caption", "the caption for the image is here" }, { "description", "description of what this share dialog is all about" } }; FacebookAndroid.showFacebookShareDialog(parameters); } if (GUILayout.Button("Show Post Dialog")) { // parameters are optional. See Facebook's documentation for all the dialogs and paramters that they support var parameters = new Dictionary <string, string> { { "link", "http://prime31.com" }, { "name", "link name goes here" }, { "picture", "http://prime31.com/assets/images/prime31logo.png" }, { "caption", "the caption for the image is here" } }; FacebookAndroid.showDialog("stream.publish", parameters); } if (GUILayout.Button("Show Apprequests Dialog")) { // See Facebook's documentation for all the dialogs and paramters that they support var parameters = new Dictionary <string, string> { { "message", "Come play my awesome game!" } }; FacebookAndroid.showDialog("apprequests", parameters); } if (GUILayout.Button("Get Friends")) { Facebook.instance.getFriends(completionHandler); } endColumn(); if (bottomLeftButton("Twitter Scene")) { Application.LoadLevel("TwitterTestScene"); } }
void OnGUI() { //write your GUI elements for 1280x720 GUI.matrix = Matrix4x4.TRS(new Vector3(0, 0, 0), Quaternion.identity, new Vector3(Screen.width / targetWidth, Screen.height / targetHeight, 1)); KongregateAPI kongregate = KongregateAPI.GetAPI(); // isReady() is true if we are on iOS platform and the API is initalized properly if (kongregate.IsReady()) { #if UNITY_STANDALONE if (GUI.Button(new Rect(targetWidth / 2 - 170 - 5, 10, 80, 40), "Reset Data")) { Kongregate.DataStore dataStore = Kongregate.DataStore.Get("analytics"); string playerId = dataStore.GetString("player_id", ""); Debug.Log("PlayerID was: " + playerId); dataStore.DeleteAll(); if (!string.IsNullOrEmpty(playerId)) { dataStore.SetString("player_id", playerId); } } #endif // add a simple button to demonstrate hidding and showing the K button if (GUI.Button(new Rect(targetWidth / 2 - 80 - 5, 10, 80, 40), "Toggle K")) { if (kongregate.Mobile.ButtonIsHidden()) { kongregate.Mobile.ButtonShow(); } else { kongregate.Mobile.ButtonHide(); } } // add a simple button to demonstrate submitting stats if (GUI.Button(new Rect(targetWidth / 2 + 5, 10, 80, 40), "Submit Win")) { kongregate.Stats.Submit("Wins", 1); } Dictionary <string, object> fields = new Dictionary <string, object>() { { "type", "Gold Pack" }, { "discount_percent", 12.5 }, { "context_of_offer", "StoreFront" } }; if (mPurchaseReady) { if (GUI.Button(new Rect(targetWidth / 2 - 170 - 5, 60, 80, 40), "Purchase")) { mPurchaseReady = false; // disable button when clicked #if UNITY_IPHONE && PRIME31_STOREKIT kongregate.Analytics.StartPurchase("com.kongregate.mobile.games.angryBots.t05_coins", 1, fields); StoreKitBinding.purchaseProduct("com.kongregate.mobile.games.angryBots.t05_coins", 1); #elif UNITY_ANDROID && PRIME31_STOREKIT kongregate.Analytics.StartPurchase("com.kongregate.android.games.angrybots.t03_hard", 1, fields); GoogleIAB.purchaseProduct("com.kongregate.android.games.angrybots.t03_hard"); #elif UNITY_WEBPLAYER || UNITY_WEBGL kongregate.Analytics.StartPurchase("com.kongregate.web.angrybots.t05_hard", 1, fields); // Use the Javascript API to initiate the purchase. Notice in this flow we call finishPurchase via // the Javascript API after the purchase is completed by serializing the game fields needed. You // could also save the game fields into a variable in your Unity script and then call // kongregate.Analytics.FinishPurchase(...) in the Unity callback as well. Application.ExternalEval(string.Format( @"kongregate.mtx.purchaseItems(['com.kongregate.web.angrybots.t05_hard'], function(result){{ var status = result.success ? 'SUCCESS' : 'FAIL'; var data = result.success ? '{0}' : '{1}'; kongregate.analytics.finishPurchase(status, result.purchase_id, data); // Fire the callback in the Unity code kongregateUnitySupport.getUnityObject().SendMessage('Kongregate', 'OnKredPurchaseResult', status); }});" , Kongregate.Analytics.toAnalyticEventJSON(getPurchaseFields()), Kongregate.Analytics.toAnalyticEventJSON(fields))); #elif UNITY_STANDALONE kongregate.Analytics.StartPurchase("com.kongregate.mobile.games.angryBots.t05_hard", 1, fields); #endif } #if UNITY_IPHONE && PRIME31_STOREKIT if (GUI.Button(new Rect(targetWidth / 2 + 5, 60, 80, 40), "Restore")) { StoreKitBinding.restoreCompletedTransactions(); } #endif if (mRecentPurchase) { GUI.Box(new Rect(targetWidth / 2 - 70, targetHeight / 2 - 30, 140, 60), "Purchase Successful!"); if (GUI.Button(new Rect(targetWidth / 2 - 20, targetHeight / 2, 40, 20), "OK")) { mRecentPurchase = false; } } } #if UNITY_STANDALONE if (!mPurchaseReady) { if (GUI.Button(new Rect(targetWidth / 2 - 170 - 5, 60, 80, 40), "Finish")) { kongregate.Analytics.FinishPurchase("SUCCESS", null, getPurchaseFields()); mPurchaseReady = true; } if (GUI.Button(new Rect(targetWidth / 2 - 80 - 5, 60, 80, 40), "Cancel")) { kongregate.Analytics.FinishPurchase("FAIL", null, fields); mPurchaseReady = true; } } #endif // add text fields to demonstrate submitting generic stat types GUI.Label(new Rect(targetWidth / 2 + 95, 10, 50, 20), "Stat:"); mCustomStatId = GUI.TextField(new Rect(targetWidth / 2 + 140, 10, 80, 20), mCustomStatId); GUI.Label(new Rect(targetWidth / 2 + 95, 35, 50, 20), "Value:"); mCustomStatValue = GUI.TextField(new Rect(targetWidth / 2 + 140, 35, 80, 20), mCustomStatValue); if (GUI.Button(new Rect(targetWidth / 2 + 230, 10, 80, 40), "Submit")) { long value = 0; if (long.TryParse(mCustomStatValue, out value)) { kongregate.Stats.Submit(mCustomStatId, long.Parse(mCustomStatValue)); } } if (GUI.Button(new Rect(targetWidth / 2 + 430, 10, 100, 40), "Inventory")) { mInventory = false; kongregate.Mtx.RequestUserItemList(); } GUI.Box(new Rect(5, 105, 200, 60), ""); if (mInventory) { GUI.Label(new Rect(10, 110, 200, 20), "Has AWESOME GUN: " + mHasGun); } else { GUI.Label(new Rect(10, 110, 200, 20), "Requesting inventory..."); } if (mUsername != null) { GUI.Label(new Rect(10, 125, 200, 20), "Username: "******", id: " + mUserId); GUI.Label(new Rect(10, 140, 200, 20), "KongPlus: " + mHasKongPlus); } if (GUI.Button(new Rect(targetWidth / 2 + 535, 10, 100, 40), "FBPost")) { Dictionary <string, object> parameters = new Dictionary <string, object>() { { "link", "http://www.kongregate.com" }, { "name", "AngryBots" }, { "caption", "Testing 123" }, { "description", "Test Post" } }; #if UNITY_ANDROID && PRIME31_SOCIAL FacebookAndroid.showFacebookShareDialog(parameters); #elif UNITY_IPHONE && PRIME31_SOCIAL FacebookBinding.showFacebookShareDialog(parameters); #endif } if (GUI.Button(new Rect(targetWidth / 2 + 535, 60, 100, 40), "More Games")) { kongregate.Mobile.OpenKongregateWindow(Kongregate.Mobile.TARGET_MORE_GAMES); } if (GUI.Button(new Rect(targetWidth / 2 + 535, 110, 100, 40), "High Scores")) { kongregate.Mobile.OpenKongregateWindow(Kongregate.Mobile.TARGET_HIGH_SCORES); } if (GUI.Button(new Rect(targetWidth / 2 + 535, 160, 100, 40), "Support")) { kongregate.Mobile.OpenKongregateWindow(Kongregate.Mobile.TARGET_SUPPORT); } if (GUI.Button(new Rect(targetWidth / 2 + 535, 210, 100, 40), "Forums")) { kongregate.Mobile.OpenKongregateWindow(Kongregate.Mobile.TARGET_FORUMS); } // add a simple button to demonstrate submitting analytics mPlayTimer = new System.Diagnostics.Stopwatch(); mPlayTimer.Start(); if (GUI.Button(new Rect(targetWidth / 2 + 330, 10, 80, 40), "Play Ends")) { DemoAddAnalyticsEvent(); } // if our button is not hidden, we need to draw it Rect kButtonRect = new Rect(10, 10, 100, 100); if (kongregate.Mobile.ButtonIsNativeRendering()) { //nothing to do, rendering is handled in native SDK // NOTE: notification count is not supported by native rendering } else if (!kongregate.Mobile.ButtonIsHidden()) { // draw the K button if (GUI.Button(kButtonRect, mKongButtonTexture)) { Debug.Log("You clicked the Kong button!"); kongregate.Mobile.OpenKongregateWindow(); } if (mNotificationCountTexture) { GUI.Label(new Rect(90, 20, 50, 50), mNotificationCountTexture); } } // add buttons for the deep links Rect deepLinkButtonsRect = new Rect(kButtonRect.x, kButtonRect.y + kButtonRect.height + 60, 200, 400); 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:"); mTargetIdText = GUI.TextField(targetIdTextRect, mTargetIdText); int deepLinkClick = GUI.SelectionGrid(deepLinkButtonsRect, -1, mDeepLinkTargets, 2); if (deepLinkClick >= 0) { KongregateAPI.GetAPI().Mobile.OpenKongregateWindow(mDeepLinkTargets[deepLinkClick], mTargetIdText); } } // IsReady } // OnGUI