private void FillData(GameObject softCurrencyContent, ProductModel productModel) { if (productModel.IsDisabled) { throw new Exception("Обычную валюту нельзя выключать."); } SoftCurrencyProductModel softCurrencyProductModel = productModel; var costModel = ZeroFormatterSerializer.Deserialize <InGameCurrencyCostModel>(productModel.CostModel .SerializedCostModel); //установить картинку Image image = softCurrencyContent.transform.Find("Image_ItemPreviewBg/Image_ItemPreview") .GetComponent <Image>(); image.sprite = Resources.Load <Sprite>(productModel.PreviewImagePath); //установить прибавляемое кол-во товара Text textLabel = softCurrencyContent.transform.Find("Image_ItemPreviewBg/Image_ItemPreview/Text_Label") .GetComponent <Text>(); textLabel.text = softCurrencyProductModel.Amount.ToString(); //установить описание Text description = softCurrencyContent.transform.Find("Text_Description").GetComponent <Text>(); description.text = $"Coins: { softCurrencyProductModel.Amount}. Use coins to improve warships."; //установить цену Text cost = softCurrencyContent.transform.Find("Button_Buy/Text_Cost").GetComponent <Text>(); cost.text = costModel.Cost.ToString(CultureInfo.InvariantCulture); //TODO сделать установку типа валюты }
public List <Increment> Create(ProductModel productModel) { List <Increment> increments = new List <Increment>(); SoftCurrencyProductModel model = productModel; Increment increment = new Increment() { IncrementTypeId = IncrementTypeEnum.SoftCurrency, Amount = model.Amount }; increments.Add(increment); return(increments); }
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 <InGameCurrencyCostModel>(purchaseModel.productModel.CostModel.SerializedCostModel); SoftCurrencyProductModel model = purchaseModel.productModel; //Создать объект на сцене GameObject regularCurrencyItemPrefab = Resources .Load <GameObject>("Prefabs/LobbyShop/Image_RegularCurrencyItem"); GameObject regularCurrencyItemGameObject = Object.Instantiate(regularCurrencyItemPrefab, sectionGameObject.transform, false); //Заполнить картинку Image itemPreview = regularCurrencyItemGameObject.transform.Find("Image_ItemPreview") .GetComponentInChildren <Image>(); itemPreview.sprite = Resources.Load <Sprite>(purchaseModel.productModel.PreviewImagePath); //Заполнить цену Text itemCost = regularCurrencyItemGameObject.transform.Find("Image_Cost/Text_Amount").GetComponent <Text>(); itemCost.text = costModel.Cost.ToString(CultureInfo.InvariantCulture); //Заполнить название Text itemName = regularCurrencyItemGameObject.transform.Find("Image_ItemPreview/Text_ItemName").GetComponent <Text>(); itemName.text = model.Amount.ToString(); //Установить обработчик нажатия Button itemButton = regularCurrencyItemGameObject.GetComponent <Button>(); itemButton.onClick.RemoveAllListeners(); itemButton.onClick.AddListener(() => { productClickHandlerScript.Product_OnClick(purchaseModel); }); }