Exemple #1
0
    public void UnlockClicked()
    {
        string buyId = "com.bombbrosinc.bombbros." + bros[selectedBro]; //Fix

        purchaser.BuyProductID(buyId);
    }
    // Use this for initialization
    void Start()
    {
        //
        this.purchaser = Purchaser.ins();//shop.gameObject.GetComponent<Purchaser>();
        // 图片
        if (type == ShopType.Item)
        {
            image.sprite = getSprite(id);
        }
        else
        {
            Object shopItemImageObj = Resources.Load("shopItemImage");
            int    index            = 0;
            if (type == ShopType.Unit)
            {
            }
            else if (type == ShopType.Peck)
            {
                addShopItemItem(Instantiate(shopItemImageObj) as GameObject, getGoldSprite(), goldNum, 10 + 80 * index++);
            }
            if (items != null && items.Count > 0)
            {
                foreach (KeyValuePair <int, int> kv in items)
                {
                    addShopItemItem(Instantiate(shopItemImageObj) as GameObject, getSprite(kv.Key), kv.Value, 10 + 80 * index++);
                }
            }
        }
        //
        Sprite spType = Resources.Load(getTypeImage(), typeof(Sprite)) as Sprite;

        typeImage.sprite = spType;
        if (typeImage2 != null)
        {
            typeImage2.sprite = spType;
        }

        //
        showPrice(1);
        //
        addNum.onClick.AddListener(delegate() {
            Sound.playSound(SoundType.Click);
            int num      = int.Parse(showNum.text) + 1;
            showNum.text = num.ToString();
            // 价格
            showPrice(num);
        });
        decNum.onClick.AddListener(delegate() {
            Sound.playSound(SoundType.Click);
            int num = int.Parse(showNum.text);
            if (num <= 1)
            {
                return;
            }
            num--;
            showNum.text = num.ToString();
            // 价格
            showPrice(num);
        });
        //
        buy.onClick.AddListener(delegate() {
            Debug.Log("do buy");
            Sound.playSound(SoundType.Click);
            // 前段进行一系列购买操作,付钱成功通知服务器加道具,然后服务器推送前端道具加成功或者数量,前端加道具
            // 买完回调

            if (type == ShopType.Item || type == ShopType.Unit)
            {
//				CSGold
                CSGoldBuy goldBuy = new CSGoldBuy();
                goldBuy.Type      = (int)type;
                goldBuy.Id        = id;
                goldBuy.Num       = int.Parse(showNum.text);
                SocketManager.SendMessageAsyc((int)MiGongOpcode.CSGoldBuy, CSGoldBuy.SerializeToBytes(goldBuy), delegate(int opcode, byte[] data) {
                    SCGoldBuy ret = SCGoldBuy.Deserialize(data);
                    shop.buyFinish(ret.Success > 0, (int)type, id, int.Parse(showNum.text), ret.Gold);
                });
            }
            else if (type == ShopType.Peck)
            {
                CSMoneyBuyBefore moneyBuyBefore = new CSMoneyBuyBefore();
                moneyBuyBefore.Id  = id;
                moneyBuyBefore.Num = int.Parse(showNum.text);
                SocketManager.SendMessageAsyc((int)MiGongOpcode.CSMoneyBuyBefore, CSMoneyBuyBefore.SerializeToBytes(moneyBuyBefore), delegate(int opcode, byte[] data) {
                    SCMoneyBuyBefore ret = SCMoneyBuyBefore.Deserialize(data);
                    if (ret.IsOk > 0)
                    {
                        // 支付
                        purchaser.BuyProductID(id.ToString());
                    }
                    else
                    {
                        Debug.Log(ret.Reason);
                        shop.buyFinish(false, (int)type, id, int.Parse(showNum.text), Params.gold);
                    }
                });
            }
        });
    }
Exemple #3
0
 public void BuyGas()
 {
     _purchaser.BuyProductID(kProductIDConsumable);
 }