예제 #1
0
        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);
            }
        }
예제 #2
0
        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();
            }
        }
예제 #3
0
        void OnGUI()
        {
            KongregateAPI kongregate = KongregateAPI.GetAPI();

            if (!kongregate.IsReady())
            {
                // don't display purchase UI until Kongregate is ready
                return;
            }
            KongDemoHelper.PrepareGUI();

            if (mPurchaseReady)
            {
                if (GUI.Button(new Rect(1280 / 2 - 100, 50, 240, 80), "P31 Purchase", KongDemoHelper.buttonStyle))
                {
                    StartPurchase();
                }
            }
        }
    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