Пример #1
0
        /// <summary>
        /// Initialize the Category
        /// </summary>
        /// <param name="_categoryData"></param>
        /// <param name="_subCategoryDotsZoneParent"></param>
        /// <param name="_scrollRect"></param>
        public void Initialize(CategoryData _categoryData, Transform _subCategoryDotsZoneParent, ScrollRect _scrollRect)
        {
            shopView           = ShopView.Instance;
            payments           = new List <Payment>();
            subCategoryVisuals = new List <SubCategoryVisual>();
            scrollRect         = (ScrollRectSwipe)_scrollRect;
            toggleGroup        = GetComponent <ToggleGroup>();
            layoutGroup        = GetComponent <LayoutGroup>();

//            List<SubCategoryDataServer> categoryDataServers = RemoteConfigManager.Instance.List<SubCategoryDataServer>();
//            categoryDataServers.AddRange(RemoteConfigManager.Instance.List<SubCategoryDataSkinServer>());
//            categoryDataServers.AddRange(RemoteConfigManager.Instance.List<SubCategoryDataBundleServer>());

            for (int i = 0; i < _categoryData.subCategories.Count; i++)
            {
                SubCategoryData subCategoryData = _categoryData.subCategories[i];
                if (subCategoryData != null)
                {
//                    SubCategoryDataServer categoryDataServer = categoryDataServers.Find(x => x.id == subCategoryData.id);
//                    if (categoryDataServer != null)
//                        subCategoryData.Initialize(categoryDataServer);

                    SubCategoryVisual subCategoryVisual = subCategoryData.AddSubCategory(transform);
                    subCategoryVisuals.Add(subCategoryVisual);
                    payments.Add(subCategoryData.payment);
                }
            }

            scrollRect.content = GetComponent <RectTransform>();

            UpdateToggleGroup(_categoryData);
            InitDots(_categoryData, _subCategoryDotsZoneParent);
        }
Пример #2
0
        /// <summary>
        /// Update the subCategory title
        /// </summary>
        public void UpdateSubCategoryTitle()
        {
            SubCategoryData subCategoryData = shop.GetCurrentSubCategoryData();

            if (titleText != null)
            {
                titleText.text = subCategoryData.title;
            }
        }
Пример #3
0
        /// <summary>
        /// Returns the data associated with the current sub category
        /// </summary>
        /// <returns></returns>
        public SubCategoryData GetCurrentSubCategoryData()
        {
            int categoryIndex    = shopView.GetCurrentCategoryIndex();
            int subCategoryIndex = shopView.GetCurrentSubCategoryIndex();

            SubCategoryData subCategoryData = shopData.categories[categoryIndex].subCategories[subCategoryIndex];

            return(subCategoryData);
        }
Пример #4
0
        private void Init()
        {
            subCategoryData = (SubCategoryData)target;

            Type        baseType   = typeof(Payment);
            List <Type> childTypes = AppDomain.CurrentDomain.GetAssemblies()
                                     .SelectMany(x => x.GetTypes())
                                     .Where(x => baseType.IsAssignableFrom(x) && !x.IsInterface && !x.IsAbstract)
                                     .ToList();

            paymentTypes     = childTypes.Select(x => x.AssemblyQualifiedName).ToArray();
            paymentTypeNames = childTypes.Select(x => x.ToString().Split('.').Last()).ToArray();
        }
Пример #5
0
 private void OnPurchaseRequested(SubCategoryData _subCategoryData, Payment _payment)
 {
     if (_subCategoryData is SubCategorySkinData subCategorySkinData)
     {
         List <Skin> remainingItems = subCategorySkinData.skins.FindAll(x => !x.IsCollected && x.enabled);
         PurchaseOrGoToNextSubCategory(remainingItems, _payment);
     }
     else if (_subCategoryData is SubCategoryBundleData subCategoryDataBundle)
     {
         List <Bundle> remainingItems = subCategoryDataBundle.bundles.FindAll(x => x.AmountAvailable > 0);
         PurchaseOrGoToNextSubCategory(remainingItems, _payment);
     }
 }
Пример #6
0
        private void InitDots(CategoryData _categoryData, Transform _subCategoryDotsZoneParent)
        {
            if (_subCategoryDotsZoneParent)
            {
                subCategoryDotZone = Instantiate(subCategoryDotPrefab, _subCategoryDotsZoneParent);
                subCategoryDotZone.SetActive(enableSubCategoryDots);
            }

            if (_categoryData.subCategories.Count > 0)
            {
                if (scrollRect)
                {
                    scrollRect.OnPageChanged += OnPageChanged;
                }

                subCategoryDotImages = new List <Image>();
            }

            if (_categoryData.subCategories.Count > 1 && subCategoryDotZone != null)
            {
                //Cache variables
                outlineSprite = Resources.Load <Sprite>("Outline");
                circleSprite  = Resources.Load <Sprite>("Circle");

                if (enableSubCategoryDots)
                {
                    //Add sub category number information (small dots)
                    for (int i = 0; i < _categoryData.subCategories.Count; i++)
                    {
                        SubCategoryData subCategory = _categoryData.subCategories[i];

                        if (subCategory == null)
                        {
                            continue;
                        }

                        if (enableSubCategoryDots)
                        {
                            InstantiateDotsImage(i);
                        }
                    }
                }
            }
            else
            {
                scrollRect.movementType = ScrollRect.MovementType.Clamped;
            }
        }
Пример #7
0
        /// <summary>
        /// Get a random available skin in _subCategoryDataSkin. (null if there is none)
        /// </summary>
        /// <param name="_skin"></param>
        /// <returns></returns>
        public SubCategorySkinData GetSubCategoryDataSkin(Skin _skin)
        {
            for (int i = 0; i < shopData.categories.Count; i++)
            {
                CategoryData category = shopData.categories[i];
                for (int j = 0; j < category.subCategories.Count; j++)
                {
                    SubCategoryData subCategory = category.subCategories[j];
                    if (subCategory is SubCategorySkinData subCategoryDataSkin && subCategoryDataSkin.skins.Contains(_skin))
                    {
                        return(subCategoryDataSkin);
                    }
                }
            }

            return(null);
        }
Пример #8
0
        //TODO : Modify the structure so that Sub Categories implement an interface IPurchasable saying that we can purchase item in it.
        /// <summary>
        /// Returns the index of the next sub category with purchasable elements inside.
        /// Returns -1 if there is none.
        /// </summary>
        /// <returns></returns>
        public int GetNextSubCategoryIndexWithCurrencyPurchasableElements()
        {
            int categoryIndex = shopView.GetCurrentCategoryIndex();

            List <SubCategoryData> subCategoryDatas = shopData.categories[categoryIndex].subCategories;

            subCategoryDatas = subCategoryDatas.FindAll(subCategory => subCategory.payment.GetType() == typeof(PaymentCurrency)).ToList();

            for (var i = subCategoryDatas.Count - 1; i >= 0; i--)
            {
                SubCategoryData subCategoryData = subCategoryDatas[i];

                if (subCategoryData is SubCategorySkinData subCategorySkinData)
                {
                    if (!subCategorySkinData.skins.Exists(item => !item.IsCollected))
                    {
                        subCategoryDatas.Remove(subCategorySkinData);
                    }
                }
                else if (subCategoryData is SubCategoryBundleData subCategoryBundleData)
                {
                    if (!subCategoryBundleData.bundles.Exists(bundle => bundle.AmountAvailable > 0))
                    {
                        subCategoryDatas.Remove(subCategoryBundleData);
                    }
                }
            }

            if (subCategoryDatas.Count > 0)
            {
//				subCategoryDatas = subCategoryDatas.OrderBy(x => (x.payment as PaymentCurrency).cost).ToList();

                int res = shopData.categories[categoryIndex].subCategories.IndexOf(subCategoryDatas[0]);
                return(res);
            }

            return(-1);
        }
Пример #9
0
        /// <summary>
        /// Display the chosen category _categoryData.
        /// Show the Shop if it's not visible.
        ///	Will automatically update the preview with the currently used skin.
        ///	Will directly move to the page corresponding to the skin's subcategory
        /// </summary>
        /// <param name="_categoryData"></param>
        public void ShowCategory(CategoryData _categoryData)
        {
            if (categories == null || _categoryData == null)
            {
                return;
            }

            bool isAlreadyInShop = m_Visible;

            if (!isAlreadyInShop)
            {
                Show();
            }

            for (var i = 0; i < categories.Count; i++)
            {
                CategoryVisual categoryVisual = categories[i];

                if (categoryVisual.name == _categoryData.name)
                {
                    categoryVisual.Show();
                }
                else
                {
                    categoryVisual.Hide();
                }
            }

            if (isAlreadyInShop)
            {
                if (shop.currentlyUsedSkins.ContainsKey(_categoryData))
                {
                    UpdateSkinPreview(shop.currentlyUsedSkins[_categoryData]);
                }
                else
                {
                    UpdateSkinPreview(null);
                }
            }

            int usedItemPageIndex = 0;

            for (var i = 0; i < _categoryData.subCategories.Count; i++)
            {
                SubCategoryData subCategoryData = _categoryData.subCategories[i];

                if (subCategoryData is SubCategorySkinData subCategorySkinData)
                {
                    if (subCategorySkinData.skins.Exists(skin => skin.IsUsed))
                    {
                        usedItemPageIndex = i;
                        break;
                    }
                }
                else if (subCategoryData is SubCategoryBundleData subCategoryBundleData)
                {
                    //TODO
                }
            }

            scrollRect.ChangePage(usedItemPageIndex, true);
        }
Пример #10
0
        /// <summary>
        /// Request a purchase for a random element in the current sub category.
        /// Fires the OnPurchaseRequested event.
        /// </summary>
        public void RequestPurchase()
        {
            SubCategoryData currentSubCategoryData = GetCurrentSubCategoryData();

            OnPurchaseRequested?.Invoke(currentSubCategoryData, currentSubCategoryData.payment);
        }