private static bool HasSameIapContent(CocoStoreItem item1, CocoStoreItem item2)
        {
            if (item1.productId == item2.productId)
            {
                return(true);
            }

            if (item1.itemIdString == item2.itemIdString)
            {
                return(true);
            }

            if (!string.IsNullOrEmpty(item1.iosIapString) && item1.iosIapString == item2.iosIapString)
            {
                return(true);
            }

            if (!string.IsNullOrEmpty(item1.gpIapString) && item1.gpIapString == item2.gpIapString)
            {
                return(true);
            }

            if (!string.IsNullOrEmpty(item1.amIapString) && item1.amIapString == item2.amIapString)
            {
                return(true);
            }

            return(false);
        }
Example #2
0
        //通过GameProductId 判断是否已经购买, 优先判断最大包
        public bool IsPurchasedByProductId(CocoStoreID pId)
        {
            CocoStoreItem pStoreItem = GetStoreItemById(pId);

            if (pStoreItem == null)
            {
                Debug.LogError("There is no CocoStoreItem for the product. Please check !(该商品不存在,检查设置): " + pId);
                return(false);
            }

            return(inventoryStateModel.HasItem(pStoreItem.iosIapString) || billingService.IsPurchased(iapConfigModel.GetIAPId(pStoreItem.iosIapString)));
        }
Example #3
0
        //购买一个商品。(会设置关联数据)
        public void PurchasedProduct(CocoStoreID pId)
        {
            CocoStoreItem pStoreItem = GetStoreItemById(pId);

            if (pStoreItem == null)
            {
                Debug.LogError("There is no CocoStoreItem for the product. Please check !(该商品不存在,检查设置): " + pId);
                return;
            }

            inventoryStateModel.SetQuantity(pStoreItem.iosIapString, 1);

            //Unlock all related store iap items
            //解锁相关联的商品
            for (int i = 0; i < pStoreItem.relatedStoreItems.Count; i++)
            {
                CocoStoreItem pRelatedItem = GetStoreItemById(pStoreItem.relatedStoreItems [i]);

                if (pStoreItem == null)
                {
                    Debug.LogError("There is no CocoStoreItem for the product. Please check !(该商品不存在,检查设置): " + pStoreItem.relatedStoreItems [i]);
                    continue;
                }

                inventoryStateModel.SetQuantity(pRelatedItem.iosIapString, 1);
            }

            foreach (CocoStoreItem pItem in CocoStoreData.Instance.allProductItems)
            {
                if (pItem.productId == pId)
                {
                    continue;
                }

                bool pAllRelatedItemsUnlocked = pItem.relatedStoreItems.Count > 0 ? true : false;
                for (int i = 0; i < pItem.relatedStoreItems.Count; i++)
                {
                    if (!IsPurchasedByProductId(pItem.relatedStoreItems [i]))
                    {
                        pAllRelatedItemsUnlocked = false;
                        break;
                    }
                }

                if (pAllRelatedItemsUnlocked)
                {
                    inventoryStateModel.SetQuantity(pItem.iosIapString, 1);
                }
            }
        }
        private bool EditCocoStoreItem(int pIndex)
        {
            bool pIsRemoveData = false;

            CocoStoreItem pStoreItem = CocoStoreData.Instance.allProductItems [pIndex];

            var box = EditorGUILayout.BeginVertical(GUI.skin.box);

            Rect pRect = new Rect(box.xMax - 110, box.yMin + 2, 50, 15);
            //按照总部的商品id的套路自动填写
            bool isAuto = GUI.Button(pRect, "Auto");

            pRect = new Rect(box.xMax - 50, box.yMin + 2, 50, 15);
            if (GUI.Button(pRect, "X"))
            {
                pIsRemoveData = true;
            }

            pStoreItem.foldout = EditorGUILayout.Foldout(pStoreItem.foldout, pStoreItem.productId.ToString());
            GUILayout.Space(5);

            if (pStoreItem.foldout)
            {
#if UNITY_5_6_OR_NEWER
                var bundleId = PlayerSettings.applicationIdentifier;
#else
                var bundleId = PlayerSettings.bundleIdentifier;
#endif

                var storeId = pStoreItem.productId.ToString().ToLower();
                pStoreItem.productId    = (CocoStoreID)EditorGUILayout.EnumPopup("ProductId (商品Id): ", pStoreItem.productId);
                pStoreItem.itemIdString = EditorGUILayout.TextField("item Id: ",
                                                                    string.IsNullOrEmpty(pStoreItem.itemIdString) ? pStoreItem.iosIapString : pStoreItem.itemIdString);
                pStoreItem.iosIapString = EditorGUILayout.TextField("iOS iap Id: ",
                                                                    isAuto ? string.Format("{0}.{1}", bundleId, storeId) : pStoreItem.iosIapString);
                pStoreItem.gpIapString = EditorGUILayout.TextField("GP iap Id: ",
                                                                   isAuto ? string.Format("{0}_{1}", bundleId, storeId) : pStoreItem.gpIapString);
                pStoreItem.amIapString = EditorGUILayout.TextField("AM iap Id: ",
                                                                   isAuto ? string.Format("{0}amazon_{1}", bundleId, storeId) : pStoreItem.amIapString);
                pStoreItem.productType = (ProductType)EditorGUILayout.EnumPopup("ProductType (商品类型): ", pStoreItem.productType);
                pStoreItem.isNoAdsLap  = EditorGUILayout.Toggle("NoAdsLap (能否去广告)", pStoreItem.isNoAdsLap);

                EditorGUILayout.BeginHorizontal();

                GUIStyle pStyle = new GUIStyle(EditorStyles.foldout);
                pStoreItem.relatedItemsFoldout = EditorGUILayout.Foldout(pStoreItem.relatedItemsFoldout, "relatedStoreItems", pStyle);
                int pItemsNum = EditorGUILayout.IntField("", pStoreItem.relatedStoreItems.Count);
                while (pStoreItem.relatedStoreItems.Count != pItemsNum)
                {
                    pStoreItem.relatedItemsFoldout = true;

                    if (pStoreItem.relatedStoreItems.Count < pItemsNum)
                    {
                        pStoreItem.relatedStoreItems.Add(CocoStoreID.NoAds);
                    }

                    if (pStoreItem.relatedStoreItems.Count > pItemsNum)
                    {
                        pStoreItem.relatedStoreItems.RemoveAt(pStoreItem.relatedStoreItems.Count - 1);
                    }
                }

                EditorGUILayout.EndHorizontal();
                if (pStoreItem.relatedItemsFoldout)
                {
                    for (int i = 0; i < pStoreItem.relatedStoreItems.Count; i++)
                    {
                        pStoreItem.relatedStoreItems [i] = (CocoStoreID)EditorGUILayout.EnumPopup("CocoStoreID ", pStoreItem.relatedStoreItems [i]);
                    }
                }
            }

            CocoStoreData.Instance.allProductItems [pIndex] = pStoreItem;

            EditorGUILayout.EndVertical();

            return(pIsRemoveData);
        }