Exemple #1
0
    static public void Write(string SheetName, string TableKey, string TableValue, string DataKey, string DataValue)
    {
        IAPConfigData      pIapConfigData = new IAPConfigData();
        CocoSqliteDBHelper db             = new CocoSqliteDBHelper(DBTool.LocalPath);
        int pTableCount = db.FindTable(SheetName, DBTool.LocalPath);

        if (pTableCount == 0)
        {
            db.CreateTable(SheetName, new string[] { TableKey, TableValue }, new string[] { "text", "text" });
        }

        SqliteDataReader pDataReader = db.SelectWhere(
            SheetName,
            new string[] { TableValue },
            new string[] { TableKey },
            new string[] { "=" },
            new string[] { DataKey });

        if (pDataReader.Read())
        {
            db.Delete(
                SheetName,
                new string[] { TableKey },
                new string[] { "'" + DataKey + "'" }
                );
        }
        pDataReader.Close();

        db.InsertInto(SheetName, new string[] { "'" + DataKey + "'", "'" + DataValue + "'" });
        db.CloseSqlConnection();
    }
Exemple #2
0
    void LoadData()
    {
        iAPData          = null;
        selectedIAPIndex = -1;

        EditorHelpers.LoadIAPConfigs();
    }
Exemple #3
0
    bool DrawLoadService()
    {
        contentColor    = GUI.contentColor;
        backgroundColor = GUI.backgroundColor;

        EditorGUILayout.BeginHorizontal();
        GUI.backgroundColor = EditorHelpers.orangeColor;
        if (GUILayout.Button("Load", GUILayout.Width(60)))
        {
            LoadData();
        }

        GUI.backgroundColor = EditorHelpers.yellowColor;
        if (GUILayout.Button("New", GUILayout.Width(60)))
        {
            ItemConfigData newData = new ItemConfigData();
            newData.id = "New Item " + newItemNameSufix.ToString();
            ++newItemNameSufix;
            EditorHelpers.allItems.Insert(0, newData);
            EditorHelpers.InitItemConfigNames();
            selectedItemIndex = 0;
            itemData          = newData;
            ShowNotification(new GUIContent("New Item added."));
            dirty = true;
        }
        GUI.backgroundColor = EditorHelpers.greenColor;
        if (GUILayout.Button("Save", GUILayout.Width(60)))
        {
            Save();
        }
        GUI.backgroundColor = backgroundColor;
        EditorGUILayout.EndHorizontal();

        EditorGUILayout.Separator(); EditorGUILayout.Separator(); EditorGUILayout.Separator();
        if (EditorHelpers.allItems == null)
        {
            EditorGUILayout.HelpBox("It seems that there is no data... try reopening the editor.", MessageType.Error);
            return(false);
        }

        iapCreatorSectionOpened = EditorGUILayout.Foldout(iapCreatorSectionOpened, "iAP Creator");

        if (iapCreatorSectionOpened)
        {
            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.LabelField("iAP Name:", GUILayout.Width(100));
            iapName = EditorGUILayout.TextField(iapName, GUILayout.Width(250));
            if (GUILayout.Button("Create", GUILayout.Width(70)))
            {
                if (iapName.Length > 0)
                {
                    bool exists = false;
                    foreach (var id in EditorHelpers.allIAPs)
                    {
                        if (id.id == iapName)
                        {
                            ShowNotification(new GUIContent("iAP with id (" + iapName + ") already exists."));
                            exists = true;
                            break;
                        }
                    }
                    if (!exists)
                    {
                        IAPConfigData newiAP = new IAPConfigData();
                        newiAP.id   = iapName;
                        newiAP.name = iapName;
                        var newIAPData = new IAPData(StoreType.All, iapName);
                        newiAP.iapData.Add(newIAPData);
                        EditorHelpers.allIAPs.Add(newiAP);
                        EditorHelpers.InitIAPNames(true);
                        ShowNotification(new GUIContent("New iAP created."));
                        if (EditorHelpers.allIAPs.Count > 0)
                        {
                            EditorHelpers.gameDB.DeleteAllConfigs(EditorHelpers.allIAPs[0].GetTableName());
                        }
                        foreach (var p in EditorHelpers.allIAPs)
                        {
                            EditorHelpers.gameDB.SaveConfig(p.GetTableName(), p.id, LitJson.JsonMapper.ToJson(p));
                        }
                        EditorHelpers.gameDB.IncrementLocalDBVersion();
                    }
                }
                else
                {
                    ShowNotification(new GUIContent("iAP must have a name."));
                }
            }
            EditorGUILayout.EndHorizontal();
            EditorGUILayout.Separator(); EditorGUILayout.Separator();
        }

        if (EditorHelpers.DrawItemsFilter("Item Filter:"))
        {
            selectedItemIndex = -1;
            itemData          = null;
        }
        if (EditorHelpers.allItems.Count > 0)
        {
            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.LabelField("Items:", GUILayout.Width(100));
            int oldIntValue = selectedItemIndex;
            selectedItemIndex = EditorGUILayout.Popup(oldIntValue, EditorHelpers.itemConfigNames, GUILayout.Width(250));
            if (oldIntValue != selectedItemIndex)
            {
                itemData = EditorHelpers.allItems[selectedItemIndex];
            }
            if (itemData != null)
            {
                GUI.backgroundColor = EditorHelpers.redColor;
                if (GUILayout.Button("Delete", GUILayout.Width(70)))
                {
                    if (EditorUtility.DisplayDialog("Deleting Item!", "Are you sure you want to delete parameter '" + itemData.id + "'?", "Yes, Delete it.", "No!"))
                    {
                        EditorHelpers.gameDB.DeleteConfig(itemData.GetTableName(), itemData.id);
                        EditorHelpers.allItems.Remove(itemData);
                        EditorHelpers.InitItemConfigNames();
                        selectedItemIndex = -1;
                        itemData          = null;
                        ShowNotification(new GUIContent("Item deleted."));
                        return(false);
                    }
                }
                GUI.backgroundColor = EditorHelpers.blueColor;
                if (GUILayout.Button("Duplicate", GUILayout.Width(100)))
                {
                    ItemConfigData newData = itemData.Clone() as ItemConfigData;
                    newData.id = itemData.id + "(Clone)";
                    EditorHelpers.allItems.Insert(0, newData);
                    EditorHelpers.InitItemConfigNames();
                    selectedItemIndex = 0;
                    itemData          = newData;
                    ShowNotification(new GUIContent("Item duplicated."));
                    dirty = true;
                }
                GUI.backgroundColor = backgroundColor;
            }
            EditorGUILayout.EndHorizontal();

            EditorGUILayout.Separator(); EditorGUILayout.Separator(); EditorGUILayout.Separator();
        }

        return(itemData != null);
    }
Exemple #4
0
    bool DrawLoadService()
    {
        contentColor    = GUI.contentColor;
        backgroundColor = GUI.backgroundColor;

        EditorGUILayout.BeginHorizontal();
        GUI.backgroundColor = EditorHelpers.orangeColor;
        if (GUILayout.Button("Load", GUILayout.Width(60)))
        {
            LoadData();
        }

        GUI.backgroundColor = EditorHelpers.yellowColor;
        if (GUILayout.Button("New", GUILayout.Width(60)))
        {
            IAPConfigData newData = new IAPConfigData();
            newData.id = "New iAP " + newIAPNameSufix.ToString();
            ++newIAPNameSufix;
            EditorHelpers.allIAPs.Insert(0, newData);
            EditorHelpers.InitIAPNames();
            selectedIAPIndex = 0;
            iAPData          = newData;
            ShowNotification(new GUIContent("New iAP added."));
            dirty = true;
        }
        GUI.backgroundColor = EditorHelpers.greenColor;
        if (GUILayout.Button("Save", GUILayout.Width(60)))
        {
            Save();
        }
        GUI.backgroundColor = backgroundColor;
        EditorGUILayout.EndHorizontal();

        EditorGUILayout.Separator(); EditorGUILayout.Separator(); EditorGUILayout.Separator();
        if (EditorHelpers.allIAPs == null)
        {
            EditorGUILayout.HelpBox("It seems that there is no data... try reopening the editor.", MessageType.Error);
            return(false);
        }
        if (EditorHelpers.allIAPs.Count > 0)
        {
            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.LabelField("iAPs:", GUILayout.Width(100));
            int oldIntValue = selectedIAPIndex;
            selectedIAPIndex = EditorGUILayout.Popup(oldIntValue, EditorHelpers.iAPNames, GUILayout.Width(250));
            if (oldIntValue != selectedIAPIndex)
            {
                iAPData = EditorHelpers.allIAPs[selectedIAPIndex];
            }
            if (iAPData != null)
            {
                GUI.backgroundColor = EditorHelpers.blueColor;
                if (GUILayout.Button("Duplicate", GUILayout.Width(70)))
                {
                    IAPConfigData newData = iAPData.Clone() as IAPConfigData;
                    newData.id = iAPData.id + "(Clone)";
                    EditorHelpers.allIAPs.Insert(0, newData);
                    EditorHelpers.InitIAPNames();
                    selectedIAPIndex = 0;
                    iAPData          = newData;
                    ShowNotification(new GUIContent("iAP duplicated."));
                    dirty = true;
                }

                GUI.backgroundColor = EditorHelpers.redColor;
                if (GUILayout.Button("Delete", GUILayout.Width(70)))
                {
                    if (EditorUtility.DisplayDialog("Deleting iAP!", "Are you sure you want to delete iAP'" + iAPData.id + "'?", "Yes, Delete it.", "No!"))
                    {
                        EditorHelpers.gameDB.DeleteConfig(iAPData.GetTableName(), iAPData.id);
                        EditorHelpers.allIAPs.Remove(iAPData);
                        EditorHelpers.InitIAPNames();
                        selectedIAPIndex = -1;
                        iAPData          = null;
                        ShowNotification(new GUIContent("iAP deleted."));
                        return(false);
                    }
                }
                GUI.backgroundColor = backgroundColor;
            }
            EditorGUILayout.EndHorizontal();

            EditorGUILayout.Separator(); EditorGUILayout.Separator(); EditorGUILayout.Separator();
        }

        return(iAPData != null);
    }
        private void WriteAllItemsDataToIapConfig()
        {
            string pPath = "data source=" + Application.streamingAssetsPath + "/DB/game.db";

            CocoSqliteDBHelper db = new CocoSqliteDBHelper(pPath);

            string pTableName = "iap_config";
            int    pCount     = db.FindTable(pTableName, pPath);
            int    pTotalItem = 0;

            if (pCount != 0)
            {
                //首先清除之前所有的数据
                db.DeleteContents(pTableName);

                List <CocoStoreItem> pAllStoreItems = CocoStoreData.Instance.allProductItems;

                foreach (var storeItem in pAllStoreItems)
                {
                    string pKey = "'" + storeItem.itemIdString + "'";

                    IAPConfigData pData = new IAPConfigData();
                    pData.id       = storeItem.itemIdString;
                    pData.name     = storeItem.productId.ToString();
                    pData.noAdsIap = storeItem.isNoAdsLap;

                    switch (storeItem.productType)
                    {
                    case ProductType.Consumable:
                        pData.consumable = true;
                        break;

                    case ProductType.Subscription:
                        pData.isSubscription = true;
                        break;
                    }

                    pData.iapData = new List <IAPData> ();

                    if (!string.IsNullOrEmpty(storeItem.iosIapString))
                    {
                        pData.iapData.Add(new IAPData {
                            store = StoreType.iOS, iapId = storeItem.iosIapString
                        });
                    }

                    if (!string.IsNullOrEmpty(storeItem.gpIapString))
                    {
                        pData.iapData.Add(new IAPData {
                            store = StoreType.Google, iapId = storeItem.gpIapString
                        });
                    }

                    if (!string.IsNullOrEmpty(storeItem.amIapString))
                    {
                        pData.iapData.Add(new IAPData {
                            store = StoreType.Amazon, iapId = storeItem.amIapString
                        });
                    }

                    string pValue = "'" + JsonMapper.ToJson(pData) + "'";

                    db.InsertInto(pTableName, new[] { pKey, pValue });
                    Debug.LogWarning("Write Data For IAP Config Success ! : ( " + pKey + "," + pValue + ")");
                    pTotalItem += 1;
                }
            }
            db.CloseSqlConnection();              //avoid to database is locked
            Debug.LogWarning("Write IAP Config Data Success ! Total (写入成功!总共):" + pTotalItem.ToString());
        }