Когда я создаю файл, я сразу же пытаюсь обновить свои коллекции, но затем получите исключение NullReferenceException.
Вот весь код, связанный с моей проблемой.
Код: Выделить всё
public void AddCollection(string collectionName)
{
string tempPath = new string(path + "/" + collectionName + ".txt");
if (!File.Exists(tempPath))
{
File.WriteAllText(tempPath, GetBaseFileCollection(collectionName));
}
algManager.UpdateCollections();
UpdateDropDown();
}
Код: Выделить всё
public string GetBaseFileCollection(string collectionName)
{
string temp = "{\r\n\t\"collectionName\" : \"" + collectionName + "\"\r\n}";
return temp;
}
Код: Выделить всё
//algManager
public void UpdateCollections()
{
algorithms.Clear();
info = new DirectoryInfo(path);
var fileInfo = info.GetFiles("*.txt");
foreach (FileInfo file in fileInfo)
{
var textFile = Resources.Load(file.Name.Replace(".txt", ""));
algorithms.Add(JsonConvert.DeserializeObject(textFile.text));
//the error occurs on this line ^
}
Код: Выделить всё
public class AlgorithmCollection
{
public string collectionName;
[SerializeField]
public List algorithms;
}
[System.Serializable]
public class AlgorithmBase
{
public string algorithmName;
public List algorithm;
public int cubeSize;
[SerializeField]
public List tilesColor;
}
Подробнее здесь: https://stackoverflow.com/questions/788 ... cces-it-nu
Мобильная версия