public ResourceModel Map(PurchaseModel purchaseModel) { ResourceModel resourceModel = new ResourceModel(); switch (purchaseModel.productModel.ResourceTypeEnum) { case ResourceTypeEnum.WarshipPowerPoints: WarshipPowerPointsProductModel wppModel = purchaseModel.productModel; resourceModel.ResourceTypeEnum = ResourceTypeEnum.WarshipPowerPoints; if (wppModel.WarshipTypeEnum == 0) { throw new Exception("В модели продукта не указан тип корабля"); } resourceModel.SerializedModel = ZeroFormatterSerializer.Serialize( new WarshipPowerPointsResourceModel() { WarshipId = wppModel.WarshipId, WarshipSkinName = null, StartValue = wppModel.SupportClientModel.StartValue, FinishValue = wppModel.SupportClientModel.StartValue + wppModel.Increment, MaxValueForLevel = wppModel.SupportClientModel.MaxValueForLevel, WarshipTypeEnum = wppModel.WarshipTypeEnum }); break; case ResourceTypeEnum.SoftCurrency: SoftCurrencyProductModel softModel = purchaseModel.productModel; resourceModel.ResourceTypeEnum = ResourceTypeEnum.SoftCurrency; resourceModel.SerializedModel = ZeroFormatterSerializer.Serialize( new SoftCurrencyResourceModel() { Amount = softModel.Amount }); break; case ResourceTypeEnum.HardCurrency: HardCurrencyProductModel hardModel = purchaseModel.productModel; resourceModel.ResourceTypeEnum = ResourceTypeEnum.HardCurrency; resourceModel.SerializedModel = ZeroFormatterSerializer.Serialize( new HardCurrencyResourceModel() { Amount = hardModel.Amount }); break; default: throw new ArgumentOutOfRangeException(); } return(resourceModel); }
public void Spawn(PurchaseModel purchaseModel, GameObject sectionGameObject, ProductClickHandlerScript productClickHandlerScript) { var costModel = ZeroFormatterSerializer.Deserialize <RealCurrencyCostModel>(purchaseModel.productModel.CostModel.SerializedCostModel); HardCurrencyProductModel hardCurrencyProductModel = purchaseModel.productModel; //Создать объект на сцене GameObject premiumCurrencyItemPrefab = Resources .Load <GameObject>("Prefabs/LobbyShop/Image_PremiumCurrencyItem"); GameObject premiumCurrencyItemGameObject = Object.Instantiate(premiumCurrencyItemPrefab, sectionGameObject.transform, false); //Заполнить картинку Image itemPreview = premiumCurrencyItemGameObject.transform.Find("Image_ItemPreview") .GetComponentInChildren <Image>(); itemPreview.sprite = Resources.Load <Sprite>(purchaseModel.productModel.PreviewImagePath); //Заполнить цену Text itemCost = premiumCurrencyItemGameObject.transform.Find("Image_Cost/Text_Amount").GetComponent <Text>(); if (costModel.CostString != null) { itemCost.text = costModel.CostString.ToString(CultureInfo.InvariantCulture); } else { itemCost.text = "undefined"; } //Заполнить название Text itemName = premiumCurrencyItemGameObject.transform.Find("Image_ItemPreview/Text_ItemName").GetComponent <Text>(); itemName.text = hardCurrencyProductModel.Amount.ToString(); //Установить обработчик нажатия Button itemButton = premiumCurrencyItemGameObject.GetComponent <Button>(); itemButton.onClick.RemoveAllListeners(); itemButton.onClick.AddListener(() => { productClickHandlerScript.Product_OnClick(purchaseModel); }); }