コード例 #1
0
 void convertToItemProperty(TempItemProperty.Param n, ItemProperty itemProperty)
 {
     itemProperty.ID   = n.ID;
     itemProperty.Name = n.Name;
     if (ItemProperty.PropType.TryParse(n.Type, out itemProperty.Type) == false)
     {
         itemProperty.Type = ItemProperty.PropType.Null;
     }
     itemProperty.Value   = n.Value;
     itemProperty.Price   = n.Price;
     itemProperty.Quality = n.Quality;
     itemProperty.Range   = n.Range;
     itemProperty.InitNum = n.InitNum;
 }
コード例 #2
0
    static void OnPostprocessAllAssets(string[] importedAssets, string[] deletedAssets, string[] movedAssets, string[] movedFromAssetPaths)
    {
        foreach (string asset in importedAssets)
        {
            if (!filePath.Equals(asset))
            {
                continue;
            }

            TempItemProperty data = (TempItemProperty)AssetDatabase.LoadAssetAtPath(exportPath, typeof(TempItemProperty));
            if (data == null)
            {
                data = ScriptableObject.CreateInstance <TempItemProperty> ();
                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;
                    }

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

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

                        TempItemProperty.Param p = new TempItemProperty.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.Value = (int)(cell == null ? 0 : cell.NumericCellValue);
                        cell = row.GetCell(4); p.Price = (int)(cell == null ? 0 : cell.NumericCellValue);
                        cell = row.GetCell(5); p.Quality = (int)(cell == null ? 0 : cell.NumericCellValue);
                        cell = row.GetCell(6); p.Range = (int)(cell == null ? 0 : cell.NumericCellValue);
                        cell = row.GetCell(7); p.InitNum = (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);
        }
    }