void LoadData() { itemData = null; selectedItemIndex = -1; EditorHelpers.LoadItemConfigs(); EditorHelpers.LoadCollectibleConfigs(); EditorHelpers.LoadItemGroupConfigs(); EditorHelpers.LoadIAPConfigs(true); }
private void WriteAllItemsDataToItemConfig() { string pPath = "data source=" + Application.streamingAssetsPath + "/DB/game.db"; CocoSqliteDBHelper db = new CocoSqliteDBHelper(pPath); string pTableName = "item_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 + "'"; ItemConfigData pData = new ItemConfigData(); pData.id = storeItem.itemIdString; pData.name = storeItem.productId.ToString(); pData.iapConfigId = storeItem.itemIdString; string pValue = "'" + JsonMapper.ToJson(pData) + "'"; db.InsertInto(pTableName, new[] { pKey, pValue }); Debug.LogWarning("Write Data For Item Config Success ! : ( " + pKey + "," + pValue + ")"); pTotalItem += 1; } } db.CloseSqlConnection(); //avoid to database is locked Debug.LogWarning("Write Item Config Data Success ! Total (写入成功!总共):" + pTotalItem.ToString()); }
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); }