107 lines
2.6 KiB
C#
107 lines
2.6 KiB
C#
using System.Collections;
|
|
using UnityEngine;
|
|
using System.IO;
|
|
using UnityEngine.UI;
|
|
using System;
|
|
|
|
public class WriteFile : MonoBehaviour
|
|
{
|
|
private string getFile(string file)
|
|
{
|
|
return Path.Combine(Application.persistentDataPath, file);
|
|
}
|
|
|
|
#region Micro
|
|
public int CheckMicro()
|
|
{
|
|
int value = 0;
|
|
|
|
string path = getFile("micro.txt");
|
|
|
|
if (File.Exists(path))
|
|
{
|
|
string readFile = File.ReadAllText(path);
|
|
value = System.Convert.ToInt32(readFile);
|
|
|
|
if (value >= Microphone.devices.Length)
|
|
{
|
|
value = 0;
|
|
File.Delete(path);
|
|
File.WriteAllText(path, "0");
|
|
}
|
|
}
|
|
else
|
|
{
|
|
File.WriteAllText(path, "0");
|
|
}
|
|
|
|
return value;
|
|
}
|
|
#endregion
|
|
|
|
#region text
|
|
|
|
public bool checkFile()
|
|
{
|
|
if (!File.Exists(getFile("login.txt")))
|
|
{
|
|
return false;
|
|
}
|
|
else
|
|
{
|
|
return true;
|
|
}
|
|
}
|
|
|
|
public void Error(string error)
|
|
{
|
|
Text txtError = GameObject.Find("txtError").GetComponent<Text>();
|
|
txtError.text = error;
|
|
}
|
|
|
|
public void DeleteFile()
|
|
{
|
|
File.Delete(getFile("login.txt"));
|
|
}
|
|
|
|
public void CreateFile(string usuario, string senha, string reference, string iplocal, string idunit, string userType)
|
|
{
|
|
string content = reference + ".dbo.;" + usuario + ";" + senha + ";" + iplocal + ";" + idunit + ";" + userType;
|
|
File.WriteAllText(getFile("login.txt"), content);
|
|
Debug.Log(content);
|
|
|
|
StartCoroutine(RobotData.RegisterRobotLogin(Convert.ToInt32(usuario), Convert.ToInt32(idunit), Convert.ToInt32(userType), senha, reference + ".dbo.", CheckMicro()));
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
#region Audio
|
|
public void CreateAudio(AudioClip clip){
|
|
Debug.Log(clip.length);
|
|
//Text txtError = GameObject.Find("txtError").GetComponent<Text>();
|
|
SavWav.Save("tempAudio", clip);
|
|
}
|
|
|
|
public AudioClip audioLoaded;
|
|
public void GetAudioClip() {
|
|
StartCoroutine(loadAudio());
|
|
}
|
|
|
|
public IEnumerator loadAudio() {
|
|
WWW request = getAudioFile("file://" + Application.persistentDataPath + "/tempAudio.wav");
|
|
yield return request;
|
|
|
|
audioLoaded = request.GetAudioClip();
|
|
Debug.Log(audioLoaded.length);
|
|
audioLoaded.name = "tempAudio.wav";
|
|
}
|
|
|
|
public WWW getAudioFile(string path) {
|
|
string audiotoLoad = path;
|
|
WWW request = new WWW(audiotoLoad);
|
|
return request;
|
|
}
|
|
#endregion
|
|
}
|