static void OnPostprocessAllAssets(string[] importedAssets, string[] deletedAssets, string[] movedAssets, string[] movedFromAssetPaths) { foreach (string asset in importedAssets) { if (!filePath.Equals(asset)) { continue; } Directory.CreateDirectory("Assets/ReadExcel/Config/Resources/DataConfig/ "); Roleattributes data = (Roleattributes)AssetDatabase.LoadAssetAtPath(exportPath, typeof(Roleattributes)); if (data == null) { data = ScriptableObject.CreateInstance <Roleattributes> (); AssetDatabase.CreateAsset((ScriptableObject)data, exportPath); data.hideFlags = HideFlags.NotEditable; } ReadExcel.CreatDataInitCs(); data.sheets.Clear(); using (FileStream stream = File.Open(filePath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) { IWorkbook book = null; if (Path.GetExtension(filePath) == ".xls") { book = new HSSFWorkbook(stream); } else { book = new XSSFWorkbook(stream); } foreach (string sheetName in sheetNames) { ISheet sheet = book.GetSheet(sheetName); if (sheet == null) { Debug.LogError("[QuestData] sheet not found:" + sheetName); continue; } Roleattributes.Sheet s = new Roleattributes.Sheet(); s.name = sheetName; for (int i = 2; i <= sheet.LastRowNum; i++) { IRow row = sheet.GetRow(i); ICell cell = null; Roleattributes.Param p = new Roleattributes.Param(); cell = row.GetCell(0); p.id = (int)(cell == null ? 0 : cell.NumericCellValue); cell = row.GetCell(1); p.strength = (int)(cell == null ? 0 : cell.NumericCellValue); cell = row.GetCell(2); p.agile = (int)(cell == null ? 0 : cell.NumericCellValue); cell = row.GetCell(3); p.body = (int)(cell == null ? 0 : cell.NumericCellValue); cell = row.GetCell(4); p.perception = (int)(cell == null ? 0 : cell.NumericCellValue); cell = row.GetCell(5); p.intelligence = (int)(cell == null ? 0 : cell.NumericCellValue); cell = row.GetCell(6); p.luck = (int)(cell == null ? 0 : cell.NumericCellValue); cell = row.GetCell(7); p.hp = (int)(cell == null ? 0 : cell.NumericCellValue); cell = row.GetCell(8); p.hpGrowth = (float)(cell == null ? 0 : cell.NumericCellValue); cell = row.GetCell(9); p.mp = (int)(cell == null ? 0 : cell.NumericCellValue); cell = row.GetCell(10); p.mpGrowth = (float)(cell == null ? 0 : cell.NumericCellValue); cell = row.GetCell(11); p.attack = (int)(cell == null ? 0 : cell.NumericCellValue); cell = row.GetCell(12); p.attackGrowth = (float)(cell == null ? 0 : cell.NumericCellValue); cell = row.GetCell(13); p.Mattack = (int)(cell == null ? 0 : cell.NumericCellValue); cell = row.GetCell(14); p.MattackGrowth = (float)(cell == null ? 0 : cell.NumericCellValue); cell = row.GetCell(15); p.armor = (int)(cell == null ? 0 : cell.NumericCellValue); cell = row.GetCell(16); p.MagicRes = (int)(cell == null ? 0 : cell.NumericCellValue); cell = row.GetCell(17); p.Resistance = (int)(cell == null ? 0 : cell.NumericCellValue); cell = row.GetCell(18); p.Dodge = (int)(cell == null ? 0 : cell.NumericCellValue); cell = row.GetCell(19); p.DodgeGrowth = (float)(cell == null ? 0 : cell.NumericCellValue); s.list.Add(p); } data.sheets.Add(s); } } ScriptableObject obj = AssetDatabase.LoadAssetAtPath(exportPath, typeof(ScriptableObject)) as ScriptableObject; EditorUtility.SetDirty(obj); } }
static void OnPostprocessAllAssets(string[] importedAssets, string[] deletedAssets, string[] movedAssets, string[] movedFromAssetPaths) { foreach (string asset in importedAssets) { if (!filePath.Equals(asset)) { continue; } Directory.CreateDirectory("Assets/ReadExcel/Config/Resources/DataConfig/ "); Equipment data = (Equipment)AssetDatabase.LoadAssetAtPath(exportPath, typeof(Equipment)); if (data == null) { data = ScriptableObject.CreateInstance <Equipment> (); AssetDatabase.CreateAsset((ScriptableObject)data, exportPath); data.hideFlags = HideFlags.NotEditable; } ReadExcel.CreatDataInitCs(); data.sheets.Clear(); using (FileStream stream = File.Open(filePath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) { IWorkbook book = null; if (Path.GetExtension(filePath) == ".xls") { book = new HSSFWorkbook(stream); } else { book = new XSSFWorkbook(stream); } foreach (string sheetName in sheetNames) { ISheet sheet = book.GetSheet(sheetName); if (sheet == null) { Debug.LogError("[QuestData] sheet not found:" + sheetName); continue; } Equipment.Sheet s = new Equipment.Sheet(); s.name = sheetName; for (int i = 2; i <= sheet.LastRowNum; i++) { IRow row = sheet.GetRow(i); ICell cell = null; Equipment.Param p = new Equipment.Param(); cell = row.GetCell(0); p.id = (int)(cell == null ? 0 : cell.NumericCellValue); cell = row.GetCell(1); p.equipTypeID = (int)(cell == null ? 0 : cell.NumericCellValue); cell = row.GetCell(2); p.weight = (int)(cell == null ? 0 : cell.NumericCellValue); cell = row.GetCell(3); p.attack = (int)(cell == null ? 0 : cell.NumericCellValue); cell = row.GetCell(4); p.armor = (int)(cell == null ? 0 : cell.NumericCellValue); cell = row.GetCell(5); p.MagicResistance = (int)(cell == null ? 0 : cell.NumericCellValue); cell = row.GetCell(6); p.strength = (int)(cell == null ? 0 : cell.NumericCellValue); cell = row.GetCell(7); p.agile = (int)(cell == null ? 0 : cell.NumericCellValue); cell = row.GetCell(8); p.body = (int)(cell == null ? 0 : cell.NumericCellValue); cell = row.GetCell(9); p.perception = (int)(cell == null ? 0 : cell.NumericCellValue); cell = row.GetCell(10); p.intelligence = (int)(cell == null ? 0 : cell.NumericCellValue); cell = row.GetCell(11); p.will = (int)(cell == null ? 0 : cell.NumericCellValue); cell = row.GetCell(12); p.ability = (int)(cell == null ? 0 : cell.NumericCellValue); cell = row.GetCell(13); p.propertyDecision = (int)(cell == null ? 0 : cell.NumericCellValue); cell = row.GetCell(14); p.decisionTime = (int)(cell == null ? 0 : cell.NumericCellValue); cell = row.GetCell(15); p.specialRequireID = (int)(cell == null ? 0 : cell.NumericCellValue); cell = row.GetCell(16); p.forgingNum = (int)(cell == null ? 0 : cell.NumericCellValue); p.forging1 = new List <string>(); cell = row.GetCell(17); var forging1temp = (cell == null ? "" : cell.StringCellValue); string [] forging1temps = forging1temp.Split(','); for (int index = 0, iMax = forging1temps.Length; index < iMax; index++) { string val = forging1temps[index]; p.forging1.Add(val); } p.forging2 = new List <string>(); cell = row.GetCell(18); var forging2temp = (cell == null ? "" : cell.StringCellValue); string [] forging2temps = forging2temp.Split(','); for (int index = 0, iMax = forging2temps.Length; index < iMax; index++) { string val = forging2temps[index]; p.forging2.Add(val); } p.forging3 = new List <string>(); cell = row.GetCell(19); var forging3temp = (cell == null ? "" : cell.StringCellValue); string [] forging3temps = forging3temp.Split(','); for (int index = 0, iMax = forging3temps.Length; index < iMax; index++) { string val = forging3temps[index]; p.forging3.Add(val); } p.hasForging = new List <string>(); cell = row.GetCell(20); var hasForgingtemp = (cell == null ? "" : cell.StringCellValue); string [] hasForgingtemps = hasForgingtemp.Split(','); for (int index = 0, iMax = hasForgingtemps.Length; index < iMax; index++) { string val = hasForgingtemps[index]; p.hasForging.Add(val); } s.list.Add(p); } data.sheets.Add(s); } } ScriptableObject obj = AssetDatabase.LoadAssetAtPath(exportPath, typeof(ScriptableObject)) as ScriptableObject; EditorUtility.SetDirty(obj); } }
static void OnPostprocessAllAssets(string[] importedAssets, string[] deletedAssets, string[] movedAssets, string[] movedFromAssetPaths) { foreach (string asset in importedAssets) { if (!filePath.Equals(asset)) { continue; } using (FileStream stream = File.Open(filePath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) { IWorkbook book = null; if (Path.GetExtension(filePath) == ".xls") { book = new HSSFWorkbook(stream); } else { book = new XSSFWorkbook(stream); } if (!Directory.Exists("Assets/ReadExcel/Config/Resources/DataConfig/")) { Directory.CreateDirectory("Assets/ReadExcel/Config/Resources/DataConfig/"); } var exportPath = "Assets/ReadExcel/Config/Resources/DataConfig/Localization_English" + ".asset"; // check scriptable object var data = (Localization_English)AssetDatabase.LoadAssetAtPath(exportPath, typeof(Localization_English)); if (data == null) { data = ScriptableObject.CreateInstance <Localization_English>(); AssetDatabase.CreateAsset((ScriptableObject)data, exportPath); data.hideFlags = HideFlags.NotEditable; } data.Params.Clear(); data.hideFlags = HideFlags.NotEditable; //Creat DataInit Script ReadExcel.CreatDataInitCs(); // check sheet var sheet = book.GetSheet(sheetName); if (sheet == null) { Debug.LogError("[QuestData] sheet not found:" + sheetName); continue; } // add infomation for (int i = 2; i <= sheet.LastRowNum; i++) { IRow row = sheet.GetRow(i); ICell cell = null; var p = new Localization_English.Param(); cell = row.GetCell(0); p.id = (int)(cell == null ? 0 : cell.NumericCellValue); cell = row.GetCell(1); p.value = (cell == null ? "" : cell.StringCellValue); data.Params.Add(p); } // save scriptable object ScriptableObject obj = AssetDatabase.LoadAssetAtPath(exportPath, typeof(ScriptableObject)) as ScriptableObject; EditorUtility.SetDirty(obj); } } }
static void OnPostprocessAllAssets(string[] importedAssets, string[] deletedAssets, string[] movedAssets, string[] movedFromAssetPaths) { foreach (string asset in importedAssets) { if (!filePath.Equals(asset)) { continue; } Directory.CreateDirectory("Assets/ReadExcel/Config/Resources/DataConfig/ "); Skill data = (Skill)AssetDatabase.LoadAssetAtPath(exportPath, typeof(Skill)); if (data == null) { data = ScriptableObject.CreateInstance <Skill> (); AssetDatabase.CreateAsset((ScriptableObject)data, exportPath); data.hideFlags = HideFlags.NotEditable; } ReadExcel.CreatDataInitCs(); data.sheets.Clear(); using (FileStream stream = File.Open(filePath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) { IWorkbook book = null; if (Path.GetExtension(filePath) == ".xls") { book = new HSSFWorkbook(stream); } else { book = new XSSFWorkbook(stream); } foreach (string sheetName in sheetNames) { ISheet sheet = book.GetSheet(sheetName); if (sheet == null) { Debug.LogError("[QuestData] sheet not found:" + sheetName); continue; } Skill.Sheet s = new Skill.Sheet(); s.name = sheetName; for (int i = 2; i <= sheet.LastRowNum; i++) { IRow row = sheet.GetRow(i); ICell cell = null; Skill.Param p = new Skill.Param(); cell = row.GetCell(0); p.id = (int)(cell == null ? 0 : cell.NumericCellValue); cell = row.GetCell(1); p.SkillName = (cell == null ? "" : cell.StringCellValue); cell = row.GetCell(2); p.effectID = (int)(cell == null ? 0 : cell.NumericCellValue); s.list.Add(p); } data.sheets.Add(s); } } ScriptableObject obj = AssetDatabase.LoadAssetAtPath(exportPath, typeof(ScriptableObject)) as ScriptableObject; EditorUtility.SetDirty(obj); } }
static void OnPostprocessAllAssets(string[] importedAssets, string[] deletedAssets, string[] movedAssets, string[] movedFromAssetPaths) { foreach (string asset in importedAssets) { if (!filePath.Equals(asset)) { continue; } using (FileStream stream = File.Open(filePath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) { IWorkbook book = null; if (Path.GetExtension(filePath) == ".xls") { book = new HSSFWorkbook(stream); } else { book = new XSSFWorkbook(stream); } Directory.CreateDirectory("Assets/ReadExcel/Config/Resources/DataConfig/ "); var exportPath = "Assets/ReadExcel/Config/Resources/DataConfig/TestConfig_Sheet1" + ".asset"; // check scriptable object var data = (TestConfig_Sheet1)AssetDatabase.LoadAssetAtPath(exportPath, typeof(TestConfig_Sheet1)); if (data == null) { data = ScriptableObject.CreateInstance <TestConfig_Sheet1>(); AssetDatabase.CreateAsset((ScriptableObject)data, exportPath); data.hideFlags = HideFlags.NotEditable; } data.Params.Clear(); data.hideFlags = HideFlags.NotEditable; //Creat DataInit Script ReadExcel.CreatDataInitCs(); // check sheet var sheet = book.GetSheet(sheetName); if (sheet == null) { Debug.LogError("[QuestData] sheet not found:" + sheetName); continue; } // add infomation for (int i = 2; i <= sheet.LastRowNum; i++) { IRow row = sheet.GetRow(i); ICell cell = null; var p = new TestConfig_Sheet1.Param(); cell = row.GetCell(0); p.id = (int)(cell == null ? 0 : cell.NumericCellValue); cell = row.GetCell(1); p.name = (cell == null ? "" : cell.StringCellValue); cell = row.GetCell(2); p.age = (int)(cell == null ? 0 : cell.NumericCellValue); p.ts = new List <int>(); cell = row.GetCell(3); var tstemp = (cell == null ? "" : cell.StringCellValue); string [] tstemps = tstemp.Split(','); for (int index = 0, iMax = tstemps.Length; index < iMax; index++) { int val = 0; val = int.Parse(tstemps[index]); p.ts.Add(val); } p.m = new List <string>(); cell = row.GetCell(4); var mtemp = (cell == null ? "" : cell.StringCellValue); string [] mtemps = mtemp.Split(','); for (int index = 0, iMax = mtemps.Length; index < iMax; index++) { string val = mtemps[index]; p.m.Add(val); } data.Params.Add(p); } // save scriptable object ScriptableObject obj = AssetDatabase.LoadAssetAtPath(exportPath, typeof(ScriptableObject)) as ScriptableObject; EditorUtility.SetDirty(obj); } } }