Пример #1
0
    protected bool TryExport()
    {
        T[] arrayOfData = GetArrayOfData();
        if (arrayOfData == null)
        {
            return(false);
        }
        string content = JsonSerialiserService.SerialyseArray(arrayOfData);

        string pathToSaveTo = GetExportDataPath();

        //Debug.Log(pathToSaveTo);

        File.WriteAllText(pathToSaveTo, content, Encoding.UTF8);
        return(true);
    }
Пример #2
0
    protected bool TryImport()
    {
        string path = GetImportDataPath();

        if (!File.Exists(path))
        {
            Debug.Log("Missing JSON file !");
            return(false);
        }

        string content = File.ReadAllText(path, Encoding.UTF8);

        T[] arrayOfData = JsonSerialiserService.DeserialyseArray <T>(content);
        if (arrayOfData == null || arrayOfData.Length == 0)
        {
            Debug.Log("Wrong or empty JSON file !");
            return(false);
        }
        DoActionWithObtainedData(arrayOfData.ToList());

        return(true);
    }