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 objsMicros = new List(); 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(); 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("MicroChoose"); for (int i = 0; i < microphones.Length; i++) { GameObject objCreate = Instantiate(objModel, tr); MicroOption microOption = objCreate.GetComponent(); microOption.SetInfo(microphones[i], i); objsMicros.Add(objCreate); if (i == chosenMicint) { chooseSome = true; objCreate.GetComponent().SetThis(true, true); } } if (!chooseSome) { tr.GetChild(0).GetComponent().SetThis(true, true); UpdateFile(microphones[0]); } } else { Text txtError = transform.Find("txtError").GetComponent(); 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"); } } }