示例#1
0
    public override bool Load()
    {
        Spells targetData = target as Spells;

        string path = targetData.SheetName;

        if (!File.Exists(path))
        {
            return(false);
        }

        string sheet = targetData.WorksheetName;

        ExcelQuery query = new ExcelQuery(path, sheet);

        if (query != null && query.IsValid())
        {
            targetData.dataArray = query.Deserialize <SpellsData>().ToArray();
            EditorUtility.SetDirty(targetData);
            AssetDatabase.SaveAssets();
            return(true);
        }
        else
        {
            return(false);
        }
    }
    static void OnPostprocessAllAssets(string[] importedAssets, string[] deletedAssets, string[] movedAssets, string[] movedFromAssetPaths)
    {
        foreach (string asset in importedAssets)
        {
            if (!filePath.Equals(asset))
            {
                continue;
            }

            Sheet1 data = (Sheet1)AssetDatabase.LoadAssetAtPath(assetFilePath, typeof(Sheet1));
            if (data == null)
            {
                data               = ScriptableObject.CreateInstance <Sheet1> ();
                data.SheetName     = filePath;
                data.WorksheetName = sheetName;
                AssetDatabase.CreateAsset((ScriptableObject)data, assetFilePath);
                //data.hideFlags = HideFlags.NotEditable;
            }

            //data.dataArray = new ExcelQuery(filePath, sheetName).Deserialize<Sheet1Data>().ToArray();

            //ScriptableObject obj = AssetDatabase.LoadAssetAtPath (assetFilePath, typeof(ScriptableObject)) as ScriptableObject;
            //EditorUtility.SetDirty (obj);

            ExcelQuery query = new ExcelQuery(filePath, sheetName);
            if (query != null && query.IsValid())
            {
                data.dataArray = query.Deserialize <Sheet1Data>().ToArray();
                ScriptableObject obj = AssetDatabase.LoadAssetAtPath(assetFilePath, typeof(ScriptableObject)) as ScriptableObject;
                EditorUtility.SetDirty(obj);
            }
        }
    }
示例#3
0
    SheetType LoadMachineExcelAsset <SheetType, DataType>(string excelName, string sheetName)
        where SheetType : new()
    {
        string totalDir = Path.Combine(Application.dataPath, "Excels/Machine/");
        string path     = totalDir + excelName + ".xls";

        Debug.Assert(File.Exists(path));

        ExcelQuery query = new ExcelQuery(path, sheetName);

        SheetType result = new SheetType();
        Type      type   = result.GetType();

        System.Reflection.PropertyInfo info = type.GetProperty("DataArray");
        DataType[] array = query.Deserialize <DataType>().ToArray();
        info.SetValue(result, array, null);
        return(result);
    }
    public override bool Load()
    {
        Player targetData = target as Player;

        string path = targetData.SheetName;
        if (!File.Exists(path))
            return false;

        string sheet = targetData.WorksheetName;

        ExcelQuery query = new ExcelQuery(path, sheet);
        if (query != null && query.IsValid())
        {
            targetData.dataArray = query.Deserialize<PlayerData>().ToArray();
            EditorUtility.SetDirty(targetData);
            AssetDatabase.SaveAssets();
            return true;
        }
        else
            return false;
    }