예제 #1
0
    public void CreateGame()
    {
        Debug.Log("tryin to create game");
        if (displayName.text == "" || userInfo.activeGames.Count >= 3)
        {
            return;
        }


        Debug.Log("Trying to create Game Info for new game");
        var newGameInfo = new GameInfo();

        newGameInfo.displayName = displayName.text;
        var dicePlayerInfo = new DicePlayerInfo();

        dicePlayerInfo.userID      = ActiveUser.Instance.userID;
        dicePlayerInfo.displayName = displayName.text;
        dicePlayerInfo.spriteIndex = userInfo.sprite;

        newGameInfo.dicePlayers = new List <DicePlayerInfo>();
        newGameInfo.dicePlayers.Add(dicePlayerInfo);

        //Create seed for first dice rolls
        int seed1 = Random.Range(0, 100);
        int seed2 = Random.Range(0, 100);

        newGameInfo.dice1 = seed1;
        newGameInfo.dice2 = seed2;

        string key  = db.RootReference.Child("games/").Push().Key;
        string path = "games/" + key;

        newGameInfo.gameID = key;
        string jsondata = JsonUtility.ToJson(newGameInfo);

        StartCoroutine(FirebaseManager.Instance.SaveData(path, jsondata));

        GameCreated(key);
    }
예제 #2
0
    public void JoinGame(GameInfo gameInfo)
    {
        Debug.Log("Trying to join game");
        userInfo.activeGames.Add(gameInfo.gameID);

        string jsondata = JsonUtility.ToJson(userInfo);

        StartCoroutine(FirebaseManager.Instance.SaveData("users/" + userID, jsondata));

        var dicePlayerInfo = new DicePlayerInfo();

        dicePlayerInfo.displayName = displayName.text;
        dicePlayerInfo.userID      = ActiveUser.Instance.userID;
        dicePlayerInfo.spriteIndex = userInfo.sprite;
        gameInfo.dicePlayers.Add(dicePlayerInfo);

        gameInfo.displayName = gameInfo.dicePlayers[0].displayName + " vs " + dicePlayerInfo.displayName;

        jsondata = JsonUtility.ToJson(gameInfo);

        StartCoroutine(FirebaseManager.Instance.SaveData("games/" + gameInfo.gameID, jsondata));
        UpdateGameList();
        ListGames();
    }