コード例 #1
0
    public Entity_sheet_Modified CreateSheetModifed(Entity_sheet1_Extra extra, [FolderPath] string input)
    {
        string exportPath = input.Replace(Path.GetFileName(input), $"{extra.name}.asset");

        Entity_sheet_Modified data = (Entity_sheet_Modified)AssetDatabase.LoadAssetAtPath(exportPath, typeof(Entity_sheet_Modified));

        if (data == null)
        {
            data = ScriptableObject.CreateInstance <Entity_sheet_Modified>();
            AssetDatabase.CreateAsset((ScriptableObject)data, exportPath);
            // data.hideFlags = HideFlags.NotEditable;
            data.name = Path.GetFileNameWithoutExtension(exportPath);
        }

        if (data.sheets.Count > 0 && data.sheets[0].list.Count > 0)
        {
            Debug.Log($"{exportPath} will be overriden");
        }

        data.sheets.Clear();
        Entity_sheet_Modified.SheetModified sheet = new Entity_sheet_Modified.SheetModified();
        sheet.name = extra.name;
        data.sheets.Add(sheet);

        for (int i = 0; i < extra.list.Count; i++)
        {
            ParamModified param = new ParamModified(extra.list[i]);
            data.sheets[0].list.Add(param);
        }

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

        EditorUtility.SetDirty(obj);
        return(data);
    }
コード例 #2
0
    public Entity_sheet_Modified GenerateDataThatHasDescription([FilePath] string filePath)
    {
        string exportPath = filePath.Replace(Path.GetExtension(filePath), ".asset");


        Entity_sheet_Modified data = (Entity_sheet_Modified)AssetDatabase.LoadAssetAtPath(exportPath, typeof(Entity_sheet_Modified));

        if (data == null)
        {
            data = ScriptableObject.CreateInstance <Entity_sheet_Modified>();
            AssetDatabase.CreateAsset((ScriptableObject)data, exportPath);
            // data.hideFlags = HideFlags.NotEditable;
            data.name = Path.GetFileNameWithoutExtension(filePath);
        }

        if (data.sheets.Count > 0 && data.sheets[0].list.Count > 0)
        {
            Debug.Log($"{exportPath} will be overriden");
        }

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

            for (int j = 0; j < book.NumberOfSheets; j++)
            {
                ISheet sheet = book.GetSheetAt(j);

                if (sheet == null)
                {
                    Debug.LogError("[QuestData] sheet not found:");
                    continue;
                }

                Entity_sheet_Modified.SheetModified s = new Entity_sheet_Modified.SheetModified();
                s.name = sheet.SheetName;

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

                    ParamModified p = new ParamModified();

                    int k = 0;
                    cell            = row.GetCell(k);
                    p.Description   = (cell == null ? "" : cell.StringCellValue.Trim());
                    cell            = row.GetCell(++k);
                    p.combinedGroup = (cell == null ? "" : cell.StringCellValue);
                    cell            = row.GetCell(++k);
                    p.group         = (int)(cell == null ? 0 : cell.NumericCellValue);
                    cell            = row.GetCell(++k);
                    p.rows          = (int)(cell == null ? 0 : cell.NumericCellValue);
                    cell            = row.GetCell(++k);
                    p.users         = (int)(cell == null ? 0 : cell.NumericCellValue);
                    cell            = row.GetCell(++k);
                    p.machines      = (int)(cell == null ? 0 : cell.NumericCellValue);
                    cell            = row.GetCell(++k);
                    p.F             = (int)(cell == null ? 0 : cell.NumericCellValue);
                    cell            = row.GetCell(++k);
                    p.H             = (int)(cell == null ? 0 : cell.NumericCellValue);
                    cell            = row.GetCell(++k);
                    p.IP            = (cell == null ? "" : cell.StringCellValue);
                    cell            = row.GetCell(++k);
                    p.LicenseHash   = (cell == null ? "" : cell.StringCellValue);
                    cell            = row.GetCell(++k);
                    p.MachineId     = (cell == null ? "" : cell.StringCellValue);
                    cell            = row.GetCell(++k);
                    p.Version       = (cell == null ? "" : cell.StringCellValue);
                    cell            = row.GetCell(++k);
                    p.Location      = (cell == null ? "" : cell.StringCellValue);
                    cell            = row.GetCell(++k);
                    p.Userid        = (cell == null ? 0.0 : cell.NumericCellValue);
                    cell            = row.GetCell(++k);
                    p.count         = (int)(cell == null ? 0 : cell.NumericCellValue);
                    cell            = row.GetCell(++k);
                    p.SerialNumber  = (cell == null ? "" : cell.StringCellValue);
                    cell            = row.GetCell(++k);
                    p.LicenseType   = (cell == null ? "" : cell.StringCellValue);
                    cell            = row.GetCell(++k);
                    p.ShortVer      = (cell == null ? "" : cell.StringCellValue);

                    s.list.Add(p);
                }

                data.sheets.Add(s);
            }
        }

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

        EditorUtility.SetDirty(obj);

        Debug.Log($"Generate intermediate data: {exportPath}");

        return(data);
    }