2

Есть следуюший код для чтения файла:

public void readPurchase(){
    string  path;
    #if UNITY_EDITOR
    path = "/StreamingAssets/purchase.json";
    #elif UNITY_ANDROID
    path = "jar:file://" + Application.dataPath + "!/assets/purchase.json";
    #endif

    StartCoroutine (jsonReadCorout(path));
    string json = File.ReadAllText(Application.dataPath + path);
    itemsContent = JsonUtility.FromJson<Main> (json); 
    bundleForPing = itemsContent.bundleID;
}
IEnumerator jsonReadCorout(string path){
    WWW www = new WWW(path);
    yield return www;
    {
        Debug.LogError ("Can't read");
    }
}

файл находится в папке StreamingAssets, у меня не правильный путь к нему но не могу понять где ошибка.

1 ответ 1

0

Всё просто оказалось...

private IEnumerator ReloadFile(){
    WWW data = new WWW(Application.streamingAssetsPath+"/"+"purchase.json");
    yield return data;
        itemsContent = JsonUtility.FromJson<Main> (data.text); 
        bundleForPing = itemsContent.bundleID;
}

Файл purchase.json нужно ставить в папку StreamingAssets.

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.