Как работает система: Есть FileChecker, который проверяет, создан ли файл. В противном случае мы получаем исключение, обрабатывая который мы создаем файл и записываем основные данные:
Синтаксис:
Используется csharp
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.IO;
using UnityEngine.UI;
public class FileChecker : MonoBehaviour
{
public static string path = Application.dataPath + "/";
public static string nameFile = "CurrentMapAndLevel.txt";
public static void IsFileCreated()
{
try
{
StreamReader sr = new StreamReader(path + "/" + nameFile);
}
catch
{
File.Create(path + "/" + nameFile);
StreamWriter writer = new StreamWriter(path + "/" + nameFile);
writer.Write("1-1");
writer.Close();
}
}
}
using System.Collections.Generic;
using UnityEngine;
using System.IO;
using UnityEngine.UI;
public class FileChecker : MonoBehaviour
{
public static string path = Application.dataPath + "/";
public static string nameFile = "CurrentMapAndLevel.txt";
public static void IsFileCreated()
{
try
{
StreamReader sr = new StreamReader(path + "/" + nameFile);
}
catch
{
File.Create(path + "/" + nameFile);
StreamWriter writer = new StreamWriter(path + "/" + nameFile);
writer.Write("1-1");
writer.Close();
}
}
}
С помощью FileReader я пытаюсь получить данные:
Синтаксис:
Используется csharp
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.IO;
using System;
public class FileReader : MonoBehaviour
{
public static string path = Application.dataPath + "/StreamingAssets";
public static string nameFile = "CurrentMapAndLevel.txt";
public static string LevelInfo = "";
public static (byte, byte) GetLevel()
{
StreamReader sr = new StreamReader(path + "/" + nameFile);
LevelInfo = sr.ReadLine();
sr.Close();
char[] array = LevelInfo.ToCharArray();
return (Convert.ToByte(array[0].ToString()), Convert.ToByte(array[2].ToString())); //returns: current map, current level
}
}
using System.Collections.Generic;
using UnityEngine;
using System.IO;
using System;
public class FileReader : MonoBehaviour
{
public static string path = Application.dataPath + "/StreamingAssets";
public static string nameFile = "CurrentMapAndLevel.txt";
public static string LevelInfo = "";
public static (byte, byte) GetLevel()
{
StreamReader sr = new StreamReader(path + "/" + nameFile);
LevelInfo = sr.ReadLine();
sr.Close();
char[] array = LevelInfo.ToCharArray();
return (Convert.ToByte(array[0].ToString()), Convert.ToByte(array[2].ToString())); //returns: current map, current level
}
}
Буду очень благодарен, если поможете
P.S. Если создать файл вручную (вписав значение) все работает...