Esempio n. 1
0
    public void OnDeleteButtonClicked()
    {
        if (serviceUser == null)
        {
            FacebookAuthText.text = "Please authenticate before using futher scenarios!";
            return;
        }

        TodoItem item1 = new TodoItem {
            Complete = false, Text = "Todo Updated", Id = this.id
        };

        AzureMobileServices.Delete <TodoItem>(item1, (response) =>
        {
            if (response.Status == CallbackStatus.Failure)
            {
                Debug.LogError("Deleting record failed.");
                Debug.LogError(response.Exception.ToString());
                return;
            }

            // print something
            FacebookAuthText.text = "Successfully deleted item";
            Debug.Log("Successfully deleted item");
        });
    }
Esempio n. 2
0
    public void OnGUI()
    {
        GUILayout.BeginVertical();
        GUILayout.BeginHorizontal();

        GUILayout.BeginVertical(GUILayout.Width(200));
        GUILayout.Label("Azure End Point");
        AzureEndPoint = GUILayout.TextField(AzureEndPoint, GUILayout.Width(200));
        GUILayout.Label("Application Key");
        ApplicationKey = GUILayout.TextField(ApplicationKey, GUILayout.Width(200));
        GUILayout.Label("Facebook Access Token");
        FacebookAccessToken = GUILayout.TextField(FacebookAccessToken, GUILayout.Width(200));
        if (GUILayout.Button("Log In"))
        {
            Login();
        }
        GUILayout.EndVertical();

        GUI.enabled = (azure != null && azure.User != null);

        GUILayout.BeginVertical(GUILayout.Width(200));
        GUILayout.TextField("" + _todo.Id);
        _todo.Text = GUILayout.TextField(_todo.Text);
        if (GUILayout.Button("Add"))
        {
            // Note: You don't need to do the following,
            // it's done in the insert method.
            // _todo.Id = null;
            azure.Insert <ToDoItem>(_todo);
        }
        GUILayout.EndVertical();
        GUILayout.BeginVertical(GUILayout.Width(200));

        if (GUILayout.Button("Query/Where"))
        {
            _toDoItems.Clear();
            azure.Where <ToDoItem>(p => p.Text == "Some Text", ReadHandler);
        }
        if (GUILayout.Button("List All"))
        {
            GetAllItems();
        }

        GUILayout.Label("Item count: " + _toDoItems.Count);

        scrollPosition = GUILayout.BeginScrollView(scrollPosition, false, true, GUILayout.Height(300));

        GUILayout.BeginVertical();
        foreach (var item in _toDoItems)
        {
            GUILayout.BeginHorizontal();
            if (GUILayout.Button(">", GUILayout.Width(20), GUILayout.Height(20)))
            {
                _selectedItem = item;
            }
            GUILayout.Label(item.Text);
            GUILayout.EndHorizontal();
        }
        GUILayout.EndVertical();

        GUILayout.EndScrollView();
        GUILayout.EndVertical();

        GUILayout.BeginVertical(GUILayout.Width(200));

        var was = GUI.enabled;

        GUI.enabled = _selectedItem.Id != null;

        GUILayout.Label("ID:" + _selectedItem.Id);
        _selectedItem.Text     = GUILayout.TextField(_selectedItem.Text);
        _selectedItem.Complete = GUILayout.Toggle(_selectedItem.Complete, "Complete");

        if (GUILayout.Button("Update"))
        {
            azure.Update <ToDoItem>(_selectedItem);
        }
        if (GUILayout.Button("Delete"))
        {
            azure.Delete <ToDoItem>(_selectedItem);
        }

        GUI.enabled = was;

        GUILayout.EndVertical();

        GUILayout.EndHorizontal();

        GUILayout.BeginHorizontal();

        GUILayout.EndHorizontal();
        GUILayout.EndVertical();

        GUI.enabled = true;
    }
    public void OnGUI()
    {
        GUILayout.BeginVertical();
        GUILayout.BeginHorizontal();

        // Column 1
        GUILayout.BeginVertical(GUILayout.Width(colWidth));
        GUILayout.Label("Azure End Point");
        AzureEndPoint = GUILayout.TextField(AzureEndPoint, GUILayout.Width(colWidth));
        GUILayout.Label("Application Key");
        ApplicationKey = GUILayout.TextField(ApplicationKey, GUILayout.Width(colWidth));
        GUILayout.EndVertical();

        // hide rest of GUI if no connection available
        GUI.enabled = (azure != null);

        // Column 2
        GUILayout.BeginVertical(GUILayout.Width(colWidth));
        GUILayout.Label("Username");
        _leaderboard.Username = GUILayout.TextField(_leaderboard.Username);
        GUILayout.Label("Score");
        _leaderboard.Score = Convert.ToInt32(GUILayout.TextField("" + _leaderboard.Score));
        if (GUILayout.Button("Add Score", GUILayout.MinWidth(width), GUILayout.Height(height)))
        {
            // Note: You don't need to do the following, it's done in the insert method.
            // _leaderboard.Id = null;

            if (_leaderboard.Score > 0)
            {
                // only insert score if greater than 0
                azure.Insert <Leaderboard>(_leaderboard);
            }
            else
            {
                Debug.Log("Score must be > 0 to insert");
            }
        }
        GUILayout.Label("Id: " + _leaderboard.Id);         // unique item Id (returned once submitted succesfully)
        GUILayout.EndVertical();

        // Column 3
        GUILayout.BeginVertical(GUILayout.Width(colWidth));
        if (GUILayout.Button("Query User Scores", GUILayout.MinWidth(width), GUILayout.Height(height)))
        {
            _leaderboardItems.Clear();
            // get a user's scores
            azure.Where <Leaderboard>(p => p.Username == _leaderboard.Username, ReadHandler);
        }
        if (GUILayout.Button("List All Scores", GUILayout.MinWidth(width), GUILayout.Height(height)))
        {
            GetAllItems();
        }
        if (GUILayout.Button("List Scores 500+", GUILayout.MinWidth(width), GUILayout.Height(height)))
        {
            _leaderboardItems.Clear();
            // get high scores
            azure.Where <Leaderboard>(p => p.Score >= 500, ReadHandler);
        }
        GUILayout.Label("Item count: " + _leaderboardItems.Count);
        scrollPosition = GUILayout.BeginScrollView(scrollPosition, false, true, GUILayout.Height(300));

        // Column 4
        GUILayout.BeginVertical();
        foreach (var item in _leaderboardItems)
        {
            GUILayout.BeginHorizontal();
            if (GUILayout.Button(">", GUILayout.Width(width), GUILayout.Height(height)))
            {
                _selectedItem = item;
            }
            GUILayout.Label(item.Username);
            GUILayout.Label(Convert.ToString(item.Score));
            GUILayout.EndHorizontal();
        }
        GUILayout.EndVertical();

        GUILayout.EndScrollView();
        GUILayout.EndVertical();

        GUILayout.BeginVertical(GUILayout.Width(colWidth));

        var was = GUI.enabled;

        GUI.enabled = _selectedItem.Id != null;

        GUILayout.Label("Id: " + _selectedItem.Id);
        if (_selectedItem.Score > 0)
        {
            _selectedItem.Score = Convert.ToInt32(GUILayout.TextField("" + _selectedItem.Score));
        }
        _selectedItem.Username = GUILayout.TextField(_selectedItem.Username);

        if (GUILayout.Button("Update", GUILayout.MinWidth(width), GUILayout.Height(height)))
        {
            azure.Update <Leaderboard>(_selectedItem);
        }
        if (GUILayout.Button("Delete", GUILayout.MinWidth(width), GUILayout.Height(height)))
        {
            azure.Delete <Leaderboard>(_selectedItem);
        }

        GUI.enabled = was;

        GUILayout.EndVertical();
        GUILayout.EndHorizontal();

        GUILayout.BeginHorizontal();
        GUILayout.EndHorizontal();

        GUILayout.EndVertical();

        GUI.enabled = true;
    }