Ejemplo n.º 1
0
    void convertToRunnerBase(TempRunnerBase.Param n, RunnerBase runnerBase)
    {
        runnerBase.ID            = n.ID;
        runnerBase.Name          = n.Name;
        runnerBase.ImageFileName = n.ImageFileName;

        foreach (var nextExp in n.NextExp.Split(new[] { ", " }, StringSplitOptions.None))
        {
            int next;
            if (int.TryParse(nextExp, out next))
            {
                if (runnerBase.NextExp.Count < 2)
                {
                    runnerBase.NextExp.Add(next);
                }
            }
        }

        foreach (var price in n.Price.Split(new[] { ", " }, StringSplitOptions.None))
        {
            int p;
            if (int.TryParse(price, out p))
            {
                if (runnerBase.Price.Count < 3)
                {
                    runnerBase.Price.Add(p);
                }
            }
        }

        foreach (var power in n.Power.Split(new[] { ", " }, StringSplitOptions.None))
        {
            int pow;
            if (int.TryParse(power, out pow))
            {
                if (runnerBase.Power.Count < 3)
                {
                    runnerBase.Power.Add(pow);
                }
            }
        }

        foreach (var personality in n.Personality.Split(new[] { ". " }, StringSplitOptions.None))
        {
            RunnerBase.Personality personal;
            Enum.TryParse(personality, out personal);
        }

        runnerBase.Description = n.Description;
    }
Ejemplo n.º 2
0
    static void OnPostprocessAllAssets(string[] importedAssets, string[] deletedAssets, string[] movedAssets, string[] movedFromAssetPaths)
    {
        foreach (string asset in importedAssets)
        {
            if (!filePath.Equals(asset))
            {
                continue;
            }

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

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

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

                        TempRunnerBase.Param p = new TempRunnerBase.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.ImageFileName = (cell == null ? "" : cell.StringCellValue);
                        cell = row.GetCell(3); p.NextExp = (cell == null ? "" : cell.StringCellValue);
                        cell = row.GetCell(4); p.Price = (cell == null ? "" : cell.StringCellValue);
                        cell = row.GetCell(5); p.Power = (cell == null ? "" : cell.StringCellValue);
                        cell = row.GetCell(6); p.Personality = (cell == null ? "" : cell.StringCellValue);
                        cell = row.GetCell(7); 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);
        }
    }