Пример #1
0
        static int Main(string[] args)
        {
            bc = new BrainCloudWrapper("RelayExampleAppProd");
            bc.ResetStoredProfileId();

            // Comment this line, and uncomment the next one. Fill in you ids
            InitBCFromIdsTXT();
            //bc.Init("https://sharedprod.braincloudservers.com/dispatcherv2", "your app secret", "your app id", "1.0");

            bc.Client.EnableLogging(true);
            bc.AuthenticateAnonymous(onAuthenticated, onFailed);

            // Main event loop running at 60fps as a game would.
            var startTime = DateTime.Now;

            while (isRunning)
            {
                bc.Update();
                Thread.Sleep(16);
                if ((DateTime.Now - startTime).TotalSeconds >= 120.0) // Run for 2mins
                {
                    isRunning = false;
                }
            }

            return(returnCode);
        }
Пример #2
0
        void Start()
        {
            ///////////////////////////////////////////////////////////////////
            // brainCloud game configuration
            ///////////////////////////////////////////////////////////////////


            BrainCloud = gameObject.AddComponent <BrainCloudWrapper>();
            BrainCloud.Init();

            ///////////////////////////////////////////////////////////////////

            _username = PlayerPrefs.GetString("username");

            // Stores the password in plain text directly in the unity store.
            // This is obviously not secure but speeds up debugging/testing.
            _password = PlayerPrefs.GetString("password");

            // Clearing current profile
            BrainCloud.ResetStoredAnonymousId();
            BrainCloud.ResetStoredProfileId();
        }
Пример #3
0
    void OnGUI()
    {
        float tw          = Screen.width / 14.0f;
        float th          = Screen.height / 7.0f;
        Rect  dialog      = new Rect(tw, th, Screen.width - tw * 2, Screen.height - th * 2);
        float offsetX     = 30;
        float offsetY     = 30;
        Rect  innerDialog = new Rect(dialog.x + offsetX, dialog.y + offsetY, dialog.width - (offsetX * 2), dialog.height - (offsetY * 2));

        GUI.Box(dialog, "Unity Example");
        GUILayout.BeginArea(innerDialog);

        GUILayout.Box("Choose Authentication Type");

        GUILayout.BeginHorizontal();
        GUILayout.FlexibleSpace();
        m_selectedAuth = GUILayout.SelectionGrid(m_selectedAuth, m_authTypes, 4);
        GUILayout.FlexibleSpace();
        GUILayout.EndHorizontal();

        if (m_selectedAuth == (int)eAuthTypes.EMAIL)
        {
            GUILayout.BeginHorizontal();
            GUILayout.BeginVertical();
            GUILayout.Label("Email:");
            GUILayout.Label("Password:"******"Authenticate", GUILayout.ExpandWidth(false)))
            {
                m_authStatus = "Attempting to authenticate";

                // clear out any previous profile or anonymous ids
                _bc.ResetStoredProfileId();
                _bc.ResetStoredAnonymousId();
                _bc.AuthenticateEmailPassword(
                    m_emailId, m_emailPwd, true, OnSuccess_Authenticate, OnError_Authenticate);
            }
        }
        else if (m_selectedAuth == (int)eAuthTypes.UNIVERSAL)
        {
            GUILayout.BeginHorizontal();
            GUILayout.BeginVertical();
            GUILayout.Label("User Id:");
            GUILayout.Label("Password:"******"Authenticate", GUILayout.ExpandWidth(false)))
            {
                m_authStatus = "Attempting to authenticate";

                // clear out any previous profile or anonymous ids
                _bc.ResetStoredProfileId();
                _bc.ResetStoredAnonymousId();
                _bc.AuthenticateUniversal(
                    m_universalUserId, m_universalPwd, true, OnSuccess_Authenticate, OnError_Authenticate);
            }
        }
        else if (m_selectedAuth == (int)eAuthTypes.ANONYMOUS)
        {
            GUILayout.Label("Profile Id: " + _bc.GetStoredProfileId());
            GUILayout.Label("Anonymous Id: " + _bc.GetStoredAnonymousId());
            GUILayout.BeginHorizontal();
            if (GUILayout.Button("Authenticate", GUILayout.ExpandWidth(false)))
            {
                m_authStatus = "Attempting to authenticate";
                _bc.AuthenticateAnonymous(OnSuccess_Authenticate, OnError_Authenticate);
            }
            if (GUILayout.Button("Reset Profile Id", GUILayout.ExpandWidth(false)))
            {
                _bc.ResetStoredProfileId();
            }
            if (GUILayout.Button("Reset Anonymous Id", GUILayout.ExpandWidth(false)))
            {
                _bc.ResetStoredAnonymousId();
            }
            GUILayout.FlexibleSpace();
            GUILayout.EndHorizontal();
        }
        else if (m_selectedAuth == (int)eAuthTypes.GOOGLE)
        {
            GUILayout.Label("Google Id: " + m_googleId);
            GUILayout.Label("Server Auth Code: " + m_serverAuthCode);


            if (GUILayout.Button("Google Signin", GUILayout.ExpandWidth(false)))
            {
#if UNITY_ANDROID
                m_authStatus += "\n\nInfo: If the authentication popup appears but nothing occurs after, it probably means the app isn't fully set up. Please follow the instruction here:\nhttp://getbraincloud.com/apidocs/portal-usage/authentication-google/ \n\n";

                PlayGamesPlatform.Activate().Authenticate((bool success) => {
                    if (success)
                    {
                        m_googleId       = PlayGamesPlatform.Instance.GetUserId();
                        m_serverAuthCode = PlayGamesPlatform.Instance.GetServerAuthCode();

                        m_authStatus += "\nGoogle Auth Success. Now click \"Authenticate\"\n\n";
                    }
                    else
                    {
                        m_authStatus += "\nGoogle Auth Failed. See documentation: https://github.com/playgameservices/play-games-plugin-for-unity\n";
                        m_authStatus += "Note: this can only be tested on an Android Device\n\n";
                    }
                });
#else
                m_authStatus += "\n\nGoogle Login will only work on an Android Device. Please build to a test device\n\n";
#endif
            }

            GUILayout.Label("Profile Id: " + _bc.GetStoredProfileId());
            GUILayout.Label("Anonymous Id: " + _bc.GetStoredAnonymousId());
            GUILayout.BeginHorizontal();
            if (GUILayout.Button("Authenticate", GUILayout.ExpandWidth(false)))
            {
                m_authStatus = "Attempting to authenticate";
                _bc.AuthenticateGoogle(m_googleId, m_serverAuthCode, true, OnSuccess_Authenticate, OnError_Authenticate);
            }
            if (GUILayout.Button("Reset Profile Id", GUILayout.ExpandWidth(false)))
            {
                _bc.ResetStoredProfileId();
            }
            if (GUILayout.Button("Reset Anonymous Id", GUILayout.ExpandWidth(false)))
            {
                _bc.ResetStoredAnonymousId();
            }
            GUILayout.FlexibleSpace();
            GUILayout.EndHorizontal();
        }
        else if (m_selectedAuth == (int)eAuthTypes.FACEBOOK)
        {
#if UNITY_WEBGL || UNITY_STANDALONE_WIN
            GUILayout.Label("Token Id: " + AccessToken.CurrentAccessToken.TokenString);
            GUILayout.Label("User Id: " + _localFacebookUser.id);
            GUILayout.Label("First Name: " + _localFacebookUser.first_name);
            GUILayout.BeginHorizontal();

            if (GUILayout.Button("Initialize", GUILayout.ExpandWidth(false)))
            {
                if (!FB.IsInitialized)
                {
                    FB.Init(InitCallback, HideUnity);
                }
                else
                {
                    FB.ActivateApp();
                }
            }

            if (GUILayout.Button("Authenticate", GUILayout.ExpandWidth(false)))
            {
                m_authStatus = "Attempting to authenticate";
                var perms = new List <string>()
                {
                    "public_profile",
                    "email"
                };
                FB.LogInWithReadPermissions(perms, AuthCallback);
            }
            GUILayout.FlexibleSpace();
            GUILayout.EndHorizontal();
#else
            m_authStatus = "Facebook login is only available on WebGL & Windows Standalone";
#endif
        }
        else if (m_selectedAuth == (int)eAuthTypes.XBOXLIVE)
        {
#if UNITY_WSA
            if (_xboxLiveUser.IsSignedIn)
            {
                GUILayout.Label("Player Number: " + playerNumber);
                GUILayout.Label("Gamer Tag: " + _xboxLiveUser.Gamertag);
                GUILayout.Label("User ID: " + _xboxLiveUser.XboxUserId);
                GUILayout.BeginHorizontal();
            }

            if (GUILayout.Button("Sign In", GUILayout.ExpandWidth(false)))
            {
                StartCoroutine(SignInManager.Instance.SignInPlayer(playerNumber));
            }
#else
            m_authStatus = "Xbox Live login is only available on Universal Windows Platform";
#endif
        }

        m_scrollPosition = GUILayout.BeginScrollView(m_scrollPosition, GUILayout.ExpandWidth(true), GUILayout.ExpandHeight(true));
        GUILayout.TextArea(m_authStatus, GUILayout.ExpandHeight(true));
        GUILayout.EndScrollView();

        GUILayout.BeginHorizontal();
        GUILayout.FlexibleSpace();
        if (GUILayout.Button("Clear Log", GUILayout.Height(25), GUILayout.Width(100)))
        {
            m_authStatus = "";
        }
        GUILayout.EndHorizontal();

        GUILayout.EndArea();
    }
    // Render the buttons and other controls.
    private void GUIDisplayControls()
    {
        if (UIEnabled)
        {
            controlsScrollViewVector =
                GUILayout.BeginScrollView(controlsScrollViewVector);
            GUILayout.BeginVertical();

            float inputWidth = Screen.width < Screen.height ? Screen.width * 0.75f : Screen.width * 0.30f;

            GUILayout.BeginHorizontal();
            GUILayout.Label("Profile Id: ", GUILayout.Width(Screen.width * 0.20f));
            GUILayout.TextField(_bc.GetStoredProfileId(), GUILayout.Width(inputWidth));
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            GUILayout.Label("Token: ", GUILayout.Width(Screen.width * 0.20f));
            GUILayout.TextField(firebaseToken, GUILayout.Width(inputWidth));
            GUILayout.EndHorizontal();

            if (!_bc.Client.IsAuthenticated())
            {
                if (!string.IsNullOrEmpty(_bc.GetStoredAnonymousId()) ||
                    !string.IsNullOrEmpty(_bc.GetStoredProfileId()))
                {
                    _bc.ResetStoredAnonymousId();
                    _bc.ResetStoredProfileId();
                }

                if (GUILayout.Button("Authenticate"))
                {
                    _bc.AuthenticateAnonymous(
                        (response, cbObject) =>
                    {
                        DebugLog(string.Format("brainCloud Authentication Success: {0}", response));
                    },
                        (status, code, error, cbObject) =>
                    {
                        DebugLog(
                            string.Format("brainCloud Authentication Failed: {0} {1} {2}", status, code, error));
                    });
                }
            }
            else
            {
                if (GUILayout.Button("Register"))
                {
                    _bc.PushNotificationService
                    .RegisterPushNotificationDeviceToken(Platform.GooglePlayAndroid, firebaseToken);

                    DebugLog("Registered to brainCloud");
                }
                if (GUILayout.Button("Deregister"))
                {
                    _bc.PushNotificationService
                    .DeregisterPushNotificationDeviceToken(Platform.GooglePlayAndroid, firebaseToken);

                    DebugLog("Deregistered from brainCloud");
                }

                if (GUILayout.Button("SendNormalizedPushNotification"))
                {
                    DebugLog("SendNormalizedPushNotification");

                    _bc.PushNotificationService.SendNormalizedPushNotification(
                        _bc.GetStoredProfileId(),
                        "{ \"body\": \"content of message\", \"title\": \"message title\" }",
                        null,
                        (response, cbObject) => { DebugLog(string.Format("Success: {0}", response)); },
                        (status, code, error, cbObject) =>
                    {
                        DebugLog(string.Format("Failed: {0} {1} {2}", status, code, error));
                    });
                }

                if (GUILayout.Button("SendRichPushNotification"))
                {
                    DebugLog("SendRichPushNotification");

                    _bc.PushNotificationService.SendRichPushNotification(
                        _bc.GetStoredProfileId(),
                        1,
                        (response, cbObject) => { DebugLog(string.Format("Success: {0}", response)); },
                        (status, code, error, cbObject) =>
                    {
                        DebugLog(string.Format("Failed: {0} {1} {2}", status, code, error));
                    });
                }

                if (GUILayout.Button("SendRawPushNotification"))
                {
                    DebugLog("SendRawPushNotification");

                    _bc.PushNotificationService.SendRawPushNotification(
                        _bc.GetStoredProfileId(),
                        "{ \"notification\": { \"body\": \"content of message\", \"title\": \"message title\" }, \"data\": { \"customfield1\": \"customValue1\", \"customfield2\": \"customValue2\" }, \"priority\": \"normal\" }",
                        "{ \"aps\": { \"alert\": { \"body\": \"content of message\", \"title\": \"message title\" }, \"badge\": 0, \"sound\": \"gggg\" } }",
                        "{\"template\": \"content of message\"}",
                        (response, cbObject) => { DebugLog(string.Format("Success: {0}", response)); },
                        (status, code, error, cbObject) =>
                    {
                        DebugLog(string.Format("Failed: {0} {1} {2}", status, code, error));
                    });
                }
            }

            GUILayout.EndVertical();
            GUILayout.EndScrollView();
        }
    }
Пример #5
0
    void OnGUI()
    {
        float tw          = Screen.width / 14.0f;
        float th          = Screen.height / 7.0f;
        Rect  dialog      = new Rect(tw, th, Screen.width - tw * 2, Screen.height - th * 2);
        float offsetX     = 30;
        float offsetY     = 30;
        Rect  innerDialog = new Rect(dialog.x + offsetX, dialog.y + offsetY, dialog.width - (offsetX * 2), dialog.height - (offsetY * 2));

        GUI.Box(dialog, "Unity Example");
        GUILayout.BeginArea(innerDialog);

        GUILayout.Box("Choose Authentication Type");

        GUILayout.BeginHorizontal();
        GUILayout.FlexibleSpace();
        m_selectedAuth = GUILayout.SelectionGrid(m_selectedAuth, m_authTypes, 4);
        GUILayout.FlexibleSpace();
        GUILayout.EndHorizontal();

        if (m_selectedAuth == (int)eAuthTypes.EMAIL)
        {
            GUILayout.BeginHorizontal();
            GUILayout.BeginVertical();
            GUILayout.Label("Email:");
            GUILayout.Label("Password:"******"Authenticate", GUILayout.ExpandWidth(false)))
            {
                m_authStatus = "Attempting to authenticate";

                // clear out any previous profile or anonymous ids
                _bc.ResetStoredProfileId();
                _bc.ResetStoredAnonymousId();
                _bc.AuthenticateEmailPassword(
                    m_emailId, m_emailPwd, true, OnSuccess_Authenticate, OnError_Authenticate);
            }
        }
        else if (m_selectedAuth == (int)eAuthTypes.UNIVERSAL)
        {
            GUILayout.BeginHorizontal();
            GUILayout.BeginVertical();
            GUILayout.Label("User Id:");
            GUILayout.Label("Password:"******"Authenticate", GUILayout.ExpandWidth(false)))
            {
                m_authStatus = "Attempting to authenticate";

                // clear out any previous profile or anonymous ids
                _bc.ResetStoredProfileId();
                _bc.ResetStoredAnonymousId();
                _bc.AuthenticateUniversal(
                    m_universalUserId, m_universalPwd, true, OnSuccess_Authenticate, OnError_Authenticate);
            }
        }

        /*else if (m_selectedAuth == (int) eAuthTypes.TWITTER)
         * {
         *  GUILayout.BeginHorizontal();
         *  GUILayout.BeginVertical();
         *  if (GUILayout.Button("Get PIN"))
         *  {
         *      StartCoroutine(Twitter.API.GetRequestToken(CONSUMER_KEY, CONSUMER_SECRET,
         *                                                     new Twitter.RequestTokenCallback(this.OnSuccess_GetPIN)));
         *  }
         *  GUILayout.EndVertical();
         *  GUILayout.BeginVertical();
         *  GUILayout.Label("PIN:");
         *  m_emailId = GUILayout.TextField(m_emailId, GUILayout.MinWidth(200));
         *  //m_emailPwd = GUILayout.PasswordField(m_emailPwd, '*', GUILayout.MinWidth(200));
         *  GUILayout.EndVertical();
         *  GUILayout.FlexibleSpace();
         *  GUILayout.EndHorizontal();
         *
         *  if (GUILayout.Button("Enter PIN", GUILayout.ExpandWidth(false)))
         *  {
         *      m_authStatus = "Attempting to authenticate";
         *
         *      // clear out any previous profile or anonymous ids
         *      _bc.ResetStoredProfileId();
         *      _bc.ResetStoredAnonymousId();
         *      StartCoroutine(Twitter.API.GetAccessToken(CONSUMER_KEY, CONSUMER_SECRET, m_RequestTokenResponse.Token, m_emailId,
         *                     new Twitter.AccessTokenCallback(this.OnSuccess_AuthenticateTwitter)));
         *      //_bc.AuthenticationService.AuthenticateTwitter()
         *
         *      //_bc.AuthenticateEmailPassword(
         *         // m_emailId, m_emailPwd, true, OnSuccess_Authenticate, OnError_Authenticate);
         *  }
         * }*/
        else if (m_selectedAuth == (int)eAuthTypes.ANONYMOUS)
        {
            GUILayout.Label("Profile Id: " + _bc.GetStoredProfileId());
            GUILayout.Label("Anonymous Id: " + _bc.GetStoredAnonymousId());
            GUILayout.BeginHorizontal();
            if (GUILayout.Button("Authenticate", GUILayout.ExpandWidth(false)))
            {
                m_authStatus = "Attempting to authenticate";
                _bc.AuthenticateAnonymous(OnSuccess_Authenticate, OnError_Authenticate);
            }
            if (GUILayout.Button("Reset Profile Id", GUILayout.ExpandWidth(false)))
            {
                _bc.ResetStoredProfileId();
            }
            if (GUILayout.Button("Reset Anonymous Id", GUILayout.ExpandWidth(false)))
            {
                _bc.ResetStoredAnonymousId();
            }
            GUILayout.FlexibleSpace();
            GUILayout.EndHorizontal();
        }
        else if (m_selectedAuth == (int)eAuthTypes.GOOGLE)
        {
            GUILayout.Label("Google Id: " + m_googleId);
            GUILayout.Label("Server Auth Code: " + m_serverAuthCode);


            if (GUILayout.Button("Google Signin", GUILayout.ExpandWidth(false)))
            {
                #if UNITY_ANDROID
                m_authStatus += "\n\nInfo: If the authentication popup appears but nothing occurs after, it probably means the app isn't fully set up. Please follow the instruction here:\nhttp://getbraincloud.com/apidocs/portal-usage/authentication-google/ \n\n";


                PlayGamesClientConfiguration config = new PlayGamesClientConfiguration.Builder()
                                                      .RequestIdToken()
                                                      .RequestServerAuthCode(false)
                                                      .Build();

                PlayGamesPlatform.InitializeInstance(config);
                PlayGamesPlatform.Activate().Authenticate((bool success) => {
                    if (success)
                    {
                        m_googleId       = PlayGamesPlatform.Instance.GetUserId();
                        m_serverAuthCode = PlayGamesPlatform.Instance.GetServerAuthCode();

                        m_authStatus += "\nGoogle Auth Success. Now click \"Authenticate\"\n\n";
                    }
                    else
                    {
                        m_authStatus += "\nGoogle Auth Failed. See documentation: https://github.com/playgameservices/play-games-plugin-for-unity\n";
                        m_authStatus += "Note: this can only be tested on an Android Device\n\n";
                    }
                });
                #else
                m_authStatus += "\n\nGoogle Login will only work on an Android Device. Please build to a test device\n\n";
                #endif
            }


            GUILayout.Label("Profile Id: " + _bc.GetStoredProfileId());
            GUILayout.Label("Anonymous Id: " + _bc.GetStoredAnonymousId());
            GUILayout.BeginHorizontal();
            if (GUILayout.Button("Authenticate", GUILayout.ExpandWidth(false)))
            {
                m_authStatus = "Attempting to authenticate";
                _bc.AuthenticateGoogle(m_googleId, m_serverAuthCode, true, OnSuccess_Authenticate, OnError_Authenticate);
            }
            if (GUILayout.Button("Reset Profile Id", GUILayout.ExpandWidth(false)))
            {
                _bc.ResetStoredProfileId();
            }
            if (GUILayout.Button("Reset Anonymous Id", GUILayout.ExpandWidth(false)))
            {
                _bc.ResetStoredAnonymousId();
            }
            GUILayout.FlexibleSpace();
            GUILayout.EndHorizontal();
        }

        m_scrollPosition = GUILayout.BeginScrollView(m_scrollPosition, GUILayout.ExpandWidth(true), GUILayout.ExpandHeight(true));
        GUILayout.TextArea(m_authStatus, GUILayout.ExpandHeight(true));
        GUILayout.EndScrollView();

        GUILayout.BeginHorizontal();
        GUILayout.FlexibleSpace();
        if (GUILayout.Button("Clear Log", GUILayout.Height(25), GUILayout.Width(100)))
        {
            m_authStatus = "";
        }
        GUILayout.EndHorizontal();

        //GUILayout.FlexibleSpace();
        //GUILayout.Box("Stored Information");

        GUILayout.EndArea();
    }