using System; using System.Collections; using System.Collections.Generic; using System.IO; using UnityEditor; using UnityEngine; using UnityEngine.UI; public class ReadingFile : MonoBehaviour { public enum UserType { Admin = 1, Teacher = 2, Demo = 3, MyRobotStudent = 4, ZoeStudent = 5, } public static bool canGo = false; public bool developing, iplocal; public UserType userType = UserType.Demo; public static string idmatricula, senha, iploc, banco, idUnit, route; string path; private void Awake() { } private void Start() { Debug.Log(Application.persistentDataPath); if (Application.platform == RuntimePlatform.Android) { path = Application.persistentDataPath + "/"; } else if (Application.platform == RuntimePlatform.WindowsEditor) { path = Application.persistentDataPath.Replace(Application.productName, "") + "RobotIngles/"; } string thisPath = path + "login.txt"; try { if (File.Exists(thisPath)) { StreamReader reader = new StreamReader(thisPath); string text = reader.ReadToEnd(); string[] textSplit = text.Split(';'); banco = textSplit[0]; idmatricula = textSplit[1]; senha = textSplit[2]; iploc = textSplit[3]; idUnit = textSplit[4]; int.TryParse(textSplit[5], out int _userType); userType = (UserType)_userType; iploc = "18.228.91.135"; if (iplocal) { route = "http://localhost:1337"; } else { route = "http://" + iploc + ":1337"; } reader.Close(); } } catch (Exception ex) { Debug.Log($"Erro ao ler arquivo de login: {ex.Message}"); } finally { canGo = true; } } #region Micro public int CheckMicro() { int value = 0; string thisPath = path + "micro.txt"; if (File.Exists(thisPath)) { string readFile = File.ReadAllText(thisPath); value = System.Convert.ToInt32(readFile); if (value >= Microphone.devices.Length) { value = 0; File.Delete(thisPath); File.WriteAllText(thisPath, "0"); } } else { File.WriteAllText(thisPath, "0"); } return value; } public void UpdateMicro(int newMic) { string thisPath = path + "micro.txt"; if (File.Exists(thisPath)) { File.Delete(thisPath); } File.WriteAllText(thisPath, newMic.ToString()); } #endregion public static Texture2D LoadPNG(string filePath) { Texture2D tex = null; byte[] fileData; if (File.Exists(filePath)) { fileData = File.ReadAllBytes(filePath); tex = new Texture2D(2, 2); tex.LoadImage(fileData); } return tex; } }