Ejemplo n.º 1
0
 void convertToItemBase(TempItemBase.Param n, ItemBase itemBase)
 {
     itemBase.ID   = n.ID;
     itemBase.Name = n.Name;
     if (ItemBase.BaseType.TryParse(n.Type, out itemBase.Type) == false)
     {
         itemBase.Type = ItemBase.BaseType.Null;
     }
     if (ItemBase.ItemAction.TryParse(n.ActionName, out itemBase.ActionType) == false)
     {
         itemBase.ActionType = ItemBase.ItemAction.Null;
     }
     foreach (var material in n.Material.Split(new[] { ", " }, StringSplitOptions.None))
     {
         ItemBase.ItemMaterialType materialType;
         if (ItemBase.ItemMaterialType.TryParse(material, out materialType))
         {
             if (itemBase.MaterialTypes.Count < 3)
             {
                 itemBase.MaterialTypes.Add(materialType);
             }
         }
     }
     if (itemBase.MaterialTypes.Count == 0)
     {
         itemBase.MaterialTypes.Add(ItemBase.ItemMaterialType.Null);
     }
     itemBase.Value       = n.Value;
     itemBase.Price       = n.Price;
     itemBase.Quality     = n.Quality;
     itemBase.Range       = n.Range;
     itemBase.InitNum     = n.InitNum;
     itemBase.Description = n.Description;
 }
    static void OnPostprocessAllAssets(string[] importedAssets, string[] deletedAssets, string[] movedAssets, string[] movedFromAssetPaths)
    {
        foreach (string asset in importedAssets)
        {
            if (!filePath.Equals(asset))
            {
                continue;
            }

            TempItemBase data = (TempItemBase)AssetDatabase.LoadAssetAtPath(exportPath, typeof(TempItemBase));
            if (data == null)
            {
                data = ScriptableObject.CreateInstance <TempItemBase> ();
                AssetDatabase.CreateAsset((ScriptableObject)data, exportPath);
                data.hideFlags = HideFlags.NotEditable;
            }

            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;
                    }

                    TempItemBase.Sheet s = new TempItemBase.Sheet();
                    s.name = sheetName;

                    for (int i = 1; i <= sheet.LastRowNum; i++)
                    {
                        IRow  row  = sheet.GetRow(i);
                        ICell cell = null;

                        TempItemBase.Param p = new TempItemBase.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.Type = (cell == null ? "" : cell.StringCellValue);
                        cell = row.GetCell(3); p.ActionName = (cell == null ? "" : cell.StringCellValue);
                        cell = row.GetCell(4); p.Material = (cell == null ? "" : cell.StringCellValue);
                        cell = row.GetCell(5); p.Value = (int)(cell == null ? 0 : cell.NumericCellValue);
                        cell = row.GetCell(6); p.Price = (int)(cell == null ? 0 : cell.NumericCellValue);
                        cell = row.GetCell(7); p.Quality = (int)(cell == null ? 0 : cell.NumericCellValue);
                        cell = row.GetCell(8); p.Range = (int)(cell == null ? 0 : cell.NumericCellValue);
                        cell = row.GetCell(9); p.InitNum = (int)(cell == null ? 0 : cell.NumericCellValue);
                        cell = row.GetCell(10); p.Description = (cell == null ? "" : cell.StringCellValue);
                        s.list.Add(p);
                    }
                    data.sheets.Add(s);
                }
            }

            ScriptableObject obj = AssetDatabase.LoadAssetAtPath(exportPath, typeof(ScriptableObject)) as ScriptableObject;
            EditorUtility.SetDirty(obj);
        }
    }