Пример #1
0
        void DisplayOutputJson()
        {
            EditorGUILayout.Separator();
            CustomEditorTools.DrawHeader("Output Excel To Json");
            CustomEditorTools.BeginContents();
            EditorGUILayout.BeginHorizontal();

            string outputPath = PlayerPrefs.GetString("ExcelToJson_OutputPath");

            if (string.IsNullOrEmpty(outputPath))
            {
                outputPath = Application.dataPath + "/" + _jsonFolder;
                PlayerPrefs.SetString("ExcelToJson_OutputPath", outputPath);
            }

            DirectoryInfo dirInfo = new DirectoryInfo(outputPath);

            if (!dirInfo.Exists)
            {
                Directory.CreateDirectory(outputPath);
            }

            EditorGUILayout.TextField(outputPath);
            if (CustomEditorTools.DrawMiniButton("Choose"))
            {
                string changePath = EditorUtility.OpenFolderPanel("Output Json Folder", outputPath, "");

                if (!string.IsNullOrEmpty(changePath))
                {
                    outputPath = changePath;
                    PlayerPrefs.SetString("ExcelToJson_OutputPath", outputPath);
                }
            }
            EditorGUILayout.EndHorizontal();
            CustomEditorTools.EndContens();
        }
Пример #2
0
        void DisplayExcelFile()
        {
            string outputPath = PlayerPrefs.GetString("ExcelToJson_OutputPath");

            CustomEditorTools.DrawHeader("Excel File Info");
            CustomEditorTools.BeginContents();
            EditorGUILayout.BeginHorizontal();
            if (CustomEditorTools.DrawMiniButton("Clear Excel Data"))
            {
                _currentBookInfo.Clear();
            }
            if (CustomEditorTools.DrawMiniButton("Remove All Json"))
            {
                DirectoryInfo outputDir = new DirectoryInfo(outputPath);
                if (outputDir.Exists)
                {
                    FileInfo[] files = outputDir.GetFiles();
                    for (int i = files.Length - 1; i >= 0; i--)
                    {
                        FileUtil.DeleteFileOrDirectory(outputPath + "/" + files[i].Name);
                    }
                }
                AssetDatabase.Refresh();
            }
            if (CustomEditorTools.DrawMiniButton("All Convert"))
            {
                if (_currentBookInfo.Count <= 0)
                {
                    CustomEditorTools.DisplayNoticeDialog("Warring", "Excel Data Empty, Select Excel Data");
                    return;
                }

                for (int i = 0; i < _currentBookInfo.Count; i++)
                {
                    for (int j = 0; j < _currentBookInfo [i].sheet.Length; j++)
                    {
                        ExcelToJsonConvert.ConvertToJson(_currentBookInfo [i].sheet[j], outputPath);
                    }
                }

                CustomEditorTools.DisplayNoticeDialog("Notice", "Completed Convert Excel To Json");
            }
            EditorGUILayout.EndHorizontal();
            CustomEditorTools.EndContens();
            CustomEditorTools.BeginContents();
            _scrollPos = EditorGUILayout.BeginScrollView(_scrollPos, GUILayout.MinHeight(200f));
            for (int i = _currentBookInfo.Count - 1; i >= 0; i--)
            {
                CustomEditorTools.BeginContents();
                EditorGUILayout.BeginHorizontal();
                bool foldOut = GUILayout.Toggle(_currentBookInfo[i].foldOut, _currentBookInfo[i].fileName, "Foldout", GUILayout.MaxWidth(200f), GUILayout.MinWidth(200f));

                if (foldOut != _currentBookInfo[i].foldOut)
                {
                    _currentBookInfo[i].foldOut = foldOut;
                }
                EditorGUILayout.EndHorizontal();

                if (_currentBookInfo[i].foldOut)
                {
                    if (_currentBookInfo[i].sheet == null)
                    {
                        continue;
                    }

                    for (int j = 0; j < _currentBookInfo[i].sheet.Length; j++)
                    {
                        DisplaySheetInfo(_currentBookInfo [i].sheet [j]);
                    }
                }
                CustomEditorTools.EndContens();
            }
            EditorGUILayout.EndScrollView();
            CustomEditorTools.EndContens();
        }
Пример #3
0
        void DisplayLoadExcelFolder()
        {
            EditorGUILayout.Separator();
            CustomEditorTools.DrawHeader("Load Excel Folder");
            CustomEditorTools.BeginContents();
            EditorGUILayout.BeginHorizontal();

            string loadPath = PlayerPrefs.GetString("ExcelLoadPath");

            if (string.IsNullOrEmpty(loadPath))
            {
                loadPath = Application.dataPath + "/" + _excelFolder;
                PlayerPrefs.SetString("ExcelLoadPath", loadPath);
            }

            DirectoryInfo dirInfo = new DirectoryInfo(loadPath);

            if (!dirInfo.Exists)
            {
                Directory.CreateDirectory(loadPath);
            }

            EditorGUILayout.TextField(loadPath);
            if (CustomEditorTools.DrawMiniButton("Choose"))
            {
                string changePath = EditorUtility.OpenFolderPanel("Output Json Folder", loadPath, "");

                if (!string.IsNullOrEmpty(changePath))
                {
                    loadPath = changePath;
                    PlayerPrefs.SetString("ExcelLoadPath", loadPath);
                }
            }
            if (CustomEditorTools.DrawMiniButton("Load"))
            {
                DirectoryInfo loadDir = new DirectoryInfo(loadPath);
                if (!loadDir.Exists)
                {
                    CustomEditorTools.DisplayNoticeDialog("Warning", "Not Exist Excel Directory");
                    return;
                }

                _currentBookInfo.Clear();
                FileInfo[] file = loadDir.GetFiles();
                for (int i = 0; i < file.Length; i++)
                {
                    string[] extention = file[i].Name.Split('.');
                    int      lastIndex = extention.Length - 1;
                    bool     isRead    = false;
                    for (int j = 0; j < _readExtention.Length; j++)
                    {
                        if (extention[lastIndex].Equals(_readExtention[j]))
                        {
                            isRead = true;
                            break;
                        }
                    }

                    if (isRead)
                    {
                        AddExcelFile(loadPath + "/" + file [i].Name);
                    }
                }

                if (_currentBookInfo.Count <= 0)
                {
                    CustomEditorTools.DisplayNoticeDialog("Warning", "Not Exist Excel File");
                    return;
                }
            }
            EditorGUILayout.EndHorizontal();
            CustomEditorTools.EndContens();
        }