private void ReadEverServer() { recordServers.Clear(); string file = ""; #if UNITY_EDITOR file = Application.dataPath + "/../server.txt"; #else file = Application.persistentDataPath + "/server.txt"; #endif if (File.Exists(file)) { string content = File.ReadAllText(file); string[] items = content.Split('#'); for (int i = 0; i < items.Length; i++) { string[] item = items[i].Split(','); if (item.Length == 3) { ServerRecord server = new ServerRecord(); server.username = item[0]; server.ip = item[1]; int.TryParse(item[2], out server.port); recordServers.Add(server); } } } }
private void AddEverServer() { if (string.IsNullOrEmpty(Username)) { return; } bool has = false; bool isChange = false; for (int i = 0; i < recordServers.Count; i++) { if (recordServers[i].username.Equals(Username) && recordServers[i].ip.Equals(ServerIP) && recordServers[i].port == ServerPort) { has = true; if (0 != i) { isChange = true; ServerRecord tmp = recordServers[i]; recordServers.RemoveAt(i); recordServers.Insert(0, tmp); } break; } } if (!has) { isChange = true; ServerRecord server = new ServerRecord(); server.username = Username; server.ip = ServerIP; server.port = ServerPort; recordServers.Insert(0, server); } if (isChange) { SaveEverServer(); } }