Beispiel #1
0
        public static string[] ListAllCsvFilesInCsvFolder()
        {
            string folder = JumpCsvEditorHelper.PathCombine(Application.dataPath, JumpCsvConfig.CsvSpreadSheetFileDirectory);

            // verify csv folder
            if (!Directory.Exists(folder))
            {
                string errorStr = string.Format("CSV file folder path {} is not existed, please check CSV Folder path is vaild", folder);
                Debug.LogError(errorStr);
                throw new Exception(errorStr);
            }

            List <string> csvFiles = new List <string>();

            SearchCsvFiles(folder, ref csvFiles);

            // check duplicate file name
            for (int i = 0; i < csvFiles.Count; i++)
            {
                for (int j = i + 1; j < csvFiles.Count; j++)
                {
                    if (GetCsvDataClassName(csvFiles[i]).ToLower() == GetCsvDataClassName(csvFiles[j]).ToLower())
                    {
                        string errorStr = string.Format("There are duplicate file names in CSV file folder {0} AND {1}", csvFiles[i], csvFiles[j]);
                        throw new Exception(errorStr);
                    }
                }
            }
            return(csvFiles.ToArray());
        }
        private void SaveSettingsValues()
        {
            if (!CheckAllSettingsValues())
            {
                return;
            }
            JumpCsvConfig jCsvConfig = null;

            if (!JumpCsvEditorHelper.ContainsJumpCsvAssetsFiles())  // if not found settings asset, create assets
            {
                jCsvConfig = JumpCsvConfig.CreateAsset();
            }
            else   // update value
            {
                jCsvConfig = JumpCsvConfig.GetAsset();
            }
            jCsvConfig.mCsvSpreadSheetFileDirectory = JumpCsvEditorHelper.MakeRelativePath(Application.dataPath, CsvSpreadSheetFileDirectory);
            jCsvConfig.mCsvSourceCodeFileDirectory  = JumpCsvEditorHelper.MakeRelativePath(Application.dataPath, CsvSourceCodeFileDirectory);
            jCsvConfig.mCsvBinDataDirectory         = JumpCsvEditorHelper.MakeRelativePath(Application.dataPath, CsvBinDataDirectory);
            jCsvConfig.mCsvDataClassPostfixName     = CsvDataClassPostfixName;
            jCsvConfig.mCsvDataClassPrefixName      = CsvDataClassPrefixName;
            jCsvConfig.mCsvDataStructPostfixName    = CsvDataStructPostfixName;
            jCsvConfig.mCsvDataStructPrefixName     = CsvDataStructPrefixName;
            jCsvConfig.mExcludeCsvFiles             = new List <string>(ExcludeCsvFiles.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries));
            jCsvConfig.mCsvExtensionNames           = new List <string>(CsvExtensionNames.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries));
            EditorUtility.SetDirty(jCsvConfig);
            AssetDatabase.SaveAssets();
            AssetDatabase.Refresh();
            AssetDatabase.ImportAsset("Assets/" + JumpCsvConfig.JumpCsvConfigAssetFile, ImportAssetOptions.ForceSynchronousImport);
            JumpCsvConfig.UpdateValue();
        }
Beispiel #3
0
        public static string[] GetAllExpiredCsvFile()
        {
            List <string> expiredCsvFiles = new List <string>();

            foreach (string csvFile in ListAllCsvFilesInCsvFolder())
            {
                string csvCodeFileName = JumpCsvEditorHelper.PathCombine(JumpCsvEditorHelper.PathCombine(Application.dataPath, JumpCsvConfig.CsvSourceCodeFileDirectory), JumpCsvEditorHelper.GetCsvDataClassName(csvFile) + ".cs");
                //string csvDataFileName = JumpCsvEditorHelper.PathCombine(JumpCsvEditorHelper.PathCombine(Application.dataPath, JumpCsvConfig.CsvBinDataDirectory) , JumpCsvEditorHelper.GetCsvDataBinaryFileName(csvFile));
                if (!File.Exists(csvCodeFileName))
                {
                    expiredCsvFiles.Add(csvFile);
                }
                else   // check content is latest
                {
                    string className   = JumpCsvEditorHelper.GetCsvDataClassName(csvFile);
                    Type   csvCodeType = CsvHelper.GetType("JumpCSV." + className);
                    int    hashCode    = (int)(csvCodeType.GetField("mHashCode").GetValue(null));

                    string         resourcePath = JumpCsvEditorHelper.PathCombine(Application.dataPath, "Build/CSV/Common");
                    string         path         = JumpCsvEditorHelper.MakeRelativePath(resourcePath, csvFile);
                    CsvSpreadSheet spreadSheet  = new CsvSpreadSheet(path.Replace(".csv", ""), true);                      //string content = reader.ReadToEnd();
                    //csvReader.ReadFromString(content);
                    int CheckSum = spreadSheet.GetHashCode();
                    if (CheckSum != hashCode)
                    {
                        expiredCsvFiles.Add(csvFile);
                    }
                }
            }
            return(expiredCsvFiles.ToArray());
        }
Beispiel #4
0
 public static bool CheckCsvBinDataDirectory(string path)
 {
     if (!Directory.Exists(path))
     {
         return(false);
     }
     return(IsContainParentPath(path, JumpCsvEditorHelper.PathCombine(Application.dataPath, "Resources")));
 }
 public void InitSettingsValues()
 {
     CsvSpreadSheetFileDirectory = JumpCsvEditorHelper.PathCombine(Application.dataPath, JumpCsvConfig.CsvSpreadSheetFileDirectory);
     CsvSourceCodeFileDirectory  = JumpCsvEditorHelper.PathCombine(Application.dataPath, JumpCsvConfig.CsvSourceCodeFileDirectory);
     CsvBinDataDirectory         = JumpCsvEditorHelper.PathCombine(Application.dataPath, JumpCsvConfig.CsvBinDataDirectory);
     CsvDataClassPrefixName      = JumpCsvConfig.CsvDataClassPrefixName;
     CsvDataClassPostfixName     = JumpCsvConfig.CsvDataClassPostfixName;
     CsvDataStructPostfixName    = JumpCsvConfig.CsvDataStructPostfixName;
     CsvExtensionNames           = string.Join(";", JumpCsvConfig.CsvExtensionNames.ToArray());
     ExcludeCsvFiles             = string.Join(";", JumpCsvConfig.ExcludeCsvFiles.ToArray());
 }
Beispiel #6
0
        public static void CleanAllFiles()
        {
            // remove all csv data class generated in csv source code folder
            string directory = JumpCsvEditorHelper.PathCombine(Application.dataPath, JumpCsvConfig.CsvSourceCodeFileDirectory);

            FileUtil.DeleteFileOrDirectory(directory);

            // remove all binary data generated in csv binary data folder
            directory = JumpCsvEditorHelper.PathCombine(Application.dataPath, JumpCsvConfig.CsvBinDataDirectory);
            FileUtil.DeleteFileOrDirectory(directory);

            // reset CsvManager.cs file
            JumpCsvCodeGenerator.CreateEmptyCsvManagerSourceFile();
        }
Beispiel #7
0
        public static string[] GetAllLoseCsvData()
        {
            List <string> csvDataFiles = new List <string>();

            foreach (string csvFile in ListAllCsvFilesInCsvFolder())
            {
                string csvDataFileName = JumpCsvEditorHelper.PathCombine(JumpCsvEditorHelper.PathCombine(Application.dataPath, JumpCsvConfig.CsvBinDataDirectory), JumpCsvEditorHelper.GetCsvDataBinaryFileName(csvFile));
                if (!File.Exists(csvDataFileName))
                {
                    csvDataFiles.Add(csvDataFileName);
                }
            }
            return(csvDataFiles.ToArray());
        }
        static void BakeCsv(GameConfig.EShipChannel shipchannel, bool popupResult = false)
        {
            var sw = System.Diagnostics.Stopwatch.StartNew();

            BakeLocalizationCsv();
            CsvManager.isInit = false;
            string directory = JumpCsvEditorHelper.PathCombine(Application.dataPath, JumpCsvConfig.CsvBinDataDirectory);

            if (!Directory.Exists(directory))
            {
                Directory.CreateDirectory(directory);
            }
            CsvManager.Serialize(GameConfig.GetCsvTargetPath(shipchannel));
            AssetDatabase.Refresh();
            if (popupResult)
            {
                EditorUtility.DisplayDialog("成功", "生成csv文件成功。", "Ok");
            }
            Debug.Log("Bake Csv Complete: " + sw.Elapsed.TotalMilliseconds.ToString() + "ms");
        }
        static void BuildLocalization()
        {
            string mapLevelFolder = "Assets/Build/Localization";

            if (!Directory.Exists(mapLevelFolder))
            {
                Directory.CreateDirectory(mapLevelFolder);
            }
            CsvReader.DOUBLEQUOTE = false;
            var csvReader = new CsvReader();

            csvReader.Read("Assets/Build/Localization/Localization.csv");
            CsvReader.DOUBLEQUOTE = true;
            int           idIndex    = -1;
            int           valueIndex = -1;
            List <int>    langList   = new List <int>();
            List <string> langStr    = new List <string>();

            for (int i = 0; i < csvReader.Width; i++)
            {
                if (csvReader.ReadCell(0, i).IndexOf("_ID") >= 0)
                {
                    idIndex = i;
                }
                else if (csvReader.ReadCell(0, i).IndexOf("_VALUE") >= 0)
                {
                    valueIndex = i;
                }
                else if (csvReader.ReadCell(0, i).IndexOf("Comment") < 0)
                {
                    langList.Add(i);
                    langStr.Add(csvReader.ReadCell(0, i).Remove(csvReader.ReadCell(0, i).IndexOf(":")));
                }
            }

            for (int i = 0; i < langList.Count; i++)
            {
                using (StreamWriter sr = new StreamWriter(mapLevelFolder + "/Localization_" + langStr[i] + ".csv", false)) {
                    string valueString = (valueIndex != -1)?",_VALUE":"";
                    sr.WriteLine(csvReader.ReadCell(0, idIndex) + valueString + "," + "text:string");
                    for (int j = 1; j < csvReader.Height; j++)
                    {
                        string id  = csvReader.ReadCell(j, idIndex);
                        string val = (valueIndex != -1)?csvReader.ReadCell(j, valueIndex):(j.ToString());
                        //string val  = csvReader.ReadCell(j, valueIndex);
                        string text = csvReader.ReadCell(j, langList[i]);
                        if (text.IndexOf(",") > 0 ||
                            text.IndexOf("\"") > 0 ||
                            text.IndexOf("\n") > 0 ||
                            text.IndexOf("\r") > 0 ||
                            (text.Length >= 3 && text[0] == '"' && text[1] == '"' && text[2] != '"'))
                        {
                            text = "\"" + text + "\"";
                        }
                        string finalVal = (valueIndex != -1)?("," + val):"";
                        sr.WriteLine(id + finalVal + "," + text);
                    }
                }
            }

            AssetDatabase.Refresh();
            // create localizationcsvdata.cs
            CsvSpreadSheet localizationSheet = new CsvSpreadSheet("Assets/Build/Localization/Localization_CN", true);

            localizationSheet.CsvFileName = "Assets/Build/Localization/Localization";
            var tmpFile = JumpCsvCodeGenerator.CreateCsvDataClassSourceFile2(localizationSheet);

            FileUtil.ReplaceFile(tmpFile, JumpCsvEditorHelper.PathCombine(Application.dataPath, JumpCsvEditorHelper.PathCombine(JumpCsvConfig.CsvSourceCodeFileDirectory, Path.GetFileName(tmpFile))));
            AssetDatabase.Refresh();



//         csvReader = new CsvReader();
//         csvReader.Read("Assets/Build/Localization/RandomName.csv");
//         idIndex = -1;
//         valueIndex = -1;
//         int maleSurname = -1;
//         int maleName = -1;
//         int femaleSurname = -1;
//         int femaleName = -1;
//
//         for(int i = 0; i < csvReader.Width; i++) {
//             if(csvReader.ReadCell(0, i).IndexOf ("_ID") >= 0) {
//                 idIndex = i;
//             }
//             else if(csvReader.ReadCell(0, i).IndexOf ("_VALUE") >= 0) {
//                 valueIndex = i;
//             }
//             else if(csvReader.ReadCell(0, i).IndexOf ("MaleSurname") >=0 ) {
//                 maleSurname = i;
//             }
//             else if(csvReader.ReadCell(0, i).IndexOf ("MaleName") >=0 ) {
//                 maleName = i;
//             }
//             else if(csvReader.ReadCell(0, i).IndexOf ("FemaleSurname") >=0 ) {
//                 femaleSurname = i;
//             }
//             else if(csvReader.ReadCell(0, i).IndexOf ("FemaleName") >=0 ) {
//                 femaleName = i;
//             }
//         }
//
//         int currentValue = 1;
//         int currentIndex = 0;
//         int currentHeight = 1;
//         for(int i = 0; i < langStr.Count; i++) {
//             using(StreamWriter sr = new StreamWriter(mapLevelFolder + "/RandomName_" + langStr[i] + ".csv", false)) {
//                 sr.WriteLine("_INDEX,MaleSurname:string[],MaleName:string[],FemaleSurname:string[],FemaleName:string[]");
//                 for(int j = currentHeight; j < csvReader.Height; j++, currentIndex++) {
//                     string val = csvReader.ReadCell(j, valueIndex);
//                     if(!string.IsNullOrEmpty(val) && Int32.Parse(val) != currentValue) {
//                         currentValue = Int32.Parse(val);
//                         currentIndex = 0;
//                         currentHeight = j;
//                         break;
//                     }
//                     if(currentIndex == 0) {
//                         sr.WriteLine(currentIndex.ToString() + "," + csvReader.ReadCell(j, maleSurname) + "," + csvReader.ReadCell(j, maleName) + "," + csvReader.ReadCell(j, femaleSurname) + "," + csvReader.ReadCell(j, femaleName));
//                     }
//                     else {
//                         sr.WriteLine("," + csvReader.ReadCell(j, maleSurname) + "," + csvReader.ReadCell(j, maleName) + "," + csvReader.ReadCell(j, femaleSurname) + "," + csvReader.ReadCell(j, femaleName));
//                     }
//                 }
//             }
//         }
//         AssetDatabase.Refresh();
//         // create localizationcsvdata.cs
//         localizationSheet = new CsvSpreadSheet("Assets/Build/Localization/RandomName_CN", true);
//         localizationSheet.CsvFileName = "Assets/Build/Localization/RandomName";
//         tmpFile = JumpCsvCodeGenerator.CreateCsvDataClassSourceFile(localizationSheet);
//         FileUtil.ReplaceFile(tmpFile, JumpCsvEditorHelper.PathCombine(Application.dataPath, JumpCsvEditorHelper.PathCombine(JumpCsvConfig.CsvSourceCodeFileDirectory, Path.GetFileName(tmpFile))));
//         AssetDatabase.Refresh();
        }
        public void OnGUI()
        {
            scrollPos = EditorGUILayout.BeginScrollView(scrollPos);
            GUILayout.BeginVertical();
            GUILayout.BeginHorizontal();
            if (GUILayout.Button("Change CSV Folder", GUILayout.Width(buttonWidth), GUILayout.Height(buttonHeight)))
            {
                OpenFolderPanelAndSetPath("Choose Target Folder", CsvSpreadSheetFileDirectory, ref CsvSpreadSheetFileDirectory);
            }
            // hint message
            EditorGUILayout.HelpBox("JumpCSV will read all csv files in this folder.", MessageType.Info);
            GUILayout.EndHorizontal();

            if (!JumpCsvEditorHelper.CheckCsvSpreadSheetFileDirectory(CsvSpreadSheetFileDirectory))
            {
                EditorGUILayout.HelpBox(CsvSpreadSheetFileDirectory + " IS INVALID CSV FILE PATH, CSV FILE PATH MUST UNDER Assets/Resources FOLDER", MessageType.Error);
            }
            else
            {
                EditorGUILayout.BeginHorizontal();
                EditorGUILayout.PrefixLabel("CSV Folder: ");
                GUILayout.Label(CsvSpreadSheetFileDirectory);
                EditorGUILayout.EndHorizontal();
            }
            GUILayout.Space(spaceHeight);
            GUILayout.EndVertical();


            // GUILayout.BeginVertical();
            //     GUILayout.BeginHorizontal();
            //         if(GUILayout.Button("Change Code Folder",  GUILayout.Width(buttonWidth), GUILayout.Height(buttonHeight) )) {
            //             OpenFolderPanelAndSetPath("Choose Target Folder", CsvSourceCodeFileDirectory, ref CsvSourceCodeFileDirectory);
            //         }
            //         EditorGUILayout.HelpBox("All C# source code which read csv file will be created in this folder.", MessageType.Info);
            //     GUILayout.EndHorizontal();

            //     if(!JumpCsvEditorHelper.CheckCsvSourceCodeFileDirectory(CsvSourceCodeFileDirectory)) {
            //         EditorGUILayout.HelpBox(CsvSourceCodeFileDirectory + " IS INVALID SOURCE CODE TARGET PATH, MAKE SURE TARGET PATH IS UNDER ./Assets", MessageType.Error);
            //     }
            //     else {
            //         EditorGUILayout.BeginHorizontal();
            //             EditorGUILayout.PrefixLabel("CSV Code Folder:");
            //             GUILayout.Label(CsvSourceCodeFileDirectory);
            //         EditorGUILayout.EndHorizontal();
            //     }
            //     GUILayout.Space(spaceHeight);
            // GUILayout.EndVertical();


            // GUILayout.BeginVertical();
            //     GUILayout.BeginHorizontal();
            //         if(GUILayout.Button("Change Bin Folder", GUILayout.Width(buttonWidth), GUILayout.Height(buttonHeight))) {
            //             OpenFolderPanelAndSetPath("Choose Target Folder", CsvBinDataDirectory, ref CsvBinDataDirectory);
            //         }
            //         EditorGUILayout.HelpBox("All csv binary files will be created in this folder. JumpCSV will load these at runtime, so the folder need under folder Resources", MessageType.Info);
            //     GUILayout.EndHorizontal();

            //     if(!JumpCsvEditorHelper.CheckCsvBinDataDirectory(CsvBinDataDirectory)) {
            //         EditorGUILayout.HelpBox(CsvBinDataDirectory + " IS INVALID BINARY DATA TARGET PATH, MAKE SURE TARGET PATH IS UNDER ./Assets/Resources", MessageType.Error);
            //     }
            //     else {
            //         EditorGUILayout.BeginHorizontal();
            //             EditorGUILayout.PrefixLabel("CSV Binary Folder:");
            //             GUILayout.Label(CsvBinDataDirectory);
            //         EditorGUILayout.EndHorizontal();
            //     }
            //     GUILayout.Space(spaceHeight);
            // GUILayout.EndVertical();


            // GUILayout.BeginHorizontal();
            //     GUILayout.BeginVertical(GUILayout.Width(buttonWidth));
            //         GUILayout.Label("Class Prefix Name", GUILayout.Width(buttonWidth));
            //         if(!string.IsNullOrEmpty(CsvDataClassPrefixName) && !CsvHelper.IsValidVariableName(CsvDataClassPrefixName)) {
            //             EditorGUILayout.HelpBox(CsvDataClassPrefixName + "IS NOT A VAILD NAME, MAKE SURE YOU NAME ONLY CONTAINS LETTER [a-zA-Z0-9_], AND NUMBER IS NOT THE FIRST LETTER", MessageType.Error);
            //         }
            //         CsvDataClassPrefixName = GUILayout.TextField(CsvDataClassPrefixName);
            //         GUILayout.Space(spaceHeight);
            //     GUILayout.EndVertical();

            //     GUILayout.BeginVertical( GUILayout.Width(buttonWidth));
            //         GUILayout.Label("Class Postfix Name", GUILayout.Width(buttonWidth));
            //         if(!string.IsNullOrEmpty(CsvDataClassPostfixName) && !CsvHelper.IsValidVariableName(CsvDataClassPostfixName)) {
            //             EditorGUILayout.HelpBox(CsvDataClassPostfixName + "IS NOT A VAILD NAME, MAKE SURE YOU NAME ONLY CONTAINS LETTER [a-zA-Z0-9_], AND NUMBER IS NOT THE FIRST LETTER", MessageType.Error);
            //         }
            //         CsvDataClassPostfixName = GUILayout.TextField(CsvDataClassPostfixName);
            //         GUILayout.Space(spaceHeight);
            //     GUILayout.EndVertical();
            //     EditorGUILayout.HelpBox("CSV read class name will be named by join prefix name, csv file name and postfix name.", MessageType.Info);

            // GUILayout.EndHorizontal();

            // GUILayout.BeginHorizontal();
            //     GUILayout.BeginVertical(GUILayout.Width(buttonWidth));
            //         GUILayout.Label("Record Prefix Name",GUILayout.Width(buttonWidth));
            //         if(!string.IsNullOrEmpty(CsvDataStructPrefixName) && !CsvHelper.IsValidVariableName(CsvDataStructPrefixName)) {
            //             EditorGUILayout.HelpBox(CsvDataStructPrefixName + "IS NOT A VAILD NAME, MAKE SURE YOU NAME ONLY CONTAINS LETTER [a-zA-Z0-9_], AND NUMBER IS NOT THE FIRST LETTER", MessageType.Error);
            //         }
            //         CsvDataStructPrefixName = GUILayout.TextField(CsvDataStructPrefixName);
            //         GUILayout.Space(spaceHeight);
            //     GUILayout.EndHorizontal();

            //     GUILayout.BeginVertical(GUILayout.Width(buttonWidth));
            //         GUILayout.Label("Record Postfix Name",GUILayout.Width(buttonWidth));
            //         if(!string.IsNullOrEmpty(CsvDataStructPostfixName) && !CsvHelper.IsValidVariableName(CsvDataStructPostfixName)) {
            //             EditorGUILayout.HelpBox(CsvDataStructPostfixName + "IS NOT A VAILD NAME, MAKE SURE YOU NAME ONLY CONTAINS LETTER [a-zA-Z0-9_], AND NUMBER IS NOT THE FIRST LETTER", MessageType.Error);
            //         }
            //         CsvDataStructPostfixName = GUILayout.TextField(CsvDataStructPostfixName);
            //         GUILayout.Space(spaceHeight);
            //     GUILayout.EndHorizontal();
            //     EditorGUILayout.HelpBox("CSV read class will be named by join prefix name, csv file name and postfix name.", MessageType.Info);
            // GUILayout.EndHorizontal();

            // GUILayout.BeginHorizontal();
            // GUILayout.Label("CSV File Extentions",GUILayout.Width(buttonWidth));
            // CsvExtensionNames = GUILayout.TextField(CsvExtensionNames);
            // GUILayout.EndHorizontal();

            // GUILayout.BeginHorizontal();
            // GUILayout.Label("Exclude CSV Files", GUILayout.Width(buttonWidth));
            // ExcludeCsvFiles = GUILayout.TextField(ExcludeCsvFiles);
            // GUILayout.EndHorizontal();

            EditorGUILayout.EndScrollView();

            if (GUILayout.Button("Save", GUILayout.Height(buttonHeight)))
            {
                SaveSettingsValues();
            }

            // if(GUILayout.Button("Test List")) {
            //     CsvManager.Init();
            //     foreach(var t in CharactersData.mItemIdValue.Values) {
            //         Debug.Log(CharactersData.mData[CsvItemId.SILT]._VALUE);
            //     }
            // }

            // if(GUILayout.Button("Test Miss Csv Code")) {
            //     foreach( var f in JumpCsvEditorHelper.GetAllLoseCsvCode()) {
            //         Debug.Log("Miss: " + f);
            //     }
            // }

            // if(GUILayout.Button("Test Miss Binary Data")) {
            //     foreach(var f in JumpCsvEditorHelper.GetAllLoseCsvData()) {
            //         Debug.Log("Miss: " + f);
            //     }
            // }

            // if(GUILayout.Button("Test Expreid Csv Files")) {
            //     foreach(var f in JumpCsvEditorHelper.GetAllExpiredCsvFile()) {
            //         Debug.Log("Expreid: " + f);
            //     }
            // }

            // if(GUILayout.Button("Test Relative Path")) {
            //     Debug.Log("From Path: " + Application.dataPath);
            //     Debug.Log("To Path:" + CsvSpreadSheetFileDirectory);
            //     Debug.Log("Relative: " + JumpCsvEditorHelper.MakeRelativePath(Application.dataPath, CsvSpreadSheetFileDirectory ));
            // }
        }