Пример #1
0
    private void QueryIdFacebookCallback(AzureResponse <List <pandafruitfarm> > response)
    {
        long score = Convert.ToInt64(ObscuredPrefs.GetString("score"));
        var  list  = response.ResponseData;

        if (list.Count > 0)
        {
            foreach (var item in list)
            {
                _selectedItem = item;
                if (item.Score < score)
                {
                    _selectedItem.Score      = score;
                    _selectedItem.IdFacebook = GetDataFacebook.IDFacebook;
                    _selectedItem.Level      = "Level" + ObscuredPrefs.GetInt("level");
                    _selectedItem.Username   = GetDataFacebook.UserFacebook;
                    azure.Update <pandafruitfarm>(_selectedItem);
                }
            }
        }
        else
        {
            _selectedItem.Score      = score;
            _selectedItem.IdFacebook = GetDataFacebook.IDFacebook;
            _selectedItem.Level      = "Level" + ObscuredPrefs.GetInt("level");
            _selectedItem.Username   = GetDataFacebook.UserFacebook;
            azure.Insert <pandafruitfarm>(_selectedItem);
        }
    }
Пример #2
0
    public void OnInsertButtonClicked()
    {
        if (serviceUser == null)
        {
            FacebookAuthText.text = "Please authenticate before using futher scenarios!";
            return;
        }

        TodoItem item1 = new TodoItem {
            Complete = false, Text = "Just Inserted text!!"
        };

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

            // print something
            FacebookAuthText.text = "Successfully inserted item";
            Debug.Log("Successfully inserted item");
            id = item1.Id;
        });
    }
        private void Start()
        {
            // Create the delays so they only have to be made once.
            m_StartWait = new WaitForSeconds(m_StartDelay);
            m_EndWait   = new WaitForSeconds(m_EndDelay);

            SpawnAllTanks();
            SetCameraTargets();

            // Once the tanks have been created and the camera is using them as targets, start the game.
            StartCoroutine(GameLoop());

            //BUILD16 Connect to Azure
            Debug.Log("Logging into Azure...");
            AzureMobileServices.Connect("https://build16gameazurelab3.azurewebsites.net");

            //BUILD16 Save initial game score in Azure
            userId = System.Guid.NewGuid().ToString();
            GameScore score = new GameScore {
                user = userId, score = 0
            };

            AzureMobileServices.Insert <GameScore>(score, (response) =>
            {
                if (response.Status == CallbackStatus.Failure)
                {
                    Debug.LogError("Inserting record failed.");
                    Debug.LogError(response.Exception.ToString());
                    return;
                }

                // print something
                Debug.Log("Successfully inserted item " + score.id);
            });
        }
        //BUILD16 - method to save score
        private void SaveScoreInAzure()
        {
            if (m_RoundWinner != null)
            {
                GameScore score = new GameScore {
                    user = userId, tank = m_RoundWinner.m_PlayerNumber, score = m_RoundWinner.m_Wins
                };
                AzureMobileServices.Insert <GameScore>(score, (response) =>
                {
                    if (response.Status == CallbackStatus.Failure)
                    {
                        Debug.LogError("Inserting record failed.");
                        Debug.LogError(response.Exception.ToString());
                        return;
                    }

                    // print something
                    Debug.Log("Successfully inserted item " + score.id);
                });
            }
        }
Пример #5
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;
    }
Пример #7
0
 public void InsertScore(int score)
 {
     _leaderboard.Score    = score;
     _leaderboard.Username = "******";
     azure.Insert <Leaderboard>(_leaderboard);
 }