using System.Collections;
using UnityEngine;
using System.IO;
using System.Text;
using UnityEngine.UI;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System;
//#if WINDOWS_UWP
//using Windows.Storage;
//using Windows.System;
//using System.Threading.Tasks;
//using Windows.Storage.Streams;
//#endif
public class StartButton : MonoBehaviour
{
public Text secondsdisplay;
public float displaytime = 5;
public float nseconds = 1;
public float timer = 0;
public float percent;
public int counter = 0;
public StreamWriter sw1;
public Text displaynseconds;
public float startTime, stopTime;
public GameObject myboard;
public string timeData;
public string ClickRespTime;
//private static bool firstSave = true;
//private string saveInformation = "";
//private static string fileName = "/Responsetime.txt";
//#if WINDOWS_UWP
// Windows.Storage.ApplicationDataContainer localSettings = Windows.Storage.ApplicationData.Current.LocalSettings;
// Windows.Storage.StorageFolder localFolder = Windows.Storage.ApplicationData.Current.LocalFolder;
//#endif
Vector3[] positionArray = new[] { new Vector3(0.6f, 0.009f, 0.5f), new Vector3(0.6f, 0.239f, 0.5f), new Vector3(1.027f, 0.239f, 0.5f), new Vector3(0.618f, 0.239f, 0.5f), new Vector3(0.6f, 0.009f, 0.5f), new Vector3(0.6f, 0.239f, 0.5f), new Vector3(1.027f, 0.239f, 0.5f), new Vector3(0.618f, 0.239f, 0.5f), new Vector3(0.6f, 0.009f, 0.5f), new Vector3(0.6f, 0.239f, 0.5f), new Vector3(0.6f, 0.009f, 0.5f), new Vector3(0.6f, 0.239f, 0.5f), new Vector3(1.027f, 0.239f, 0.5f), new Vector3(0.618f, 0.239f, 0.5f), new Vector3(0.6f, 0.009f, 0.5f), new Vector3(0.6f, 0.239f, 0.5f), new Vector3(1.027f, 0.239f, 0.5f), new Vector3(0.618f, 0.239f, 0.5f), new Vector3(0.6f, 0.009f, 0.5f), new Vector3(0.6f, 0.239f, 0.5f), new Vector3(0.6f, 0.239f, 0.5f), new Vector3(1.027f, 0.239f, 0.5f), new Vector3(0.618f, 0.239f, 0.5f), new Vector3(0.6f, 0.009f, 0.5f), new Vector3(0.6f, 0.239f, 0.5f) };
void Start()
{
// string path = Application.persistentDataPath + "/Responsetime.txt";
//StreamWriter sw1 = new StreamWriter(path);
// Debug.Log("file created" + File.Exists(path).ToString());
// if (!File.Exists(path))
// {
// sw1 = File.CreateText(path);
// }
//StringBuilder sb = new StringBuilder();
timer = displaytime;
}
IEnumerator fivesecondtime()
{
//Debug.Log("Started Coroutine at timestamp : " + Time.time);
yield return new WaitForSeconds(10.0f);
//Debug.Log("Finished Coroutine at timestamp : " + Time.time);
XButtonPressed();
}
public void hideboard()
{
myboard.SetActive(false);
}
public void textdisplay()
{
secondsdisplay.text = ClickRespTime.ToString();
}
void Update()
{
//Debug.Log("upadte checking inside");
if (counter == 20)
{
// sw1.WriteLine(timeData);
//sw.Close();
//sw.Flush();
StopCoroutine(fivesecondtime());
#if UNITY_EDITOR
UnityEditor.EditorApplication.isPlaying = false;
#else
Application.Quit();
#endif
}
}
public void starButtonPressed()
{
startTime = Time.time;
StartCoroutine(fivesecondtime());
}
//#if WINDOWS_UWP
// async void WriteData()
// {
// if (firstSave){
// StorageFile sampleFile = await localFolder.CreateFileAsync(fileName, CreationCollisionOption.ReplaceExisting);
// await FileIO.AppendTextAsync(sampleFile, saveInformation + "\r\n");
// firstSave = false;
// }
// else{
// StorageFile sampleFile = await localFolder.CreateFileAsync(fileName, CreationCollisionOption.OpenIfExists);
// await FileIO.AppendTextAsync(sampleFile, saveInformation + "\r\n");
// }
// }
//#endif
public void XButtonPressed()
{
// if (counter == 10)
// counter = 0;
// Debug.Log("time of the update \n" + timeData);
StopCoroutine(fivesecondtime());
stopTime = Time.time;
//saveInformation = counter.ToString() + " " + (stopTime - startTime).ToString();
//#if WINDOWS_UWP
// WriteData();
//#endif
transform.position = positionArray[counter];
// Debug.Log("counter before : " + counter);
counter++;
Debug.Log("new counter : " + counter.ToString());
//timeData = "counter after," + counter.ToString();
//timeData = timeData + "Time elapsed = " + (stopTime - startTime) + "\n";
//ClickRespTime = timeData;
// Debug.Log("Time elapsed = " + (stopTime - startTime));
Debug.Log("time of the update \n" + timeData);
startTime = Time.time;
// write lines
// sw1.WriteLine(timeData);
//#if WINDOWS_UWP
// WriteData();
//#endif
StartCoroutine(fivesecondtime());
}
}
What are the standard procedures for writing the data and saving files into the hololens device? I used two different methods but its not working. Moreover, I tried 2 3 different recommended methods on StackOverflow but it's not working in my case. When I run the application on HL1 only file created but not writing my data into it.
I want to know is there any other way to store data into the files for unity2018 with MRTK 2.3. On different forums i checked there is no standard information specifically for HL1.
FileIO.AppendTextAsync
should work fine on HoloLens, but I find that there is a mistake in your code: the variable "fileName" got an invalid string because it can't contain the character "/".
Actually, when using UWP StorageFile API, there is no need to manually combine the path string, so we don't need to take care of the path component separator. Check out this doc: Work with files
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.