簡體   English   中英

將 txt 文件保存到 Oculus Go 內部存儲

[英]Saving a txt file to the Oculus Go Internal Storage

我正在使用 Unity 構建 Oculus Go 應用程序,但我不知道如何將 txt 文件保存到 Oculus Storage。 我已經閱讀了我在網上找到的關於它的所有內容,包括使用本網站在此處此處提出的解決方案。

我正在嘗試創建一個文本文件,用於記錄用戶選擇了切換組中的哪個按鈕。

當我為 PC 構建相同的東西時,代碼可以工作,但我在 Oculus Go 中找不到文件。 我編輯了 OVR android 清單,並根據幾個教程制作了一個非常簡單的腳本。

任何幫助將不勝感激,謝謝!

using UnityEngine;
using UnityEngine.UI;
using System.Linq;
using System.IO;
public class SubmitandWriteButtonOVR : MonoBehaviour

{
    //GameObject
    public ToggleGroup toggleGroup;

    public void onClick()
    {
        string selectedLabel = toggleGroup.ActiveToggles()
            .First().GetComponentsInChildren<Text>()
            .First(t => t.name == "Label").text;

        //Path of the file
        string path = Application.persistentDataPath + "/Answers.txt";

        //Create file if it doesn't exist
        if (!File.Exists(path))
        {
            File.WriteAllText(path, "Answers");
        }

        //Content of the file Get the label in activated toggles
        string content = "Selected Answers: \n" + System.DateTime.Now + "\n" + selectedLabel;

        //Add some text
        File.AppendAllText(path, content);

    }
}

有幾件事可能是這里的錯誤:

1)嘗試像這樣設置你的根路徑

rootPath = Application.persistentDataPath.Substring(0, Application.persistentDataPath.IndexOf("Android", StringComparison.Ordinal));

2) 即使您的根路徑設置正確,該文件也可能不會顯示。 嘗試將 Answers.txt 手動放入您的 GO,從您的應用程序內部將一些內容寫入 Answers.txt,重新啟動您的 Go 並在資源管理器中再次檢查它是否已寫入您的文件。 我讀到它與 Android 文件系統有關,沒有意識到這個文件已經被創建/更新,所以它沒有顯示。

3) 確保您通過 PlayerSettings 擁有對 externalSD 的寫入權限

這是我在 Android 上針對 StreamWriter 的解決方案:

private void WriteLogToFile()
    {
        Debug.Log("Starting to Write Logfile");
        string path = Path.Combine(rootPath, "Logs.txt");

        StreamWriter writer = new StreamWriter(path, true);
        writer.WriteLine("TEST");

        writer.Close();
        Debug.Log("Logging Done");
    }

嘗試一下,結合上述所有提示,是否可以幫助您實現目標並告訴我。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM