Exemple #1
0
    public void AskMana()
    {
        // Play sound
        SoundManager.PlayButtonClick();

        if (!Helper.IsOnline())
        {
            Manager.Instance.ShowMessage(Settings.NoInternetConnection);
            return;
        }

        FBHelper.AskForObject(null, "mana", Settings.AskManaTitle, Settings.AskManaMessage, (error) => {
            if (!string.IsNullOrEmpty(error))
            {
                ///Log.Debug("Ask mana error: " + error);
                Manager.Instance.ShowMessage(Settings.AskManaFailed);
            }
            else
            {
                // Close popup
                Close();
            }
        });
    }
    void OnGUI()
    {
        if (!_showDebug)
        {
            if (GUI.Button(new Rect(0, 0, 100, 100), "", GUIStyle.none))
            {
                double time = System.DateTime.Now.TimeOfDay.TotalSeconds;

                if (time - _lastTime < 0.35)
                {
                    _lastTime = 0;

                    _showDebug = !_showDebug;
                }
                else
                {
                    _lastTime = time;
                }
            }
        }

        if (_showDebug)
        {
            GUILayout.BeginArea(new Rect(10, 10, Screen.width, Screen.height));
            GUILayout.BeginHorizontal();
            GUILayout.BeginVertical();

//			if (!FB.IsLoggedIn)
//			{
//				if (settingsPopup.activeSelf)
//				{
//					if (GUILayout.Button("Log in Facebook"))
//					{
//						LoginFacebook();
//					}
//				}
//				else
//				{
//					if (GUILayout.Button("Connect Facebook"))
//					{
//						ConnectFacebook();
//					}
//				}
//			}

            if (FB.IsLoggedIn)
            {
                if (GUILayout.Button("Get score"))
                {
                    FBHelper.GetScore(null, (score, error) => {
                        if (!string.IsNullOrEmpty(error))
                        {
                            //Log.Debug("Get score error: " + error);
                        }
                        else
                        {
                            //Log.Debug("Score: " + score);
                        }
                    });
                }

                if (GUILayout.Button("Post score"))
                {
                    int score = Random.Range(1, 10);

                    FBHelper.PostScore(null, score, (result, error) => {
                        if (!string.IsNullOrEmpty(error))
                        {
                            //Log.Debug("Post score error: " + error);
                        }
                        else
                        {
                            //Log.Debug(string.Format("Post score {0}: {1}", score, result));
                        }
                    });
                }

                if (GUILayout.Button("Delete score"))
                {
                    FBHelper.DeleteScore(null, (result, error) => {
                        if (!string.IsNullOrEmpty(error))
                        {
                            //Log.Debug("Delete score error: " + error);
                        }
                        else
                        {
                            //Log.Debug("Delete score: " + result);
                        }
                    });
                }

                if (GUILayout.Button("Get highscores"))
                {
                    FBHelper.GetHighscores((ids, names, scores, error) => {
                        if (!string.IsNullOrEmpty(error))
                        {
                            //Log.Debug("Get highscores error: " + error);
                        }
                        else
                        {
                            int count = ids.Length;

                            for (int i = 0; i < count; i++)
                            {
                                //Debug.Log(string.Format("{0}. {1}\t{2}\t{3}", i + 1, ids[i], names[i], scores[i]));
                            }
                        }
                    });
                }

                if (GUILayout.Button("Delete highscores"))
                {
                    FBHelper.DeleteHighscores((result, error) => {
                        if (!string.IsNullOrEmpty(error))
                        {
                            //Log.Debug("Delete highscores error: " + error);
                        }
                        else
                        {
                            //Log.Debug("Delete highscores: " + result);
                        }
                    });
                }

                if (GUILayout.Button("Invite friends"))
                {
                    FBHelper.Invite(Settings.InviteTitle, Settings.InviteMessage, FriendType.Invitable, FBObjectType.Coin, (error) => {
                        if (!string.IsNullOrEmpty(error))
                        {
                            //Log.Debug("Invite friends error: " + error);
                        }
                    });
                }

                if (GUILayout.Button("Invite users"))
                {
                    FBHelper.Invite(Settings.InviteTitle, Settings.InviteMessage, FriendType.Game, FBObjectType.Coin, (error) => {
                        if (!string.IsNullOrEmpty(error))
                        {
                            //Log.Debug("Invite users error: " + error);
                        }
                    });
                }

                if (GUILayout.Button("Send Coin"))
                {
                    FBHelper.SendObject(null, "coin", "Send a coin to your friend", "Take this coin", (error) => {
                        if (!string.IsNullOrEmpty(error))
                        {
                            //Log.Debug("Send coin error: " + error);
                        }
                    });
                }

                if (GUILayout.Button("Ask Coin"))
                {
                    FBHelper.AskForObject(null, "coin", "Request a coin from your friend", "Give me a coin", (error) => {
                        if (!string.IsNullOrEmpty(error))
                        {
                            //Log.Debug("Ask coin error: " + error);
                        }
                    });
                }

                if (GUILayout.Button("Send Mana"))
                {
                    FBHelper.SendObject(null, "mana", Settings.SendManaTitle, Settings.SendManaMessage, (error) => {
                        if (!string.IsNullOrEmpty(error))
                        {
                            //Log.Debug("Send mana error: " + error);
                        }
                    });
                }

                if (GUILayout.Button("Ask Mana"))
                {
                    FBHelper.AskForObject(null, "mana", Settings.AskManaTitle, Settings.AskManaMessage, (error) => {
                        if (!string.IsNullOrEmpty(error))
                        {
                            //Log.Debug("Ask mana error: " + error);
                        }
                    });
                }
            }

            if (GUILayout.Button("Reset Data"))
            {
                UserData.Instance.Reset();

                NotificationManager.ManaChanged(UserData.Instance.Mana);
                NotificationManager.CoinChanged(UserData.Instance.Coin);

                if (FB.IsLoggedIn)
                {
                    // Delete Facebook score
                    FBHelper.DeleteScore(null);
                }
            }

            if (GUILayout.Button("Close"))
            {
                _showDebug = false;
            }

            GUILayout.EndVertical();
            GUILayout.FlexibleSpace();
            GUILayout.EndHorizontal();
            GUILayout.EndArea();
        }
    }