122 lines
3.1 KiB
C#
122 lines
3.1 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
public class MicroPhoneChoose_Contorl : MonoBehaviour
|
|
{
|
|
public Sprite chosen, notChosen;
|
|
public Color chosenColor;
|
|
|
|
public GameObject objBtnTest;
|
|
List<GameObject> objsMicros = new List<GameObject>();
|
|
|
|
public static MicroPhoneChoose_Contorl instance;
|
|
public string chosenMic;
|
|
|
|
private void Awake()
|
|
{
|
|
instance = this;
|
|
}
|
|
|
|
public void ListMicros()
|
|
{
|
|
Transform tr = transform.Find("AllignMicros");
|
|
|
|
foreach (GameObject item in objsMicros)
|
|
{
|
|
Destroy(item.gameObject);
|
|
}
|
|
|
|
if (Microphone.devices.Length > 0)
|
|
{
|
|
Text txtError = transform.Find("txtError").GetComponent<Text>();
|
|
txtError.color = new Color(.4f, .09f, .06f, 0);
|
|
|
|
objBtnTest.SetActive(true);
|
|
|
|
CheckFile();
|
|
|
|
int chosenMicint = System.Convert.ToInt32(chosenMic);
|
|
if (chosenMicint > Microphone.devices.Length)
|
|
{
|
|
chosenMicint = 0;
|
|
UpdateFile(chosenMicint.ToString());
|
|
}
|
|
MicroOption.chosenMic = chosenMicint;
|
|
|
|
string[] microphones = Microphone.devices;
|
|
|
|
//string[] microphones = new string[3] { "None", "Teste", "Teste2" };
|
|
|
|
bool chooseSome = false;
|
|
objsMicros.Clear();
|
|
GameObject objModel = Resources.Load<GameObject>("MicroChoose");
|
|
for (int i = 0; i < microphones.Length; i++)
|
|
{
|
|
GameObject objCreate = Instantiate(objModel, tr);
|
|
MicroOption microOption = objCreate.GetComponent<MicroOption>();
|
|
microOption.SetInfo(microphones[i], i);
|
|
|
|
objsMicros.Add(objCreate);
|
|
|
|
if (i == chosenMicint)
|
|
{
|
|
chooseSome = true;
|
|
objCreate.GetComponent<MicroOption>().SetThis(true, true);
|
|
}
|
|
}
|
|
|
|
if (!chooseSome)
|
|
{
|
|
tr.GetChild(0).GetComponent<MicroOption>().SetThis(true, true);
|
|
UpdateFile(microphones[0]);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
Text txtError = transform.Find("txtError").GetComponent<Text>();
|
|
txtError.color = new Color(.4f, .09f, .06f, 1);
|
|
|
|
objBtnTest.SetActive(false);
|
|
}
|
|
|
|
}
|
|
|
|
public void UpdateFile(string newMic)
|
|
{
|
|
chosenMic = newMic;
|
|
string path = Application.persistentDataPath + "/micro.txt";
|
|
|
|
if (File.Exists(path))
|
|
{
|
|
File.Delete(path);
|
|
}
|
|
|
|
File.WriteAllText(path, newMic);
|
|
|
|
StartCoroutine(RobotData.RegisterRobotMicro(newMic));
|
|
}
|
|
|
|
void CheckFile()
|
|
{
|
|
string path = Application.persistentDataPath + "/micro.txt";
|
|
|
|
if (File.Exists(path))
|
|
{
|
|
string content = File.ReadAllText(path);
|
|
|
|
chosenMic = content;
|
|
}
|
|
else
|
|
{
|
|
File.WriteAllText(path, "0");
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|