예제 #1
0
    public void UpdateLobbyPlayerList_Parsed(DataSnapshot ds)
    {
        Debug.Log("Received new snapshot to update player list with (" + ds.ToString() + ")");
        Debug.Log(ds.Value);
        if (ds.Value is long)
        {
            Debug.Log("Received new player count. Updating entire player list!");
            player_count = int.Parse(ds.Value + "");

            DatabaseReference _ref = FirebaseDatabase.DefaultInstance.RootReference.Child("Lobbies/lobby_" + is_in_lobby + "/players");
            _ref.GetValueAsync().ContinueWith(task =>
            {
                if (task.Result.Value is long)
                {
                    return;
                }

                UpdateLobbyPlayerList_Parsed(task.Result);
            });
            return;
        }
        else if (ds.Value is string)
        {
            return;
        }

        Debug.Log("Detected Player List change! (" + ds.ToString() + ")");

        Dictionary <string, object> d = ds.Value as Dictionary <string, object>;

        player_count = int.Parse(d["player_count"] + "");

        d.Remove("player_count");

        string newPlayerText = "";

        foreach (var e in d)
        {
            if (!playerList.Contains(e.Value + ""))
            {
                playerList.Add(e.Value + "");
            }
            newPlayerText += "" + e.Value + "\n";
        }

        Debug.Log(newPlayerText);

        //playerList = "Players:\n"+newPlayerText;
    }
예제 #2
0
    private IEnumerator RetrieveData(DatabaseReference reference)
    {
        // TODO: This will be called in the start() method and again once the refresh button is clicked
        S("Inside RetrieveData");

        if (assets.Count > 0)
        {
            S("RD - asset count > 0");
            var datasnap = LoadDataAsset(reference, assets[assets.Count - 1], 10);

            yield return(new WaitUntil(() => datasnap.IsCompleted));

            S("RD - ac>0 : Finised datasnapshot");

            DataSnapshot snapshot = datasnap.Result;

            S($"RD - ac>0 : got datasnapshot {snapshot.ToString()}");


            foreach (var datashot in snapshot.Children)
            {
                Asset asset = JsonUtility.FromJson <Asset>(datashot.GetRawJsonValue());

                Additemchild(asset);

                S($"RD - ac>0 : Adding assets {asset.name}");
            }
        }
        else
        {
            S("RD - asset count = 0");

            var datasnap = LoadData(reference, 0, 1);


            yield return(new WaitUntil(() => datasnap.IsCompleted));

            S("RD - ac=0 : Finised Datasnapshot process");

            DataSnapshot snapshot = datasnap.Result;

            S($"RD - ac=0 : Got datasnapshot {snapshot.ToString()}");


            foreach (var datashot in snapshot.Children)
            {
                Asset asset = JsonUtility.FromJson <Asset>(datashot.GetRawJsonValue());

                Additemchild(asset);

                S($"RD - ac=0 : Adding assets {asset.name}");
            }
        }



        S($"Done with Retrieve Data");
    }
예제 #3
0
    /// <summary>
    /// Read data from a certain path and send it to a callback function. The Menu Manager contains a 5 steps tutorial how the method structure for these works.
    /// </summary>
    /// <param name="path"></param>
    /// <param name="callbackFunction"></param>
    public void ReadData(string path, System.Action <string> callbackFunction)
    {
        Debug.Log("Reading data from '" + path + "'");

        DatabaseReference _ref = FirebaseDatabase.DefaultInstance.RootReference;

        _ref.Child(path).GetValueAsync().ContinueWith(task =>
        {
            DataSnapshot ds = task.Result;
            Debug.Log("Read call completed!");
            callbackFunction(ds.ToString());
        });
    }
예제 #4
0
    void Start()
    {
        //InitializeFirebaseSDK();
        Debug.Log("System time = " + System.DateTime.Now.Month + System.DateTime.Now.Day + System.DateTime.Now.Year);
        Debug.Log("System time = " + System.DateTime.Now.Hour + System.DateTime.Now.Minute + System.DateTime.Now.Second);
        FirebaseApp.DefaultInstance.SetEditorDatabaseUrl("https://ufogame-bcdca.firebaseio.com/");
        DatabaseReference reference = FirebaseDatabase.DefaultInstance.RootReference;
        FirebaseApp       app       = FirebaseApp.DefaultInstance;

        //Debug.Log("PlayerStats = " + PlayerStats.test);

        //FirebaseDatabase.DefaultInstance.GetReference("Level1").SetValueAsync("New time");



        currentLevel = SceneManager.GetActiveScene().buildIndex;
        PlayerPrefs.SetInt("CurrentLevel", currentLevel);
        Debug.Log("PlayerPrefs CurrentLevel = " + PlayerPrefs.GetInt("CurrentLevel"));
        rb2d           = GetComponent <Rigidbody2D>();
        spriteRenderer = GetComponent <SpriteRenderer>(); // we are accessing the SpriteRenderer that is attached to the Gameobject
        if (spriteRenderer.sprite == null)                // if the sprite on spriteRenderer is null then
        {
            spriteRenderer.sprite = sprite1;              // set the sprite to sprite1
        }
        count = 0;
        StartCoroutine(SetCountText());
        winText.SetText("");
        timerText.text  = "Timer: ";
        isLevelComplete = false;


        FirebaseDatabase.DefaultInstance.GetReference("Jim").GetValueAsync().ContinueWith(task =>
        {
            if (task.IsFaulted)
            {
                // Handle the error...
                Debug.Log("isFaulted");
            }
            else if (task.IsCompleted)
            {
                DataSnapshot snapshot = task.Result;
                // Do something with snapshot...
                Debug.Log("snapshot string = " + snapshot.ToString());
            }
        });
    }
예제 #5
0
    public void UpdateChat(System.Action <List <string> > callbackFunction)
    {
        if (is_in_lobby == "")
        {
            Debug.LogError("Can't update chat while not in lobby!");
            return;
        }

        string            path = "Lobbies/" + is_in_lobby + "/chat/messages";
        DatabaseReference _ref = FirebaseDatabase.DefaultInstance.RootReference.Child(path);

        _ref.GetValueAsync().ContinueWith((task) =>
        {
            DataSnapshot data = task.Result;

            Debug.Log(data.ToString());
        });
    }
예제 #6
0
        private async void RetrieveFromDB(string userId)
        {
            try
            {
                DataSnapshot dss = await _database.GetReference("users").Child(_firebaseUser.UserId).GetValueAsync();

                Log.Color(dss.ToString(), this);
                string json = dss.GetRawJsonValue();
                Log.Color(json, this);
                UserData = GetFromJson(json);
                SaveJSONLocal(json);
            }
            catch (AggregateException ex)
            {
                Log.ColorError("GetRawJsonValue encountered an error: " + ex.Message + " Data: " + ex.Data.Values, this);
                PopupManager.Instance.PrintMessage("Getting user from DB error: " + ex.Message);
            }
        }
예제 #7
0
    void Start()
    {
        //InitializeFirebaseSDK();

        FirebaseApp.DefaultInstance.SetEditorDatabaseUrl("https://ufogame-bcdca.firebaseio.com/");
        DatabaseReference reference = FirebaseDatabase.DefaultInstance.RootReference;
        FirebaseApp       app       = FirebaseApp.DefaultInstance;

        Debug.Log("reference.ToString() = " + reference.ToString());

        //Debug.Log("PlayerStats = " + PlayerStats.test);

        reference.Child("HighScores").SetRawJsonValueAsync("2"); //updates Firebase with new value
        reference.Child("Jim").SetValueAsync("Top Player");



        currentLevel = SceneManager.GetActiveScene().buildIndex;
        Debug.Log("Scene = " + currentLevel);

        rb2d  = GetComponent <Rigidbody2D>();
        count = 0;
        StartCoroutine(SetCountText());
        winText.text    = "";
        timerText.text  = "Timer: ";
        isLevelComplete = false;


        FirebaseDatabase.DefaultInstance.GetReference("Jim").GetValueAsync().ContinueWith(task =>
        {
            if (task.IsFaulted)
            {
                // Handle the error...
                Debug.Log("isFaulted");
            }
            else if (task.IsCompleted)
            {
                DataSnapshot snapshot = task.Result;
                // Do something with snapshot...
                Debug.Log("snapshot string = " + snapshot.ToString());
            }
        });
    }
예제 #8
0
 /// <summary>
 /// Get model list from DB
 /// </summary>
 /// <param name="location">DB path</param>
 /// <returns>model List</returns>
 async Task LoadDBData(DatabaseReference location)
 {
     var dataPair = new Dictionary <string, string>();
     await location.GetValueAsync().ContinueWith(task =>
     {
         if (task.IsFaulted)
         {
             // Handle the error...
             Debug.Log("couldn't load list from DB");
         }
         else if (task.IsCompleted)
         {
             DataSnapshot snapshot = task.Result;
             // Do something with snapshot...
             IEnumerator <DataSnapshot> list = snapshot.Children.GetEnumerator();
             while (list.MoveNext())
             {
                 DataSnapshot data = list.Current;
                 dataPair.Add(data.ToString(), data.Child("name").Value.ToString());
             }
         }
     });
 }
예제 #9
0
    public float[] SnapshotToTile(DataSnapshot ds)
    {
        Debug.Log("Parsing Tile Snapshot data (" + ds.ToString() + "; " + ds.Value.ToString() + ")");

        Dictionary <string, DataSnapshot> di = ds.Value as Dictionary <string, DataSnapshot>;

        Debug.Log(di.Count);

        foreach (var a in di)
        {
            Debug.Log(a.Key + "; " + a.Value);
        }

        string str_id     = ds.Child("id").Value.ToString();
        string str_pos_x  = ds.Child("pos_x").Value.ToString();
        string str_tile_x = ds.Child("tile_id").Value.ToString();

        int   id      = int.Parse(str_id);
        float pos_x   = float.Parse(str_pos_x);
        int   tile_id = int.Parse(str_tile_x);

        return(new float[] { id, pos_x, tile_id });
    }
예제 #10
0
 void ReadInfo()
 {
     Debug.Log("ReadInfo");
     FirebaseDatabase.DefaultInstance
     .GetReference("users").Child("E7xjHlAgCNh5Tkv9goASFBPQjXB3")
     .GetValueAsync().ContinueWith(task =>
     {
         if (task.IsFaulted)
         {
             // Handle the error...
         }
         else if (task.IsCompleted)
         {
             DataSnapshot snapshot = task.Result;
             // Do something with snapshot...
             Debug.Log("ok");
             Debug.Log(snapshot.ToString());
             string s  = snapshot.Child("score").Value.ToString();
             int score = 0;
             int.TryParse(s, out score);
             Debug.Log(score);
         }
     });
 }