I need to use it as textasset…I need to find an way because I am using a static class and cant simply declare [SerializeField]…
So I tryed it but isnt working too:
var jsonTextFile = Resources.Load(“Data_I18N/LocalizationData”);
UnityEngine.Debug.Log(jsonTextFile.text);
This file is fixed, I dont need to change it,only read. But I have another file where I am saving data:
string filePath = Application.persistentDataPath + “SettingData.json”;
Thas isnt working too.
string path = Path.Combine(Application.streamingAssetsPath, "Data_I18N", "LocalizationData.json");
if (Application.platform == RuntimePlatform.Android)
{
UnityWebRequest www = UnityWebRequest.Get(path);
www.SendWebRequest();
while (!www.isDone) ;
string json = www.downloadHandler.text;
val.text = json;
}
else
{
if (File.Exists(path))
{
using (StreamReader reader = new StreamReader(path))
{
string json = reader.ReadToEnd();
val.text = json;
}
}
else
{
val.text = "file not found";
}
}
I create a folder called StreamingAssets and inside it I put my json.
Is possible that the file cant exist there in mobile? Like be deleted? Because how I can protec the code is doesnt exist?
If I use [SerializeField] TextAsset t; to get my json and parse it, it will be more safer?
My fear is the user delete data like cleaning cache or something and stop all the app.