public void Activate() { cli = Statics.mainClient; cli.OnMessage += OnMessage; if (!File.Exists(Application.persistentDataPath + "/" + conversationID)) { File.Create(Application.persistentDataPath + "/" + conversationID); CA = new ChatArchive(); } else { var file = File.ReadAllBytes(Application.persistentDataPath + "/" + conversationID); string json = Encoding.ASCII.GetString(file); CA = JsonUtility.FromJson <ChatArchive>(json); } foreach (MessageArj marj in CA.messages) { GameObject go = GameObject.Instantiate(messageTemplate, messageParent); go.SetActive(true); messages.Add(go); MessageTemplate mt = go.GetComponent <MessageTemplate>(); mt.cm = this; mt.isSender = marj.SentByMe; mt.SendMessageXMPP(marj.body); } }
public void ReadFile() { if (File.Exists(Path.Combine(Application.persistentDataPath, jsonFileName))) { string json = File.ReadAllText(Path.Combine(Application.persistentDataPath, jsonFileName)); userArchive = JsonUtility.FromJson <ChatArchive>(json); } }