Esempio n. 1
0
        //対象のエクセルファイルを全て読み込み
        StringGridDictionary ReadExcel(string path)
        {
            StringGridDictionary book = ExcelParser.Read(path, '#', Project.ParseFormula, Project.ParseNumreic);

            book.RemoveSheets(@"^#");
            return(book);
        }
        StringGridDictionary ConvertToLocalized(StringGridDictionary gridTbl)
        {
            List <string> languageNameList = LanguageNameList();

            StringGridDictionary localizedGirdTbl = new StringGridDictionary();

            foreach (var keyValue in gridTbl.List)
            {
                int        index;
                StringGrid grid = keyValue.Grid;
                if (grid.TryGetColumnIndex(TextKey, out index))
                {
                    StringGrid localizedGird = new StringGrid(grid.Name, grid.SheetName, CsvType.Tsv);
                    localizedGird.AddRow(languageNameList);
                    for (int i = 0; i < grid.Rows.Count; ++i)
                    {
                        if (i == 0)
                        {
                            continue;
                        }
                        string text = grid.Rows[i].ParseCellOptional <string>(TextKey, "");
                        localizedGird.AddRow(new List <string>(new string[] { text }));
                    }
                    localizedGirdTbl.Add(new StringGridDictionaryKeyValue(grid.SheetName, localizedGird));
                }
            }
            return(localizedGirdTbl);
        }
Esempio n. 3
0
 //未インポートのシナリオデータを追加
 public void AddSrourceBook(StringGridDictionary book)
 {
     foreach (var sheet in book.List)
     {
         GridList.Add(sheet.Grid);
     }
 }
Esempio n. 4
0
        //ファイル書き込みをせずに、バイナリデータにコンバートする
        internal bool TryConvertToCsvList(List <string> excelPathList, int version, out List <CsvInfo> csvInfoList)
        {
            csvInfoList = new List <CsvInfo>();
            if (excelPathList.Count <= 0)
            {
                return(false);
            }
            //対象のエクセルファイルを全て読み込み
            StringGridDictionary readSheets = ReadAllExcelFiles(excelPathList);

            if (readSheets.List.Count <= 0)
            {
                return(false);
            }

            //各シートをコンバート
            scenarioSheetDictionary.Clear();
            foreach (var sheet in readSheets.List)
            {
                CsvInfo csvInfo;
                if (TryConvertSheet(sheet, out csvInfo))
                {
                    csvInfoList.Add(csvInfo);
                }
            }
            //シナリオ設定シートは個別にコンバート
            csvInfoList.Add(ConvertScenarioSetting(version));

            ///起動用CSVをコンバート
            csvInfoList.Add(ConvertBootSetting(version));
            return(true);
        }
        //設定データをインポート
        void ImportSettingBook(StringGridDictionary book, string path)
        {
            //インポート後のスクリプタブルオブジェクトを作成
            string assetPath = Path.GetDirectoryName(path) + "/" + Path.GetFileNameWithoutExtension(path) + SettingAssetExt;

            foreach (var sheet in book.List)
            {
                StringGrid grid = sheet.Grid;
                //設定データか、シナリオデータかチェック
                if (AdvSettingDataManager.IsBootSheet(sheet.Name) || AdvSettingDataManager.IsSettingsSheet(sheet.Name))
                {
                    //設定データのアセットを作成
                    if (assetSetting == null)
                    {
                        assetSetting = UtageEditorToolKit.GetImportedAssetCreateIfMissing <AdvSettingDataManager>(assetPath);
                        assetSetting.Clear();
                    }
                    assetSetting.hideFlags = HideFlags.NotEditable;
                    assetSetting.ParseFromExcel(sheet.Name, grid);
                }
            }

            if (assetSetting != null)
            {
                assetSetting.EditorTestInit();
                Debug.Log(LanguageAdvErrorMsg.LocalizeTextFormat(AdvErrorMsg.Import, assetPath));
                //変更を反映
                EditorUtility.SetDirty(assetSetting);
            }
        }
        //ブックのインポート
        void ImportScenarioBook(StringGridDictionary book, string path)
        {
            //シナリオデータ用のスクリプタブルオブジェクトを宣言
            string scenarioAssetPath = Path.ChangeExtension(path, ScenarioAssetExt);
            AdvScenarioDataExported assetScenario = null;

            foreach (var sheet in book.List)
            {
                StringGrid grid = sheet.Grid;
                //設定データか、シナリオデータかチェック
                if (!AdvSettingDataManager.IsBootSheet(sheet.Name) && !AdvSettingDataManager.IsSettingsSheet(sheet.Name))
                {
                    //シナリオデータのアセットを作成
                    if (assetScenario == null)
                    {
                        assetScenario = UtageEditorToolKit.GetImportedAssetCreateIfMissing <AdvScenarioDataExported>(scenarioAssetPath);
                        assetScenario.Clear();
                    }
                    assetScenario.hideFlags = HideFlags.NotEditable;
                    assetScenario.ParseFromExcel(sheet.Name, grid);
                    if (assetSetting != null)
                    {
                        AdvScenarioData scenarioData = assetScenario.ErrorCheck(sheet.Name, grid, assetSetting);
                        scenarioDataTbl.Add(sheet.Name, scenarioData);
                    }
                }
            }

            //変更を反映
            if (assetScenario != null)
            {
                Debug.Log(LanguageAdvErrorMsg.LocalizeTextFormat(AdvErrorMsg.Import, scenarioAssetPath));
                EditorUtility.SetDirty(assetScenario);
            }
        }
Esempio n. 7
0
 //ブックの読み込み
 static void ReadBook(IWorkbook book, string path, StringGridDictionary gridDictionary)
 {
     for (int i = 0; i < book.NumberOfSheets; ++i)
     {
         ISheet     sheet = book.GetSheetAt(i);
         StringGrid grid  = ReadSheet(sheet, path);
         gridDictionary.Add(new StringGridDictionaryKeyValue(sheet.SheetName, grid));
     }
 }
 internal AdvExcelSheets(string path)
 {
     this.SettingsSheets = new List <StringGrid>();
     this.ScenarioSheets = new List <StringGrid>();
     this.CsvList        = new List <CsvInfo>();
     this.Path           = path;
     this.Name           = System.IO.Path.GetFileNameWithoutExtension(Path);
     this.sheets         = ExcelParser.Read(path, '#', false);
     this.sheets.RemoveSheets(@"^#");
 }
Esempio n. 9
0
 void Convert(string outputDirectiory, List <string> assetPathList)
 {
     foreach (string path in assetPathList)
     {
         StringGridDictionary gridTbl = ExcelParser.Read(path, '#', AdvScenarioDataBuilderWindow.ProjectData.ParseFormula, AdvScenarioDataBuilderWindow.ProjectData.ParseNumreic);
         gridTbl.RemoveSheets(@"^#");
         string outputPath = FilePathUtil.Combine(outputDirectiory, FilePathUtil.GetFileName(path));
         ExcelParser.Write(outputPath, ConvertToLocalized(gridTbl));
     }
 }
 void Convert(string outputDirectiory, List <string> assetPathList)
 {
     foreach (string path in assetPathList)
     {
         StringGridDictionary gridTbl = ExcelParser.Read(path);
         gridTbl.RemoveSheets(@"^#");
         string outputPath = FilePathUtil.Combine(outputDirectiory, FilePathUtil.GetFileName(path));
         ExcelParser.Write(outputPath, ConvertToLocalized(gridTbl));
     }
 }
Esempio n. 11
0
        //ファイルの読み込み
        public bool Import(List <string> pathList)
        {
            //対象のエクセルファイルを全て読み込み
            Dictionary <string, StringGridDictionary> bookDictionary = new Dictionary <string, StringGridDictionary>();

            foreach (string path in pathList)
            {
                if (!string.IsNullOrEmpty(path))
                {
                    StringGridDictionary book = ExcelParser.Read(path);
                    if (book.List.Count > 0)
                    {
                        bookDictionary.Add(path, book);
                    }
                }
            }

            if (bookDictionary.Count <= 0)
            {
                return(false);
            }

            assetSetting = null;
            //設定データをインポート
            foreach (string path in bookDictionary.Keys)
            {
                ImportSettingBook(bookDictionary[path], path);
                if (assetSetting != null)
                {
                    break;
                }
            }
            if (assetSetting == null)
            {
                return(false);
            }

            AssetFileManager.IsEditorErrorCheck = true;
            AdvCommand.IsEditorErrorCheck       = true;
            TextData.CallbackCalcExpression     = assetSetting.DefaultParam.CalcExpressionNotSetParam;
            //シナリオデータをインポート
            foreach (string path in bookDictionary.Keys)
            {
                ImportScenarioBook(bookDictionary[path], path);
            }
            TextData.CallbackCalcExpression = null;

            //シナリオラベルのリンクチェック
            ErroeCheckScenarioLabel();

            AdvCommand.IsEditorErrorCheck       = false;
            AssetFileManager.IsEditorErrorCheck = false;
            return(true);
        }
Esempio n. 12
0
        //対象のエクセルファイルを全て読み込み
        StringGridDictionary ReadExcel(string path)
        {
            StringGridDictionary book = ExcelParser.Read(path, '#', Project.ParseFormula, Project.ParseNumreic);

            book.RemoveSheets(@"^#");
            if (Project.EnableCommentOutOnImport)
            {
                book.EraseCommentOutStrings(@"//");
            }
            return(book);
        }
Esempio n. 13
0
        bool ImportChapter(string chapterName, List <string> pathList)
        {
            if (pathList.Count <= 0)
            {
                return(false);
            }

            List <AdvImportBook> bookAssetList = new List <AdvImportBook>();

            //エクセルファイルのアセットを取得
            foreach (var path in pathList)
            {
                if (string.IsNullOrEmpty(path))
                {
                    continue;
                }

                AdvImportBook bookAsset;
                //再インポートが必要なアセットを取得
                //失敗する→再インポートが必要なし
                if (CheckReimport(path, out bookAsset))
                {
                    Debug.Log("Reimport " + path);
                    //対象のエクセルファイルを読み込み
                    StringGridDictionary book = ReadExcel(path);
                    if (book.List.Count <= 0)
                    {
                        //中身がない
                        continue;
                    }
                    //末尾の空白文字をチェック
                    if (Project.CheckWhiteSpaceEndOfCell)
                    {
                        CheckWhiteSpaceEndOfCell(book);
                    }
                    bookAsset.Clear();
                    bookAsset.AddSrourceBook(book);
                }
                bookAssetList.Add(bookAsset);
            }
            //インポート処理をする
            ImportChapter(chapterName, bookAssetList);

            //変更を反映
            foreach (var asset in bookAssetList)
            {
                Debug.Log(LanguageAdvErrorMsg.LocalizeTextFormat(AdvErrorMsg.Import, asset.name));
                EditorUtility.SetDirty(asset);
            }
            return(true);
        }
Esempio n. 14
0
        //対象のエクセルファイルを全て読み込み
        StringGridDictionary ReadAllExcelFiles(List <string> excelPathList)
        {
            StringGridDictionary readSheets = new StringGridDictionary();

            foreach (string assetPath in excelPathList)
            {
                if (!string.IsNullOrEmpty(assetPath))
                {
                    StringGridDictionary dictionary = ExcelParser.Read(assetPath);
                    foreach (var sheet in dictionary.List)
                    {
                        readSheets.Add(sheet);
                    }
                }
            }
            return(readSheets);
        }
Esempio n. 15
0
        //対象のエクセルファイルを全て読み込み
        Dictionary <string, StringGridDictionary> ReadExcels(List <string> pathList)
        {
            Dictionary <string, StringGridDictionary> bookDictionary = new Dictionary <string, StringGridDictionary>();

            foreach (string path in pathList)
            {
                if (!string.IsNullOrEmpty(path))
                {
                    StringGridDictionary book = ExcelParser.Read(path);
                    book.RemoveSheets(@"^#");
                    if (book.List.Count > 0)
                    {
                        bookDictionary.Add(path, book);
                    }
                }
            }
            return(bookDictionary);
        }
Esempio n. 16
0
        //ブックのインポート
        AdvImportBook ImportBook(StringGridDictionary book, string path)
        {
            //シナリオデータ用のスクリプタブルオブジェクトを宣言
            string        bookAssetPath = Path.ChangeExtension(path, BookAssetExt);
            AdvImportBook asset         = UtageEditorToolKit.GetImportedAssetCreateIfMissing <AdvImportBook>(bookAssetPath);

            asset.hideFlags = HideFlags.NotEditable;
            asset.Clear();

            foreach (var sheet in book.List)
            {
                asset.AddData(sheet.Grid);
            }

            //変更を反映
            Debug.Log(LanguageAdvErrorMsg.LocalizeTextFormat(AdvErrorMsg.Import, bookAssetPath));
            EditorUtility.SetDirty(asset);
            return(asset);
        }
Esempio n. 17
0
        public static IWorkbook MakeBook(StringGridDictionary gridDictionary)
        {
            IWorkbook book = new HSSFWorkbook();

            foreach (var item in gridDictionary.List)
            {
                StringGrid grid  = item.Grid;
                ISheet     sheet = book.CreateSheet(grid.SheetName);
                for (int i = 0; i < grid.Rows.Count; ++i)
                {
                    StringGridRow gridRow = grid.Rows[i];
                    IRow          row     = sheet.CreateRow(i);
                    for (int j = 0; j < gridRow.Strings.Length; ++j)
                    {
                        row.CreateCell(j).SetCellValue(gridRow.Strings[j]);
                    }
                }
            }
            return(book);
        }
Esempio n. 18
0
        //ファイルの読み込み
        public static StringGridDictionary Read(string path)
        {
            StringGridDictionary gridDictionary = new StringGridDictionary();

            if (IsExcelFile(path))
            {
                string ext = Path.GetExtension(path);
                using (FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
                {
                    if (ext == ExtXls)
                    {
                        ReadBook(new HSSFWorkbook(fs), path, gridDictionary);
                    }
                    else if (ext == ExtXlsx)
                    {
                        ReadBook(new XSSFWorkbook(fs), path, gridDictionary);
                    }
                }
            }
            return(gridDictionary);
        }
        /// <summary>
        /// コンバートする
        /// </summary>
        /// <param name="folderPath">出力先パス</param>
        /// <param name="assetPathList">読み込むエクセルファイルのリスト</param>
        /// <returns>コンバートしたらtrue。失敗したらfalse</returns>
        public bool Convert(string folderPath, List <string> assetPathList, int version)
        {
            scenarioSheetDictionary.Clear();
            if (!string.IsNullOrEmpty(folderPath) && assetPathList.Count > 0)
            {
                //対象のエクセルファイルを全て読み込み
                StringGridDictionary readSheet = new StringGridDictionary();
                foreach (string assetPath in assetPathList)
                {
                    if (!string.IsNullOrEmpty(assetPath))
                    {
                        StringGridDictionary dictionary = ExcelParser.Read(assetPath);
                        foreach (var sheet in dictionary.List)
                        {
                            readSheet.Add(sheet);
                        }
                    }
                }

                if (readSheet.List.Count <= 0)
                {
                    return(false);
                }

                //各シートをコンバート
                foreach (var sheet in readSheet.List)
                {
                    ConvertSheet(sheet, folderPath);
                }
                //シナリオ設定シートは個別にコンバート
                WriteScenarioSetting(folderPath, version);

                ///起動用CSVをコンバート
                WriteBootSetting(folderPath, version);

                return(true);
            }
            return(false);
        }
Esempio n. 20
0
        public static void Write(string path, StringGridDictionary gridDictionary)
        {
/*			string ext = Path.GetExtension (path);
 *                      switch (ext)
 *                      {
 *                              case ExtXls:
 *                                      book = new HSSFWorkbook();
 *                                      break;
 *                              case ExtXlsx:
 *                                      book = new XSSFWorkbook();
 *                                      break;
 *                              default:
 *                                      break;
 *                      }
 */
            path = FilePathUtil.ChangeExtension(path, ExtXls);
            IWorkbook book = MakeBook(gridDictionary);

            using (FileStream fs = new FileStream(path, FileMode.OpenOrCreate, FileAccess.Write))
            {
                book.Write(fs);
            }
        }
Esempio n. 21
0
        //ファイルの読み込み
        public static StringGridDictionary Read(string path, char ignoreSheetMark, bool parseFormula, bool parseNumreic)
        {
            UnityEngine.Profiling.Profiler.BeginSample("ReadExcel");
            StringGridDictionary gridDictionary = new StringGridDictionary();

            if (IsExcelFile(path))
            {
                string ext = Path.GetExtension(path);
                using (FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
                {
                    if (ext == ExtXls)
                    {
                        ReadBook(new HSSFWorkbook(fs), path, ignoreSheetMark, parseFormula, parseNumreic, gridDictionary);
                    }
                    else if (ext == ExtXlsx)
                    {
                        ReadBook(new XSSFWorkbook(fs), path, ignoreSheetMark, parseFormula, parseNumreic, gridDictionary);
                    }
                }
            }
            UnityEngine.Profiling.Profiler.EndSample();
            return(gridDictionary);
        }
Esempio n. 22
0
//#if UNITY_EDITOR

        /// <summary>
        /// エクセルからCSVファイルにコンバートする際に、シナリオ設定データをマージして作成する
        /// </summary>
        /// <param name="grid">シナリオ設定データ</param>
        /// <param name="scenarioSheetDictionary">シナリオデータ</param>
        /// <returns>マージしたシナリオ設定データ</returns>
        public static StringGrid MargeScenarioData(StringGrid grid, StringGridDictionary scenarioSheetDictionary, int version)
        {
            if (grid == null)
            {
                grid = new StringGrid(AdvSettingDataManager.SheetNameScenario, CsvType.Tsv);
                grid.AddRow(new List <string> {
                    AdvParser.Localize(AdvColumnName.FileName), AdvParser.Localize(AdvColumnName.Version)
                });
                grid.ParseHeader();
            }

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

            foreach (string sheetName in scenarioSheetDictionary.Keys)
            {
                bool isFind = false;
                foreach (StringGridRow row in grid.Rows)
                {
                    if (AdvParser.ParseCell <string>(row, AdvColumnName.FileName) == sheetName)
                    {
                        isFind = true;
                    }
                }
                if (!isFind)
                {
                    addScnenarioList.Add(sheetName);
                }
            }
            foreach (string sheetName in addScnenarioList)
            {
                grid.AddRow(new List <string> {
                    sheetName, "" + version
                });
            }
            return(grid);
        }
        //ファイルの読み込み
        public bool Import(List <string> pathList)
        {
            //対象のエクセルファイルを全て読み込み
            Dictionary <string, StringGridDictionary> bookDictionary = new Dictionary <string, StringGridDictionary>();

            foreach (string path in pathList)
            {
                if (!string.IsNullOrEmpty(path))
                {
                    StringGridDictionary book = ExcelParser.Read(path);
                    if (book.List.Count > 0)
                    {
                        bookDictionary.Add(path, book);
                    }
                }
            }

            if (bookDictionary.Count <= 0)
            {
                return(false);
            }

            AdvEngine engine = UtageEditorToolKit.FindComponentAllInTheScene <AdvEngine>();

            if (engine != null)
            {
                engine.BootInitCustomCommand();
            }
            assetSetting = null;
            //設定データをインポート
            foreach (string path in bookDictionary.Keys)
            {
                ImportSettingBook(bookDictionary[path], path);
                if (assetSetting != null)
                {
                    break;
                }
            }
            if (assetSetting == null)
            {
                return(false);
            }

            AssetFileManager.IsEditorErrorCheck = true;
            AdvCommand.IsEditorErrorCheck       = true;
            GraphicInfo.CallbackExpression      = assetSetting.DefaultParam.CalcExpressionBoolean;
            TextParser.CallbackCalcExpression   = assetSetting.DefaultParam.CalcExpressionNotSetParam;
            iTweenData.CallbackGetValue         = assetSetting.DefaultParam.GetParameter;

            //シナリオデータをインポート
            foreach (string path in bookDictionary.Keys)
            {
                ImportScenarioBook(bookDictionary[path], path);
            }
            GraphicInfo.CallbackExpression    = null;
            TextParser.CallbackCalcExpression = null;
            iTweenData.CallbackGetValue       = null;

            //シナリオラベルのリンクチェック
            ErroeCheckScenarioLabel();

            AdvCommand.IsEditorErrorCheck       = false;
            AssetFileManager.IsEditorErrorCheck = false;
            return(true);
        }
Esempio n. 24
0
        //末尾の空白文字をチェック
        private void CheckWhiteSpaceEndOfCell(StringGridDictionary book)
        {
            AdvEditorSettingWindow editorSetting = AdvEditorSettingWindow.GetInstance();

            if (UnityEngine.Object.ReferenceEquals(editorSetting, null))
            {
                return;
            }
            if (!editorSetting.CheckWhiteSpaceOnImport)
            {
                return;
            }

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

            ignoreHeader.Add("Text");
            if (LanguageManagerBase.Instance != null)
            {
                foreach (string language in LanguageManagerBase.Instance.Languages)
                {
                    ignoreHeader.Add(language);
                }
            }

            foreach (var sheet in book.Values)
            {
                List <int> ignoreIndex = new List <int>();
                foreach (var item in ignoreHeader)
                {
                    int index;
                    if (sheet.Grid.TryGetColumnIndex(item, out index))
                    {
                        ignoreIndex.Add(index);
                    }
                }
                foreach (var row in sheet.Grid.Rows)
                {
                    if (row.RowIndex == 0)
                    {
                        continue;
                    }

                    for (int i = 0; i < row.Strings.Length; ++i)
                    {
                        string str = row.Strings[i];
                        if (str.Length <= 0)
                        {
                            continue;
                        }
                        if (ignoreIndex.Contains(i))
                        {
                            continue;
                        }

                        int endIndex = str.Length - 1;
                        if (char.IsWhiteSpace(str[endIndex]))
                        {
                            Debug.LogWarning(row.ToErrorString("Last characer is white space [" + ColorUtil.AddColorTag(str, ColorUtil.Red) + "]  \n"));
                        }
                    }
                }
            }
        }
Esempio n. 25
0
 //ブックの読み込み
 static void ReadBook(IWorkbook book, string path, char ignoreSheetMark, bool parseFormula, bool parseNumreic, StringGridDictionary gridDictionary)
 {
     for (int i = 0; i < book.NumberOfSheets; ++i)
     {
         UnityEngine.Profiling.Profiler.BeginSample("ReadBook");
         ISheet     sheet = book.GetSheetAt(i);
         StringGrid grid  = ReadSheet(sheet, path, ignoreSheetMark, parseFormula, parseNumreic);
         gridDictionary.Add(new StringGridDictionaryKeyValue(sheet.SheetName, grid));
         UnityEngine.Profiling.Profiler.EndSample();
     }
 }