示例#1
0
    public void onClickBuyButton(GameObject button)
    {
        Gamestate_Gameplay gs = GameObject.Find("Gamestate").GetComponent <Gamestate_Gameplay> ();

        if (gs == null)
        {
            return;
        }

        ShopContent content = button.GetComponent <ShopContent> ();

        if (content.type == ShopContentType.IAP)
        {
            if (PlayerPrefs.HasKey("joystick." + content.uniqueID) == true)
            {
                PlayerPrefs.SetString("playerjoy", content.uniqueID);
                gs.SetJoystick(content.uniqueID);
                refreshJoystickStatus(content);
            }
            else if (PlayerPrefs.HasKey("claw." + content.uniqueID) == true)
            {
                PlayerPrefs.SetString("playerclaw", content.uniqueID);
                gs.SetClaw(content.uniqueID);
                refreshClawStatus(content);
            }
            else
            {
                currShopContent = content;
                AndroidInAppPurchaseManager.instance.purchase(currShopContent.uniqueID);
                                #if UNITY_EDITOR
                Debug.Log("purchased " + currShopContent.Name);
                                #endif
            }
        }
        else if (content.type == ShopContentType.PowerUp)
        {
            int currCoins = GameManager.GEMUCOINS;

            if (currCoins - content.Price >= 0)
            {
                currShopContent = content;
                Debug.Log("purchased " + currShopContent.Name);
                //show dialog box buy confirmation
            }
            else
            {
                //show dialog box not enough coins
                Debug.Log("not enough coins");
            }
        }

        PlayerPrefs.Save();
    }
示例#2
0
    public void OnClickShopContent()
    {
        UIButton button = UIButton.current;

        if (button == null)
        {
            return;
        }

        Gamestate_Gameplay gs = GameObject.Find("Gamestate").GetComponent <Gamestate_Gameplay>();

        if (gs == null)
        {
            return;
        }

        ShopContent content = button.transform.parent.gameObject.GetComponent <ShopContent> ();

        if (content.type == ShopContentType.IAP)
        {
            if (content.uniqueID == "freecoins")
            {
                GUI_Dialog.InsertStack(gemuFreeCoins.gameObject);
                //if ( GameDataManager.GetTimerToWatchAds() > GameDataManager.TIMER_TO_WATCH_ADS )
                //{
                //if (GameDataManager.PlayUnityVideoAd ()) {
                //	StartCoroutine(ShowingAds());
                //} else {
                //	gs.ShowDialogBox ("Info", "Please wait...", false, "", this.gameObject);
                //}
                //}
                //else
                //	gs.ShowDialogBox("Info","Please wait to watch the next ads.",false,"",this.gameObject);
            }
            else if (PlayerPrefs.HasKey("joystick." + content.uniqueID) == true)
            {
                PlayerPrefs.SetString("playerjoy", content.uniqueID);
                gs.SetJoystick(content.uniqueID);
                RefreshJoystickStatus();
            }
            else if (PlayerPrefs.HasKey("claw." + content.uniqueID) == true)
            {
                PlayerPrefs.SetString("playerclaw", content.uniqueID);
                gs.SetClaw(content.uniqueID);
                RefreshClawStatus();
            }
            else
            {
                currentShopContent = content;
                AndroidInAppPurchaseManager.instance.purchase(currentShopContent.uniqueID);
                //OnSuccessfulPurchase(currentShopContent.uniqueID);
            }
        }
        else if (content.type == ShopContentType.PowerUp)
        {
            int gemucoins = GameManager.GEMUCOINS;
            if (gemucoins - content.Price >= 0)
            {
                currentShopContent = content;
                gs.ShowDialogBox(content.Name, content.Desc + "\n\nDo you want to buy ?", true, "buypowerup", this.gameObject);
                //gs.achievementManager.OnAchievementEvent(AchievementType.PowerPlay,1);
            }
            else
            {
                gs.ShowDialogBox("Info", "Not enough coins", false, "confirm", this.gameObject);
            }
        }
        else if (content.type == ShopContentType.Claw)
        {
            if (PlayerPrefs.HasKey("claw." + content.uniqueID) == false)
            {
                int gemucoins = GameManager.GEMUCOINS;
                if (gemucoins - content.Price >= 0)
                {
                    //currentShopContent = content;
                    //gs.ShowDialogBox(content.Name,content.Desc+"Do you want to buy ?",true,"buyclaw",this.gameObject);
                    PlayerPrefs.SetString("playerclaw", content.uniqueID);
                    gs.SetClaw(content.uniqueID);
                    RefreshClawStatus();
                }
                else
                {
                    //gs.ShowDialogBox("Info","Not enough GemuGold",false,"confirm",this.gameObject);
                }
            }
            else
            {
                PlayerPrefs.SetString("playerclaw", content.uniqueID);
                gs.SetClaw(content.uniqueID);
                RefreshClawStatus();
            }
        }
        else if (content.type == ShopContentType.Joystick)
        {
            if (PlayerPrefs.HasKey("joystick." + content.uniqueID) == false)
            {
                int gemucoins = GameManager.GEMUCOINS;
                if (gemucoins - content.Price >= 0)
                {
                    //currentShopContent = content;
                    //gs.ShowDialogBox(content.Name,content.Desc+"Do you want to buy ?",true,"buyjoystick",this.gameObject);
                    PlayerPrefs.SetString("playerjoy", content.uniqueID);
                    gs.SetJoystick(content.uniqueID);
                    RefreshJoystickStatus();
                }
                else
                {
                    //gs.ShowDialogBox("Info","Not enough GemuGold",false,"confirm",this.gameObject);
                }
            }
            else
            {
                PlayerPrefs.SetString("playerjoy", content.uniqueID);
                gs.SetJoystick(content.uniqueID);
                RefreshJoystickStatus();
            }
        }
        else if (content.type == ShopContentType.FreeCoin)
        {
            int gemucoins = GameManager.GEMUCOINS;
            if (gemucoins - content.Price >= 0)
            {
                currentShopContent = content;
                gs.ShowDialogBox(content.Name, "Do you want to buy ?", true, "buyenergy", this.gameObject);
            }
            else
            {
                gs.ShowDialogBox("Info", "Not enough GemuGold", false, "confirm", this.gameObject);
            }
        }
        else
        {
            gs.ShowNotImplemented();
        }

        PlayerPrefs.Save();
    }