Esempio n. 1
0
    //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();
    }
 private void Start()
 {
     m_sessions = GameSessionRecord.EnumerateSavedSessions();
     //Debug.Log(m_sessions.Count);
     //Debug.Assert(m_sessions.Count > 0);
     if (m_sessions.Count == 0)
     {
         m_textSessionName.text  = "No Sessions found";
         m_textLastLogin.enabled = false;
         foreach (var btn in m_buttonsToDisableWhenNoSession)
         {
             btn.interactable = false;
         }
     }
     PrintSelectedSession();
 }
Esempio n. 3
0
    public void Confirm()
    {
        Regex validator = new Regex(@"^[a-zA-Z0-9][A-Za-z0-9_-]*$");

        if (!validator.IsMatch(m_user1.text) || !validator.IsMatch(m_user2.text))
        {
            m_errorText.text = "Error: Username may not be empty and may " +
                               "only contain letters, numbers and underscores.";
        }
        else if (SessionAlreadyExists())
        {
            m_errorText.text = "Error: Session already exists.";
        }
        else
        {
            m_sessionObject.Init(GameSessionRecord.CreateNew(m_user1.text, m_user2.text));
            Debug.Assert(m_sessionObject == GameSession.Instance);
            DontDestroyOnLoad(m_sessionObject.gameObject);
            SceneUtil.LoadScene("FallingDown");
        }
    }
Esempio n. 4
0
 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);
     }
 }