Save and load on Mobile
Workflow 1:
Workflow 2:
var jsonString = Resources.Load<TextAsset>("Data");
File.WriteAllText(System.IO.Path.Combine(Application.persistentDataPath, "Data"), jsonString.text); public IEnumerator Load()
{
string _result = "";
using (UnityEngine.Networking.UnityWebRequest _download = UnityEngine.Networking.UnityWebRequest.Get(System.IO.Path.Combine(Application.streamingAssetsPath), "FileName.ext"))
{
yield return _download.SendWebRequest();
while (!_download.isDone)
{
if (_download.isNetworkError || _download.isHttpError)
{
break;
}
yield return null;
}
if (_download.isNetworkError || _download.isHttpError)
{
Debug.Log(_download.error);
}
else
{
_result = _download.downloadHandler.text;
// Write file to persistent data path
File.WriteAllText(Path.Combine(Application.persistentDataPath, "FileName.ext"), _result );
}
}
} Last updated