//public void Init(string user1, string user2) //{ // m_sessionName = $"{user1.ToLower()}-{user2.ToLower()}"; // m_players = new string[] { user1, user2 }; // Record = GameSessionRecord.LoadOrCreate(user1, user2); // Record.SetGameRecord("@LastLogin", DateTime.UtcNow); // SyncRecord(); //} public void Init(GameSessionRecord record) { DontDestroyOnLoad(gameObject); m_sessionName = record.GetName(); bool result = record.TryGetGameRecord <string[]>("@Players", out m_players); Debug.Assert(result); Record = record; Record.SetGameRecord("@LastLogin", DateTime.UtcNow); SyncRecord(); }
public static GameSessionRecord CreateNew(string user1, string user2) { try { GameSessionRecord record = new GameSessionRecord(); var players = new string[] { user1, user2 }; record.SetGameRecord("@Players", players); var path = $"{Application.persistentDataPath}/{record.GetName()}.json"; using (var fs = File.Open(path, FileMode.Create)) using (var sw = new StreamWriter(fs)) { var jsonDeserializer = new JsonSerializer() { TypeNameHandling = TypeNameHandling.Auto }; jsonDeserializer.Serialize(sw, record); } return(record); } catch { return(null); } }