【发布时间】:2019-08-16 07:54:35
【问题描述】:
我把 json 文件放在 Application.persistentDataPath 中,然后它就可以在 PC 上加载和工作了。
但是在Android上不行,卡了好久。
我找到了很多方法,但没有人能解决它。
请帮帮我,谢谢!
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.IO;
public class QuizCon : MonoBehaviour
{
public RoundData[] allRoundData;
private string gameDataFileName = "quiz.json";
private void Start()
{
DontDestroyOnLoad(gameObject);
LoadGameData();
}
public RoundData GetCurrectRoundData()
{
return allRoundData[0];
}
private void LoadGameData()
{
string filePath = Path.Combine(Application.persistentDataPath, gameDataFileName);
if(File.Exists(filePath))
{
string dataJson = File.ReadAllText(filePath);
GameData loadedData = JsonUtility.FromJson<GameData>(dataJson);
allRoundData = loadedData.allRoundData;
}
else
{
Debug.LogError("Cannot load game data!");
}
}
【问题讨论】: