public static void init(SCBaseInfo baseInfo) { gold = baseInfo.Gold; foreach (PBItemTable it in baseInfo.ItemTable) { ItemTable itemTable = new ItemTable(); itemTable.Id = it.Id; itemTable.ItemType = it.ItemType; itemTable.Para1 = it.Para1; itemTable.Para2 = it.Para2; itemTable.Price = it.Price; itemTables.Add(itemTable.Id, itemTable); } foreach (PBUnitTable ut in baseInfo.UnitTable) { UnitTable unitTable = new UnitTable(); unitTable.Id = ut.Id; string[] itemStrs = ut.Items.Split('|'); unitTable.Items = new Dictionary <int, int> (); foreach (string itemStr in itemStrs) { if (itemStr.Length == 0) { continue; } string[] strs = itemStr.Split(';'); unitTable.Items.Add(int.Parse(strs[0]), int.Parse(strs[1])); } unitTable.Price = ut.Price; unitTables.Add(unitTable.Id, unitTable); } foreach (PBPeckTable pt in baseInfo.PeckTable) { PeckTable peckTable = new PeckTable(); peckTable.Id = pt.Id; peckTable.gold = pt.Gold; peckTable.goldNum = pt.Gold; if (pt.Items != null && pt.Items.Length > 0) { peckTable.Items = new Dictionary <int, int> (); string[] itemStrs = pt.Items.Split('|'); peckTable.Items = new Dictionary <int, int> (); foreach (string itemStr in itemStrs) { if (itemStr.Length == 0) { continue; } string[] strs = itemStr.Split(';'); peckTable.Items.Add(int.Parse(strs[0]), int.Parse(strs[1])); } } peckTable.Price = pt.Price; peckTables.Add(peckTable.Id, peckTable); } }
// 买完回调 public void buyFinish(bool success, int shopType, int id, int num, int gold) { if (!success) { WarnDialog.showWarnDialog(Message.getText("buyFail")); return; } Params.gold = gold; goldText.text = Params.gold.ToString(); // WarnDialog.showWarnDialog("buy success,type = "+shopType+",itemId = "+id+",num = "+num); show.SetActive(true); ShopType type = (ShopType)shopType; if (type == ShopType.Item) // 道具用的时候是实时获得的,所以,啥都不做 { showItemByCount(1); showIn(id, num, 0); } else if (type == ShopType.Unit) // 道具用的时候是实时获得的,所以,啥都不做 { UnitTable unitTable = Params.unitTables[id]; showItemByCount(unitTable.Items.Count); int index = 0; foreach (KeyValuePair <int, int> kv in unitTable.Items) { showIn(kv.Key, kv.Value * num, index++); } } else if (type == ShopType.Peck) // { PeckTable peckTable = Params.peckTables[id]; if (peckTable.gold > 0) { Sprite sp = ShopItem.getGoldSprite(); showItemImage[0].sprite = sp; showItemText [0].text = "x" + (peckTable.gold * num); } int index = peckTable.gold > 0?1:0; foreach (KeyValuePair <int, int> kv in peckTable.Items) { showIn(kv.Key, kv.Value * num, index++); } showItemByCount(index); } }
// 礼包 private void initPeck() { showTabColor(ShopType.Peck); for (int i = 0; i < contentGo.transform.childCount; i++) { Destroy(contentGo.transform.GetChild(i).gameObject); } itemGo.Clear(); Dictionary <int, string> products = new Dictionary <int, string>(); foreach (PeckTable peckTable in Params.peckTables.Values) { products.Add(peckTable.Id, "s_" + peckTable.Price); } Purchaser.ins().InitializePurchasing(delegate(bool success) { if (success) { // Purchaser.ins().buyCallBack = buyCallBack; // Object shopItemObj = Resources.Load("shopItem3"); RectTransform contentTrans = contentGo.GetComponent <RectTransform>(); contentTrans.sizeDelta = new Vector2(0, 140 * Params.peckTables.Count); // goldMoneyRate ProductInfo onePi = Purchaser.ins().productInfos[1]; PeckTable onePt = Params.peckTables[1]; goldMoneyRate = onePi.price / onePt.goldNum; int index = 0; foreach (KeyValuePair <int, ProductInfo> pi in Purchaser.ins().productInfos) { PeckTable peckTable = Params.peckTables[pi.Key]; GameObject go = Instantiate(shopItemObj) as GameObject; ShopItem si = go.GetComponent <ShopItem>(); si.shop = this; si.type = ShopType.Peck; si.id = peckTable.Id; si.gold = peckTable.gold; si.goldNum = peckTable.goldNum; si.items = peckTable.Items; //Mathf. si.price = decimal.Round(calOriginPrice(peckTable.gold, peckTable.Items), 2); //si.price = calOriginPrice(peckTable.gold, peckTable.Items); si.price2 = decimal.Round(pi.Value.price, 2); //si.price2 = pi.Value.price;//peckTable.Price; si.isDiscount = true; go.transform.localPosition = new Vector3(0, -140 * index++, 0); go.transform.localScale = new Vector3(1, 1, 1); go.transform.SetParent(contentGo.transform, false); } //int index = 0; //foreach (PeckTable peckTable in Params.peckTables.Values) //{ // GameObject go = Instantiate(shopItemObj) as GameObject; // ShopItem si = go.GetComponent<ShopItem>(); // si.shop = this; // si.type = ShopType.Peck; // si.id = peckTable.Id; // si.gold = peckTable.gold; // si.goldNum = peckTable.goldNum; // si.items = peckTable.Items; // si.price = calOriginPrice(peckTable.gold, peckTable.Items); // si.price2 = peckTable.Price; // si.isDiscount = true; // go.transform.localPosition = new Vector3(0, -140 * index++, 0); // go.transform.localScale = new Vector3(1, 1, 1); // go.transform.SetParent(contentGo.transform, false); //} } }, products); }