Написание .txt файла в android - PullRequest
       2

Написание .txt файла в android

0 голосов
/ 06 октября 2018

Мне нужна помощь с проблемой в нашей системе.Мы используем Unity и Visual Studio C # для создания мобильной VR-игры, используя только элементы управления взглядом (без контроллера).Нам нужно найти способ записать журналы отладки в текстовый файл и сохранить их на внутреннем хранилище Android.Заранее спасибо за помощь !!

Вот наш код ниже

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.IO;
using UnityEngine;

 public class VRPlace : MonoBehaviour 
 {
    ...

    void OnTriggerEnter(Collider other)
    {
        string path = "Assets/Resources/PlacesLog.txt";
        StreamWriter testing = new StreamWriter(path, true);

        if (other.gameObject.name == "Hospital")
        {
            GameObject otherObj = other.gameObject;
            Debug.Log("Triggered to: " + otherObj);
        }                
        testing.WriteLine(other.gameObject.name);                 
        testing.Close();          
    }  
}

1 Ответ

0 голосов
/ 06 октября 2018

Вот пример для сохранения файла .txt с StreamWriter.

class FileSaver
{
    static void Main()
    {
        // Create a StreamWriter instance
        StreamWriter writer = new 
        StreamWriter(Application.PersistentDataPath + "/droidlog.txt");

        // This using statement will ensure the writer will be closed when no longer used   
        using(writer)   
        {
            // Loop through the numbers from 1 to 20 and write them
            for (int i = 1; i <= 20; i++)
            {
                writer.WriteLine(i);
            }
        }
    }
}

это сохраняет цифры 1-20, вы захотите заполнить пробелы ... удачи!

...