Exemple #1
0
 private void handleAbilityUpdated(IAPAbility ability)
 {
     if (ability.uid == this.uid)
     {
         IAPUIUtility.UpdateLabelText(gameObject, GetText(ability, textType));
     }
 }
Exemple #2
0
 private void handleInventoryUpdated(IAPInventory inventory)
 {
     if (inventory.uid == this.uid)
     {
         IAPUIUtility.UpdateLabelText(gameObject, GetText(inventory, textType));
     }
 }
Exemple #3
0
        private void handleCurrencyUpdated(IAPCurrency currency)
        {
            //Debug.Log("handleCurrencyUpdated: " + currency.uid + " value: " + currency.amount);
            if (currency.uid == this.uid)
            {
                if ((textType == IAPTextType.price || textType == IAPTextType.amount))
                {
                    int result = 0;
                    if (textType == IAPTextType.price)
                    {
                        result = currency.price;
                    }
                    else if (textType == IAPTextType.amount)
                    {
                        result = currency.amount;
                    }

                    if (animated && _lastNumber != result)
                    {
                        startCountTo(result);
                        _lastNumber = result;
                    }
                    else
                    {
                        IAPUIUtility.UpdateLabelText(gameObject, GetText(currency, textType));
                    }
                }
                else
                {
                    IAPUIUtility.UpdateLabelText(gameObject, GetText(currency, textType));
                }
            }
        }
Exemple #4
0
 private void handlePackageUpdated(IAPPackage package)
 {
     if (package.uid == this.uid)
     {
         IAPUIUtility.UpdateLabelText(gameObject, GetText(package, textType));
     }
 }
Exemple #5
0
        // Use this for initialization
        void Start()
        {
            if (uid != null)
            {
                IAPObject obj = null;

                //
                if (targetType == IAPType.Inventory)
                {
                    obj = IAPInventoryManager.GetInventory(uid);
                }
                else if (targetType == IAPType.Currency)
                {
                    obj = IAPInventoryManager.GetCurrency(uid);
                }

                if (obj != null)
                {
                    UpdateTemplate(obj);

                    // Update text
                    Text[] txts = gameObject.GetComponentsInChildren <Text>();
                    // InAppPurchase
                    foreach (Text txt in txts)
                    {
                        if (txt.name == "amount_consume")
                        {
                            txt.text = amount.ToString();
                        }
                    }

                    IAPUIUtility.AddButtonCallback(
                        gameObject, (GameObject go) => {
                        if (useConfirmDialog)
                        {
                            // Construct confirm msg
                            string msg = IAPInventoryManager.uiSettings.consumeConfirmString.Replace("%title%", obj.title);
                            msg        = msg.Replace("%description%", obj.description);
                            msg        = msg.Replace("%amount_consume%", amount.ToString());
                            // Show confirm diaglog
                            IAPInventoryManager.ShowConfirmDialog(msg,
                                                                  delegate(IAPDialog diag){
                                if (obj.Consume(amount))
                                {
                                    UpdateTemplate(obj);
                                }
                            }
                                                                  );
                        }
                        else
                        {
                            obj.Consume(amount);
                        }
                    }
                        );
                }
            }
        }
Exemple #6
0
        protected IEnumerator doCountTo(int target)
        {
            int start = _lastNumber;

            for (float timer = 0; timer <= animationTime; timer += Time.deltaTime)
            {
                float progress = timer / animationTime;
                int   score    = (int)Mathf.Lerp(start, target, progress);
                IAPUIUtility.UpdateLabelText(gameObject, score.ToString());
                yield return(null);
            }
            _lastNumber = target;
            IAPUIUtility.UpdateLabelText(gameObject, _lastNumber.ToString());
        }
Exemple #7
0
        // Helper for animated text

        private void startCountTo(int result)
        {
            try{
                if (isActiveAndEnabled)
                {
                    StopCoroutine("doCountTo");
                    StartCoroutine("doCountTo", result);
                }
                else
                {
                    IAPUIUtility.UpdateLabelText(gameObject, result.ToString());
                }
            } catch (Exception e) {
                Debug.Log(e);
            }
        }
        private void handlePackageUpdated(IAPPackage package)
        {
            if (package.product == null && package.product.id == this.uid)
            {
                // Update template
//				Debug.LogFormat("handlePackageUpdated {0} type {1} amount {2} hasReceipt {3} {4}",uid,package.productType,package.amount,package.product.hasReceipt,package.product.rawProduct.hasReceipt);
                // To enable/disable button
                if (package.productType == IAPProductType.NonConsumable && package.product.hasReceipt)
                {
                    if (package.amount <= 0)
                    {
                        package.Refill(1);                                     // Add 1 if no
                    }
                    IAPUIUtility.SetButtonEnabled(gameObject, false, "purchase_button");
                }
                else if (package.productType == IAPProductType.Subscription && package.product.hasReceipt)
                {
                    if (package.amount <= 0)
                    {
                        package.Refill(1);                                     // Add 1 if no
                    }
                    package.Unlock();
                    IAPUIUtility.SetButtonEnabled(gameObject, false, "purchase_button");
                }
                else if ((package.productType == IAPProductType.NonConsumable && package.amount > 0))
                {
                    IAPUIUtility.SetButtonEnabled(gameObject, false, "purchase_button");
                }
                else
                {
                    IAPUIUtility.SetButtonEnabled(gameObject, true, "purchase_button");
                    IAPUIUtility.AddButtonCallback(gameObject, (GameObject go) => {
                        IAPUIUtility.SetButtonEnabled(gameObject, false, "purchase_button");
                        package.Purchase(handlePackageUpdated);
                    }, "purchase_button");
                }

                UpdateTemplate(package);
            }
        }
 // Use this for initialization
 void Start()
 {
     IAPUIUtility.AddButtonCallback(
         gameObject, (GameObject go) => {
         if (go.name == "confirm_button")
         {
             if (OnConfirmButtonPressed != null)
             {
                 OnConfirmButtonPressed(this);
             }
         }
         else if (go.name == "cancel_button")
         {
             if (OnCancelButtonPressed != null)
             {
                 OnCancelButtonPressed(this);
             }
         }
         Destroy(gameObject);
     }
         );
 }
Exemple #10
0
        protected void UpdateTemplate(IAPObject obj)
        {
            if (obj != null)
            {
                // Update images
                Image[] imgs = gameObject.GetComponentsInChildren <Image>();
                foreach (Image img in imgs)
                {
                    if (img.name == "icon" && obj.icon != null)
                    {
                        img.sprite = obj.icon;
                    }
                    else if (obj is IAPInventory && img.name == "lock_icon")
                    {
                        IAPInventory obji = (IAPInventory)obj;
                        img.gameObject.SetActive(obji.isLocked());
                    }
                    else if (obj is IAPInventory && img.name == "unlock_icon")
                    {
                        IAPInventory obji = (IAPInventory)obj;
                        img.gameObject.SetActive(!obji.isLocked());
                    }
                    else if (img.name == "currency_icon")
                    {
                        IAPCurrency currency = IAPInventoryManager.GetCurrency(obj.currency);
                        if (currency != null && currency.icon != null)
                        {
                            img.sprite = currency.icon;
                        }
                    }
                    else if (img.name == "level")
                    {
                        if (targetType == IAPType.Ability)
                        {
                            IAPAbilityLevel lv = (obj as IAPAbility).GetCurrentLevel();
                            if (lv != null && lv.icon != null)
                            {
                                img.sprite = lv.icon;
                            }
                        }
                    }
                }

                // For inventory
                if (obj is IAPInventory)
                {
                    IAPInventory inventory = obj as IAPInventory;
                    bool         locked    = inventory.isLocked();

                    Text[] inventoryText = gameObject.GetComponentsInChildren <Text>();
                    Debug.Log("UPDATE Tempate: " + uid + " obj: " + inventoryText.Length);
                    foreach (Text txt in inventoryText)
                    {
                        string name = txt.name.ToLower();
                        Debug.Log("UPDATE Text: " + name + " locked: " + locked);
                        if (name.StartsWith("locked"))
                        {
                            txt.enabled = locked;
                        }
                        else if (name.StartsWith("unlocked"))
                        {
                            txt.enabled = !locked;
                        }
                    }

                    Button[] inventoryBtns = gameObject.GetComponentsInChildren <Button>();
                    foreach (Button btn in inventoryBtns)
                    {
                        string name = btn.name.ToLower();
                        Debug.Log("UPDATE button: " + name + " locked: " + locked);
                        if (name.StartsWith("locked"))
                        {
                            btn.enabled = locked;
                        }
                        else if (name.StartsWith("unlocked"))
                        {
                            btn.enabled = !locked;
                        }
                    }

                    if (inventory.isLocked())
                    {
                        IAPUIUtility.SetButtonActive(true, gameObject, "locked_button");
                        IAPUIUtility.SetButtonActive(false, gameObject, "unlocked_button");
                    }
                    else
                    {
                        IAPUIUtility.SetButtonActive(false, gameObject, "locked_button");
                        IAPUIUtility.SetButtonActive(true, gameObject, "unlocked_button");
                    }
                }

                // Update text
                Text[] txts = gameObject.GetComponentsInChildren <Text>();
                // InAppPurchase
                if (targetType == IAPType.InAppPurchase)
                {
                    IAPPackage package = (obj as IAPPackage);
                    foreach (Text txt in txts)
                    {
                        string name = txt.name.ToLower();
                        if (name.StartsWith("content_"))
                        {
                            string[] ss = name.Split('_');
                            if (ss.Length == 3)
                            {
                                IAPPackageContent cc = package.GetContent(ss[1]);
                                if (cc != null)
                                {
                                    if (ss[2] == "amount")
                                    {
                                        txt.text = cc.amount.ToString();
                                    }
                                    else
                                    {
                                        UpdateTextWithObject(txt, cc.obj, ss[2]);
                                    }
                                }
                            }
                        }
                        else if (package.fetchFromStore)
                        {
                            UpdateTextWithPackage(txt, package);
                        }
                        else
                        {
                            UpdateTextWithObject(txt, obj, name);
                        }
                    }
                    // Ability
                }
                else if (targetType == IAPType.Ability)
                {
                    IAPAbility ability = (obj as IAPAbility);
                    foreach (Text txt in txts)
                    {
                        string name = txt.name.ToLower();
                        if (name == "price")
                        {
                            if (ability.isLocked() && ability.lockedString != null && ability.lockedString != "")
                            {
                                txt.text = ability.lockedString;
                            }
                            else
                            {
                                IAPAbilityLevel lv = ability.GetCurrentLevel();
                                if (lv != null)
                                {
                                    if (ability.level == ability.levels.Count - 1 && ability.maxString != null && ability.maxString != "")
                                    {
                                        txt.text = ability.maxString;
                                    }
                                    else
                                    {
                                        txt.text = lv.price.ToString();
                                    }
                                }
                            }
                        }
                        else
                        {
//							Debug.Log("text " + txt + " name: " + name);
                            UpdateTextWithObject(txt, obj, name);
                        }
                    }
                }
                else
                {
                    foreach (Text txt in txts)
                    {
                        UpdateTextWithObject(txt, obj, txt.name);
                    }
                }
            }
        }
Exemple #11
0
        // Use this for initialization
        void Start()
        {
            // hide the background
            Image background = gameObject.GetComponent <Image>();

            if (background != null)
            {
                background.enabled = false;
            }

            // Add item to viewport content
//			if(searchTag != null && searchTag != "")
//			if(searchTag != 0)
//			{
            if (itemType == IAPType.Inventory)
            {
                List <IAPInventory> inventoryList = IAPInventoryManager.GetInventoryListByTags(searchTag);

                if (inventoryList != null && itemTemplate != null)
                {
                    DoLayout(inventoryList.Count);
                    foreach (IAPInventory inventory in inventoryList)
                    {
                        GameObject  obj = Instantiate(itemTemplate);
                        IAPTemplate btn = obj.GetComponent <IAPTemplate>();
                        if (btn == null)
                        {
                            btn = obj.AddComponent <IAPTemplate>();
                        }

                        btn.targetType       = IAPType.Inventory;
                        btn.uid              = inventory.uid;
                        btn.useConfirmDialog = useConfirmDialog;
                        obj.transform.SetParent(_listView.transform);
                        obj.transform.localScale = new Vector3(1, 1, 1);
                    }
                }
            }
            else if (itemType == IAPType.InAppPurchase)
            {
                List <IAPPackage> packageList = IAPInventoryManager.GetPackageListByTags(searchTag);

                if (packageList != null && itemTemplate != null)
                {
                    DoLayout(packageList.Count);
                    foreach (IAPPackage package in packageList)
                    {
//							Debug.Log("package " + package.uid + " type: ");
                        GameObject  obj = Instantiate(itemTemplate);
                        IAPTemplate btn = obj.GetComponent <IAPTemplate>();
                        if (btn == null)
                        {
                            btn = obj.AddComponent <IAPTemplate>();
                        }

                        btn.targetType       = IAPType.InAppPurchase;
                        btn.uid              = package.uid;
                        btn.useConfirmDialog = useConfirmDialog;
                        obj.transform.SetParent(_listView.transform);
                        obj.transform.localScale = new Vector3(1, 1, 1);
                    }
                }
            }
            else if (itemType == IAPType.Ability)
            {
                List <IAPAbility> abilityList = IAPInventoryManager.GetAbilityListByTags(searchTag);
//					Debug.Log("abilityList: " + abilityList + " count : " + abilityList.Count);
                if (abilityList != null && itemTemplate != null)
                {
                    DoLayout(abilityList.Count);
                    foreach (IAPAbility ability in abilityList)
                    {
                        GameObject  obj = Instantiate(itemTemplate);
                        IAPTemplate btn = obj.GetComponent <IAPTemplate>();
                        if (btn == null)
                        {
                            btn = obj.AddComponent <IAPTemplate>();
                        }

                        btn.targetType       = IAPType.Ability;
                        btn.uid              = ability.uid;
                        btn.useConfirmDialog = useConfirmDialog;
                        obj.transform.SetParent(_listView.transform);
                        obj.transform.localScale = new Vector3(1, 1, 1);
                    }
                }
            }
            else if (itemType == IAPType.GameLevel)
            {
                IAPGameLevel gameLevel = IAPInventoryManager.GetGameLevel(uid);
                Debug.Log("GameLevel " + uid);
                if (gameLevel != null && itemTemplate != null)
                {
                    Debug.Log("GameLevel " + gameLevel.levels.Count);
                    DoLayout(gameLevel.levels.Count);
                    for (int i = 0; i < gameLevel.levels.Count; i++)
                    {
                        GameObject  obj = Instantiate(itemTemplate);
                        IAPTemplate btn = obj.GetComponent <IAPTemplate>();
                        if (btn == null)
                        {
                            btn = obj.AddComponent <IAPTemplate>();
                        }

                        btn.targetType       = IAPType.GameLevel;
                        btn.uid              = gameLevel.uid;
                        btn.level            = i;
                        btn.useConfirmDialog = useConfirmDialog;
                        obj.transform.SetParent(_listView.transform);
                        obj.transform.localScale = new Vector3(1, 1, 1);

                        // Add Events
                        IAPUIUtility.AddButtonCallback(obj, (GameObject go) => {
                            IAPGameSubLevel lv = gameLevel.levels[btn.level];
                            bool islocked      = false;
                            islocked           = (gameLevel.GetPropertyValue("locked", btn.level) > 0);
                            Debug.LogFormat("Lock {0}", islocked);
                            // if(gameLevel.isLocked()){
                            islocked = (gameLevel.GetPropertyValue("locked", btn.level) > 0);
                            // }
                            lv.locked = islocked;
                            // if(islocked&&lv.price>0){

                            // } else {
                            if (OnGameLevelSelect != null)
                            {
                                OnGameLevelSelect.Invoke(gameLevel, btn.level);
                            }
                            // }
                        }, "self,select_button");
                    }
                }
            }
//			}
        }
        // Use this for initialization
        void Start()
        {
            if (uid != null)
            {
                // Purchase button action
                System.Action <GameObject> purchaseButtonCallback = null;

                //
                if (targetType == IAPType.Currency)
                {
                    IAPCurrency obj = IAPInventoryManager.GetCurrency(uid);

                    if (obj != null)
                    {
                        UpdateTemplate(obj);
                        IAPInventoryManager.OnCurrencyUpdated += handleCurrencyUpdated;
                        purchaseButtonCallback = (GameObject go) => {
                            handleButtonCallback(obj);
                        };
                    }
                }
                else if (targetType == IAPType.Inventory)
                {
                    IAPInventory obj = IAPInventoryManager.GetInventory(uid);

                    if (obj != null)
                    {
                        Debug.Log("UpdateTemplate " + obj.uid);
                        UpdateTemplate(obj);

                        IAPInventoryManager.OnInventoryUpdated += handleInventoryUpdated;
                        // Debug.Log("obj.available: " + obj.available);
                        // Check if inventory available
                        // if(obj.available==0){
                        //  IAPUIUtility.SetButtonActive(false,gameObject,"purchase_button");
                        // } else {
                        purchaseButtonCallback = (GameObject go) => {
                            // Debug.Log("213123");
                            handleButtonCallback(obj);
                        };
                        // }
                    }
                }
                else if (targetType == IAPType.Ability)
                {
                    IAPAbility obj = IAPInventoryManager.GetAbility(uid);

                    if (obj != null)
                    {
                        UpdateTemplate(obj);

                        IAPInventoryManager.OnAbilityUpdated += handleAbilityUpdated;
                        IAPAbility ability = (obj as IAPAbility);
                        if (ability.level < ability.levels.Count - 1)
                        {
                            // Get the currency
                            IAPCurrency currency = IAPInventoryManager.GetCurrency(obj.currency);
                            purchaseButtonCallback = (GameObject go) => {
                                if (useConfirmDialog)
                                {
                                    if (currency != null)
                                    {
                                        // Construct confirm msg
                                        IAPAbilityLevel lv  = ability.GetCurrentLevel();
                                        string          msg = IAPInventoryManager.uiSettings.abilityConfirmString.Replace("%title%", obj.title);
                                        msg = msg.Replace("%description%", lv.description.ToString());
                                        msg = msg.Replace("%price%", lv.price.ToString());
                                        msg = msg.Replace("%currency_title%", currency.title);
                                        msg = msg.Replace("%currency_description%", currency.description);
                                        // Show confirm diaglog
                                        IAPInventoryManager.ShowConfirmDialog(msg,
                                                                              delegate(IAPDialog diag){
                                            ability.Upgrade();
                                        }
                                                                              );
                                    }
                                }
                                else
                                {
                                    // Purchase the package
                                    ability.Upgrade();
                                }
                            };
                        }
                        else
                        {
                            // Disable the button
                            IAPUIUtility.SetButtonEnabled(gameObject, false);
                        }
                    }
                }
                else if (targetType == IAPType.InAppPurchase)
                {
                    IAPPackage obj = IAPInventoryManager.GetPackage(uid);

                    if (obj != null)
                    {
                        // UpdateTemplate(obj);

                        // if((obj.productType==IAPProductType.NonConsumable || obj.productType==IAPProductType.Subscription) && obj.amount>0)
                        // {
                        //  IAPUIUtility.SetButtonEnabled(gameObject,false,"purchase_button");

                        // } else {

                        if (obj.fetchFromStore)
                        {
                            // For Real Money IAP

                            IAPInventoryManager.OnIAPInitialized += handleOnIAPInitialized;

                            // Check if IAP initialized
                            if (IAPManager.IsInitialized())
                            {
                                Debug.LogFormat("uid: {0} type: {1}  amount: {2}", uid, obj.productType, obj.amount);

                                if ((obj.productType == IAPProductType.NonConsumable || obj.productType == IAPProductType.Subscription) && obj.amount > 0)
                                {
                                    IAPUIUtility.SetButtonEnabled(gameObject, false, "purchase_button");
                                }
                                else
                                {
                                    purchaseButtonCallback = (GameObject go) => {
                                        IAPUIUtility.SetButtonEnabled(gameObject, false, "purchase_button");
                                        obj.Purchase(handlePackageUpdated);
                                    };
                                }
                            }
                            else
                            {
                                IAPUIUtility.SetButtonEnabled(gameObject, false, "purchase_button");
                                IAPInventoryManager.InitIAPManager();
                            }
                        }
                        else
                        {
                            // For Virtual Currency IAP

                            purchaseButtonCallback = (GameObject go) => {
                                if (useConfirmDialog)
                                {
                                    // Construct confirm msg
                                    IAPCurrency currency = IAPInventoryManager.GetCurrency(obj.currency);
                                    if (currency != null)
                                    {
                                        string msg = IAPInventoryManager.uiSettings.iapConfirmString.Replace("%title%", obj.title);
                                        msg = msg.Replace("%description%", obj.description);
                                        msg = msg.Replace("%price%", obj.price.ToString());
                                        msg = msg.Replace("%currency_title%", currency.title);
                                        msg = msg.Replace("%currency_description%", currency.description);
                                        // Show confirm diaglog
                                        IAPInventoryManager.ShowConfirmDialog(msg,
                                                                              delegate(IAPDialog diag){
                                            // Purchase the package
                                            obj.Purchase();
                                        }
                                                                              );
                                    }
                                }
                                else
                                {
                                    // Purchase the package
                                    obj.Purchase();
                                }
                            };
                        }
                        // }

                        UpdateTemplate(obj);
                    }
                }
                else if (targetType == IAPType.GameLevel && level != -1)
                {
                    IAPGameLevel obj = IAPInventoryManager.GetGameLevel(uid);
                    IAPInventoryManager.OnGameLevelUpdated += handleGameLevelUpdated;

                    if (obj != null)
                    {
                        UpdateGameLevelTemplate(obj, level);

                        // IAPCurrency currency = IAPInventoryManager.GetCurrency(obj.currency);
// Debug.LogFormat("obj {0}",level);

                        // purchaseButtonCallback=(GameObject go)=>{
                        IAPUIUtility.AddButtonCallback(gameObject, (GameObject go) => {
                            IAPGameSubLevel subLevel = obj.levels[level];
                            bool islocked            = (obj.GetPropertyValue("locked", level) > 0);
                            // Debug.LogFormat("obj {0} {1} {2}", level, useConfirmDialog, obj.currency);

                            // Check if price valid and
                            if (subLevel.price > 0 && islocked)
                            {
                                if (useConfirmDialog)
                                {
                                    // Construct confirm msg
                                    IAPCurrency currency = IAPInventoryManager.GetCurrency(obj.currency);
                                    if (currency != null)
                                    {
                                        string msg = IAPInventoryManager.uiSettings.iapConfirmString.Replace("%title%", obj.title);
                                        msg        = msg.Replace("%description%", obj.description + " Level " + level.ToString());
                                        msg        = msg.Replace("%price%", subLevel.price.ToString());
                                        msg        = msg.Replace("%currency_title%", currency.title);
                                        msg        = msg.Replace("%currency_description%", currency.description);
                                        // Show confirm diaglog
                                        IAPInventoryManager.ShowConfirmDialog(msg,
                                                                              delegate(IAPDialog diag){
                                            // Check if enough currency
                                            if (currency != null && currency.Consume(subLevel.price))
                                            {
                                                // obj.SetPropertyValue("locked",level,1);
                                                obj.UnlockLevel(level);
                                            }
                                        }
                                                                              );
                                    }
                                }
                                else
                                {
                                    // Get the currency
                                    IAPCurrency currency = IAPInventoryManager.GetCurrency(obj.currency);
                                    // Check if enough currency
                                    if (currency != null && currency.Consume(subLevel.price))
                                    {
                                        obj.UnlockLevel(level);
                                    }
                                }
                            }
                        }, "self,select_button");
                    }
                }

                // Add the button callback to purchase_button
                if (purchaseButtonCallback != null)
                {
                    IAPUIUtility.AddButtonCallback(gameObject, purchaseButtonCallback, "purchase_button");
                }
            }
        }