void OnDestroy()
 {
     try
     {
         TSDatabaseUtils.SavaGlobalData();
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Exemple #2
0
 private void OnDestroy()
 {
     try
     {
         EditorUtility.SetDirty(_excelConfig);
         TSDatabaseUtils.SavaGlobalData();
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Exemple #3
0
    /// <summary>
    /// 显示Title
    /// </summary>
    private void GUITitleInfo()
    {
        GUI.color = new Color(0.8f, 0.8f, 0.8f);
        GUILayout.BeginHorizontal("OL Title");
        GUI.color = Color.white;
        GUILayout.Space(-5);
        if (GUILayout.Button(LanguageUtils.DataSave, EditorGUIStyle.MiddleButtonStyle, GUILayout.ExpandHeight(true), GUILayout.Width(100)))
        {
            this.ShowNotification(new GUIContent(LanguageUtils.DataSaving));
            _primaryKeyInfo.Values.Clear();
            for (int i = 0; i < _serializeData.DataList.Count; i++)
            {
                string value = _serializeData.DataList[i].Id.ToString();
                if (!_primaryKeyInfo.Values.ContainsKey(value))
                {
                    _primaryKeyInfo.Values.Add(value, 1);
                }
                else
                {
                    _primaryKeyInfo.Values[value]++;
                }
            }
            TSDatabaseUtils.SavaGlobalData();
            EditorUtility.SetDirty(_serializeData);
            AssetDatabase.SaveAssets();
            this.RemoveNotification();
            EditorUtility.DisplayDialog(LanguageUtils.DataSave, "Success", "Ok");
        }

        GUILayout.FlexibleSpace();
        if (GUILayout.Button(LanguageUtils.CreateListAdd, EditorGUIStyle.MiddleButtonStyle, GUILayout.ExpandHeight(true), GUILayout.Width(100)))
        {
            Test data = new Test();
            _serializeData.DataList.Add(data);
            if (_primaryKeyInfo.Values.ContainsKey(data.Id.ToString()))
            {
                _primaryKeyInfo.Values[data.Id.ToString()]++;
            }
            else
            {
                _primaryKeyInfo.Values.Add(data.Id.ToString(), 1);
            }
            _pageMaxNum = (_serializeData.DataList.Count / _excelConfig.ShowCount);
            if (_serializeData.DataList.Count % _excelConfig.ShowCount > 0)
            {
                _pageMaxNum++;
            }
            _pageNum = 1;
        }
        GUILayout.Space(-5);

        GUILayout.EndHorizontal();
    }
    private void HeadGUI()
    {
        GUI.color = new Color(0.8f, 0.8f, 0.8f);
        GUILayout.BeginHorizontal("OL Title");
        GUI.color = Color.white;
        GUILayout.Label(LanguageUtils.SettingHead);
        GUILayout.FlexibleSpace();

        if (GUILayout.Button(LanguageUtils.CommonSaveSetting))
        {
            TSDatabaseUtils.SavaGlobalData();
        }
        GUILayout.EndHorizontal();
    }
Exemple #5
0
    private void ImportData(ExportDto dto)
    {
        string fileName = EditorUtility.OpenFilePanel("", "", "txt");

        if (!string.IsNullOrEmpty(fileName))
        {
            List <FieldConfig> importFieldConfigList = new List <FieldConfig>();
            for (int i = 0; i < dto.CurrentConfig.FieldList.Count; i++)
            {
                if (dto.CurrentConfig.FieldList[i].FieldName == dto.CurrentConfig.PrimaryKey)
                {
                    if (dto.CurrentConfig.FieldList[i].IsExport == false)
                    {
                        if (EditorUtility.DisplayDialog("Error", "PrimaryKey 没有导出", "OK"))
                        {
                            return;
                        }
                    }
                }
                if (dto.CurrentConfig.FieldList[i].IsExport)
                {
                    importFieldConfigList.Add(dto.CurrentConfig.FieldList[i]);
                }
            }
            int      count   = importFieldConfigList.Count;
            string[] allLine = File.ReadAllLines(fileName);
            if (allLine.Length < 1)
            {
                if (EditorUtility.DisplayDialog("Error", "File Error", "OK"))
                {
                    return;
                }
            }
            string[] fieldArray = allLine[0].Split(new char[] { '\t' }, StringSplitOptions.RemoveEmptyEntries);
            if (fieldArray.Length != count)
            {
                Debug.LogError("fieldArray.Length");
                if (EditorUtility.DisplayDialog("Error", "File Error", "OK"))
                {
                    return;
                }
            }
            ScriptableObject assetObj = AssetDatabase.LoadAssetAtPath <ScriptableObject>(dto.CurrentConfig.DataPath);
            object           items    = assetObj.GetType().GetField("DataList").GetValue(assetObj);
            if (items == null)
            {
                if (EditorUtility.DisplayDialog("Error", "Unity data is null", "OK"))
                {
                    return;
                }
            }

            Assembly assembly    = assetObj.GetType().Assembly;
            Type     itemType    = assembly.GetType(dto.CurrentConfig.TableName);
            object   targetItems = Activator.CreateInstance(typeof(List <>).MakeGenericType(itemType));

            MethodInfo addMethod  = items.GetType().GetMethod("Add");
            MethodInfo getMethod  = items.GetType().GetMethod("get_Item");
            int        orginCount = (int)items.GetType().GetProperty("Count").GetValue(items, null);

            if (itemType == null)
            {
                if (EditorUtility.DisplayDialog("Error", "Table type Error", "OK"))
                {
                    return;
                }
            }
            //清空所有主键重新键入
            if (TSDatabaseUtils.PrimaryKeySerializeData.PrimaryKeyDic.ContainsKey(dto.CurrentConfig.TableName))
            {
                TSDatabaseUtils.PrimaryKeySerializeData.PrimaryKeyDic[dto.CurrentConfig.TableName].Values.Clear();
            }
            else
            {
                TSDatabaseUtils.PrimaryKeySerializeData.PrimaryKeyDic.Add(dto.CurrentConfig.TableName, new PrimaryKeyInfo());
                TSDatabaseUtils.PrimaryKeySerializeData.PrimaryKeyDic[dto.CurrentConfig.TableName].TableName   = dto.CurrentConfig.TableName;
                TSDatabaseUtils.PrimaryKeySerializeData.PrimaryKeyDic[dto.CurrentConfig.TableName].PrimaryKey  = dto.CurrentConfig.PrimaryKey;
                TSDatabaseUtils.PrimaryKeySerializeData.PrimaryKeyDic[dto.CurrentConfig.TableName].PrimaryType = dto.CurrentConfig.PrimaryType;
                TSDatabaseUtils.PrimaryKeySerializeData.PrimaryKeyDic[dto.CurrentConfig.TableName].Values      = new Dictionary <string, int>();
            }

            string keyName  = dto.CurrentConfig.PrimaryKey;
            int    keyIndex = 0;
            for (int i = 0; i < count; i++)
            {
                if (fieldArray[i] == dto.CurrentConfig.PrimaryKey)
                {
                    keyIndex = i;
                    break;
                }
            }
            EditorUtility.DisplayProgressBar("开始导入", "正在导入0/" + (allLine.Length - 1), 0f);
            try
            {
                int begin = 1;
                for (; begin < allLine.Length; begin++)
                {
                    string[] contentArray = allLine[begin].Split(new char[] { '\t' }, StringSplitOptions.RemoveEmptyEntries);
                    if (contentArray.Length > count)
                    {
                        continue;
                    }
                    object o        = null;
                    object keyValue = null;
                    //找到主键ID 一样的数据
                    for (int j = 0; j < orginCount; j++)
                    {
                        o        = getMethod.Invoke(items, new object[] { j });
                        keyValue = o.GetType().GetField(keyName).GetValue(o);
                        if (keyValue.ToString() == contentArray[keyIndex])
                        {
                            break;
                        }
                        else
                        {
                            o = null;
                        }
                    }
                    //如果原表中没有查询到,则创建新的
                    if (o == null)
                    {
                        o = assembly.CreateInstance(itemType.FullName);
                    }

                    for (int i = 0; i < importFieldConfigList.Count; i++)
                    {
                        FieldConfig fieldConfig = importFieldConfigList[i];
                        ///如果是Unity对象类型则不赋值
                        switch (fieldConfig.FieldType)
                        {
                        case "Sprite":
                        case "Texture":
                        case "GameObject":
                        case "Texture2D":
                            continue;

                        case "List":
                            switch (fieldConfig.GenericType)
                            {
                            case "Sprite":
                            case "Texture":
                            case "GameObject":
                            case "Texture2D":
                                continue;
                            }
                            break;
                        }
                        o.GetType().GetField(fieldConfig.FieldName).SetValue(o, GetObject(fieldConfig, contentArray[i], assembly, fieldConfig.FieldType));
                        if (keyName == fieldConfig.FieldName)
                        {
                            keyValue = o.GetType().GetField(fieldConfig.FieldName).GetValue(o);
                        }
                    }

                    addMethod.Invoke(targetItems, new object[] { o });
                    if (TSDatabaseUtils.PrimaryKeySerializeData.PrimaryKeyDic[dto.CurrentConfig.TableName].Values.ContainsKey(keyValue.ToString()))
                    {
                        TSDatabaseUtils.PrimaryKeySerializeData.PrimaryKeyDic[dto.CurrentConfig.TableName].Values[keyValue.ToString()]++;
                    }
                    else
                    {
                        TSDatabaseUtils.PrimaryKeySerializeData.PrimaryKeyDic[dto.CurrentConfig.TableName].Values.Add(keyValue.ToString(), 1);
                    }
                    EditorUtility.DisplayProgressBar("开始导入", "正在导入" + (begin - 1) + "/" + (allLine.Length - 1), (begin - 1) * 1f / (allLine.Length - 1));
                    System.Threading.Thread.Sleep(10);
                }
                assetObj.GetType().GetField("DataList").SetValue(assetObj, targetItems);
                EditorUtility.SetDirty(assetObj);
                TSDatabaseUtils.SavaGlobalData();
                EditorUtility.ClearProgressBar();
                EditorUtility.DisplayDialog("成功", "导入成功!", "OK");
            }
            catch (Exception ex)
            {
                EditorUtility.ClearProgressBar();
                throw ex;
            }
        }
        else
        {
            if (EditorUtility.DisplayDialog("Error", "Path is Error", "OK"))
            {
                return;
            }
        }
    }
 private void WriteConfig()
 {
     TSDatabaseUtils.SavaGlobalData();
     AssetDatabase.SaveAssets();
 }
Exemple #7
0
 private void CheckPlayerData()
 {
     for (int i = 0; i < TSDatabaseUtils.TableConfigSerializeData.TableConfigList.Count; i++)
     {
         if (TSDatabaseUtils.TableConfigSerializeData.TableConfigList[i].TableName == "Test")
         {
             _tableConfig = TSDatabaseUtils.TableConfigSerializeData.TableConfigList[i];
             break;
         }
     }
     if (string.IsNullOrEmpty(_tableConfig.DataPath))
     {
         string path = EditorUtility.SaveFilePanelInProject(LanguageUtils.CommonSaveFile, _tableConfig.TableName + ".asset", "asset", "");
         if (string.IsNullOrEmpty(path))
         {
             if (EditorUtility.DisplayDialog(LanguageUtils.CommonSaveFailed, LanguageUtils.CommonNullPath, "OK"))
             {
                 return;
             }
         }
         _tableConfig.DataPath = path;
         _serializeData        = ScriptableObject.CreateInstance <TestSerializeData>();
         TSDatabaseUtils.PrimaryKeySerializeData.PrimaryKeyDic.Add(_tableConfig.TableName, new PrimaryKeyInfo());
         _primaryKeyInfo             = TSDatabaseUtils.PrimaryKeySerializeData.PrimaryKeyDic[_tableConfig.TableName];
         _primaryKeyInfo.TableName   = _tableConfig.TableName;
         _primaryKeyInfo.PrimaryKey  = _tableConfig.PrimaryKey;
         _primaryKeyInfo.PrimaryType = _tableConfig.PrimaryType;
         _primaryKeyInfo.Values      = new Dictionary <string, int>();
         TSDatabaseUtils.SavaGlobalData();
         AssetDatabase.CreateAsset(_serializeData, path);
         AssetDatabase.SaveAssets();
         AssetDatabase.Refresh();
     }
     else
     {
         _serializeData  = AssetDatabase.LoadAssetAtPath <TestSerializeData>(_tableConfig.DataPath);
         _primaryKeyInfo = TSDatabaseUtils.PrimaryKeySerializeData.PrimaryKeyDic[_tableConfig.TableName];
         if (_tableConfig.PrimaryKey != _primaryKeyInfo.PrimaryKey)
         {
             //更换主键
             _primaryKeyInfo.TableName   = _tableConfig.TableName;
             _primaryKeyInfo.PrimaryKey  = _tableConfig.PrimaryKey;
             _primaryKeyInfo.PrimaryType = _tableConfig.PrimaryType;
             _primaryKeyInfo.Values      = new Dictionary <string, int>();
             for (int i = 0; i < _serializeData.DataList.Count; i++)
             {
                 string value = _serializeData.DataList[i].Id.ToString();
                 if (!_primaryKeyInfo.Values.ContainsKey(value))
                 {
                     _primaryKeyInfo.Values.Add(value, 1);
                 }
                 else
                 {
                     _primaryKeyInfo.Values[value]++;
                 }
             }
             TSDatabaseUtils.SavaGlobalData();
         }
     }
     _dataList = new List <Test>();
     _dataList.AddRange(_serializeData.DataList);
 }