void OnFacebookLogin(FBResult result)
    {
        if (FB.IsLoggedIn)
        {
            // It worked
            Debug.Log("Facebook auth success");

            // Now we login using Braincloud
            BrainCloudWrapper.GetBC().AuthenticationService.AuthenticateFacebook(
                FB.UserId,
                FB.AccessToken,
                true,
                OnBraincloudAuthenticateFacebookSuccess,
                OnBraincloudAuthenticateFacebookFailed);

            // Meanwhile, we will fetch info about our player, to get the profile pic and name
            FB.API("/me?fields=name,picture", Facebook.HttpMethod.GET, OnFacebookMe);
        }
        else
        {
            // It failed
            Debug.LogError("Facebook auth failed");
            m_isConnecting = false;
            spinner.gameObject.SetActive(false);             // Hide spinner
        }
    }
Exemple #2
0
    public void ResetPlayerVC_Success(string json, object cbObject)
    {
        m_currencies.Clear();

        BrainCloudWrapper.GetBC().PlayerStateService.ReadPlayerState(ReadPlayerState_Success, Failure_Callback);
        m_mainScene.AddLogNoLn("[ReadPlayerState]... ");
    }
        public void Setup()
        {
            LoadIds();

            _bc = new BrainCloudWrapper();
            Dictionary <string, string> secretMap = new Dictionary <string, string>();

            secretMap.Add(AppId, Secret);
            secretMap.Add(ChildAppId, ChildSecret);
            _bc.InitWithApps(ServerUrl, AppId, secretMap, Version);
            _bc.Client.EnableLogging(true);
            _bc.Client.RegisterLogDelegate(HandleLog);

            //set to enable compression
            if (SupportsCompression != "")
            {
                _bc.Client.EnableCompression(Boolean.Parse(SupportsCompression));
            }

            if (ShouldAuthenticate())
            {
                TestResult tr = new TestResult(_bc);
                _bc.Client.AuthenticationService.AuthenticateUniversal(
                    GetUser(Users.UserA).Id,
                    GetUser(Users.UserA).Password,
                    true,
                    tr.ApiSuccess, tr.ApiError);
                tr.Run();
            }
        }
Exemple #4
0
        void RetrieveGlobalStats()
        {
            m_stats.Clear();

            BrainCloudWrapper.GetBC().GlobalStatisticsService.ReadAllGlobalStats(
                ReadGlobalStatsSuccess, ReadGlobalStatsFailure);
        }
        void Start()
        {
            m_versionNumber = ((TextAsset)Resources.Load("Version")).text.ToString();
            GameObject.Find("Version Text").GetComponent <Text>().text = m_versionNumber;
            DontDestroyOnLoad(GameObject.Find("Version Text"));
            DontDestroyOnLoad(GameObject.Find("FullScreen"));
            GameObject.Find("Version Text").transform.SetParent(GameObject.Find("Canvas").transform);
            GameObject.Find("FullScreen").transform.SetParent(GameObject.Find("Canvas").transform);
            Application.runInBackground = true;

            ///////////////////////////////////////////////////////////////////
            // brainCloud game configuration
            ///////////////////////////////////////////////////////////////////

            BrainCloudWrapper.Initialize();

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

            m_username = PlayerPrefs.GetString("username");
            if (PlayerPrefs.GetInt("remember") == 0)
            {
                GameObject.Find("Toggle").GetComponent <Toggle>().isOn = false;
            }
            else
            {
                GameObject.Find("Toggle").GetComponent <Toggle>().isOn = true;
            }
            // Stores the password in plain text directly in the unity store.
            // This is obviously not secure but speeds up debugging/testing.
            m_password = PlayerPrefs.GetString("password");
            GameObject.Find("UsernameBox").GetComponent <InputField>().text = m_username;
            GameObject.Find("PasswordBox").GetComponent <InputField>().text = m_password;
        }
        public void OnSuccess_Authenticate(string responseData, object cbObject)
        {
            AppendLog("Authenticate successful!");
            JsonData response = JsonMapper.ToObject(responseData);
            string   username = "";

            if (response["data"]["playerName"].ToString() == "")
            {
                for (int i = 0; i < m_username.Length; i++)
                {
                    if (m_username[i] != '@')
                    {
                        username += m_username[i].ToString();
                    }
                    else
                    {
                        break;
                    }
                }
                BrainCloudWrapper.GetBC().PlayerStateService.UpdatePlayerName(username);
            }
            else
            {
                username = response["data"]["playerName"].ToString();
            }

            GameObject.Find("BrainCloudStats").GetComponent <BrainCloudStats>().ReadStatistics();
            GameObject.Find("BrainCloudStats").GetComponent <BrainCloudStats>().ReadGlobalProperties();
            GameObject.Find("BrainCloudStats").GetComponent <BrainCloudStats>().m_playerName = username;
            GameObject.Find("Version Text").transform.SetParent(null);
            GameObject.Find("FullScreen").transform.SetParent(null);
            NetworkManager.singleton.StartMatchMaker();
            Application.LoadLevel("Matchmaking");
        }
    // When the app starts, check to make sure that we have
    // the required dependencies to use Firebase, and if not,
    // add them if possible.
    private void Start()
    {
        dependencyStatus = FirebaseApp.CheckDependencies();
        if (dependencyStatus != DependencyStatus.Available)
        {
            FirebaseApp.FixDependenciesAsync().ContinueWith(task =>
            {
                dependencyStatus = FirebaseApp.CheckDependencies();
                if (dependencyStatus == DependencyStatus.Available)
                {
                    InitializeFirebase();
                }
                else
                {
                    Debug.LogError(
                        "Could not resolve all Firebase dependencies: " + dependencyStatus);
                }
            });
        }
        else
        {
            InitializeFirebase();
        }



        //Set up brainCloud
        _bc = gameObject.AddComponent <BrainCloudWrapper>();
        _bc.Init();

        _bc.AlwaysAllowProfileSwitch = true;
    }
Exemple #8
0
 private void Awake()
 {
     DontDestroyOnLoad(gameObject);
     _bc             = gameObject.AddComponent <BrainCloudWrapper>();
     _bc.WrapperName = gameObject.name;
     _bc.InitWithApps();
 }
    void Start()
    {
        _bc = BCConfig.GetBrainCloud();
#if UNITY_ANDROID
        PlayGamesClientConfiguration config = new PlayGamesClientConfiguration.Builder()
                                              .RequestIdToken()
                                              .RequestEmail()
                                              .RequestServerAuthCode(false)
                                              .Build();

        PlayGamesPlatform.InitializeInstance(config);
#endif

#if UNITY_WSA
        _xboxLiveUser = new XboxLiveUser();
        try
        {
            SignInManager.Instance.OnPlayerSignOut(playerNumber, OnPlayerSignOut);
            SignInManager.Instance.OnPlayerSignIn(playerNumber, OnPlayerSignIn);
        }
        catch (Exception ex)
        {
            Debug.Log(ex.Message);
        }
#endif

        //m_AccessTokenResponse = new Twitter.AccessTokenResponse();
    }
Exemple #10
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);
        }
    public IEnumerator SetUpNewUser(Users user, bool resetCount = true, BrainCloudWrapper wrapper = null)
    {
        if (!_init)
        {
            Debug.Log(">> Initializing New Random Users");
            BrainCloudWrapper userWrapper = wrapper != null ? wrapper : bcWrapper;
            userWrapper.Client.EnableLogging(true);

            Random rand = new Random();

            TestUserA = gameObject.AddComponent <TestUser>();
            IEnumerator setUpUserRoutine = TestUserA.SetUp
                                           (
                userWrapper,
                user + "_UNITY" + "-",
                rand.Next(),
                this
                                           );

            yield return(StartCoroutine(setUpUserRoutine));

            _init = true;

            successCount = resetCount ? 0 : successCount;
        }
    }
Exemple #12
0
        void RetrievePlayerStats()
        {
            m_stats.Clear();

            BrainCloudWrapper.GetBC().PlayerStatisticsService.ReadAllPlayerStats(
                ReadPlayerStatsSuccess, ReadPlayerStatsFailure);
        }
Exemple #13
0
    public static BrainCloudWrapper GetInstance()
    {
        if (s_applicationIsQuitting)
        {
            return(null);
        }

        lock (s_lock)
        {
            if (s_instance == null)
            {
                s_instance = (BrainCloudWrapper)FindObjectOfType(typeof(BrainCloudWrapper));
                if (s_instance != null)
                {
                    s_instance.Reauthenticate();
                }

                if (FindObjectsOfType(typeof(BrainCloudWrapper)).Length > 1)
                {
                    Debug.LogError("[Singleton] Something went really wrong " +
                                   " - there should never be more than 1 singleton!" +
                                   " Reopenning the scene might fix it.");
                    return(s_instance);
                }

                if (s_instance == null)
                {
                    GameObject go = new GameObject(GAMEOBJECT_BRAINCLOUD);
                    s_instance = go.AddComponent <BrainCloudWrapper>();
                    DontDestroyOnLoad(go);
                }
            }
            return(s_instance);
        }
    }
Exemple #14
0
    private void SaveStatisticsToBrainCloud()
    {
        // Build the statistics name/inc value dictionary
        Dictionary <string, object> stats = new Dictionary <string, object> {
            { "BirdsShot", m_BirdsShot },
            { "MiniUFOsShot", m_MiniUFOsShot },
            { "CarsDestroyed", m_CarsDestroyed },
            { "BossesKilled", m_BossesKilled },
            { "TrucksDestroyed", m_TrucksDestroyed }
        };

        // Send to the cloud
        BrainCloudWrapper.GetBC().PlayerStatisticsService.IncrementPlayerStats(
            stats, StatsSuccess_Callback, StatsFailure_Callback, null);

        m_BirdsShot       = 0;
        m_CarsDestroyed   = 0;
        m_MiniUFOsShot    = 0;
        m_TrucksDestroyed = 0;
        m_BossesKilled    = 0;

        if (m_IsQuitting)
        {
            Application.Quit();
        }
    }
    void EnterMatch(MatchInfo match)
    {
        m_state = eState.LOADING;

        // Query more detail state about the match
        BrainCloudWrapper.GetBC().AsyncMatchService.ReadMatch(match.ownerId, match.matchId, OnReadMatch, OnReadMatchFailed, match);
    }
 public TestUser(BrainCloudWrapper bc, string idPrefix, int suffix)
 {
     _bc      = bc;
     Id       = idPrefix + suffix;
     Password = Id;
     Email    = Id + "@bctestuser.com";
 }
Exemple #17
0
        public void OnSuccess_Authenticate(string responseData, object cbObject)
        {
            AppendLog("Authenticate successful!");
            JsonData response = JsonMapper.ToObject(responseData);
            string   username = "";

            if (response["data"]["playerName"].ToString() == "")
            {
                for (int i = 0; i < m_username.Length; i++)
                {
                    if (m_username[i] != '@')
                    {
                        username += m_username[i].ToString();
                    }
                    else
                    {
                        break;
                    }
                }
                BrainCloudWrapper.GetBC().PlayerStateService.UpdatePlayerName(username);
                PhotonNetwork.player.name = username;
            }
            else
            {
                PhotonNetwork.player.name = response["data"]["playerName"].ToString();
            }

            GameObject.Find("BrainCloudStats").GetComponent <BrainCloudStats>().ReadStatistics();
            GameObject.Find("BrainCloudStats").GetComponent <BrainCloudStats>().ReadGlobalProperties();
            PhotonNetwork.sendRate = 20;
            Application.LoadLevel("Matchmaking");
        }
Exemple #18
0
        void OnGUI()
        {
            if (!BrainCloudWrapper.GetBC().IsAuthenticated())
            {
                int width = Screen.width / 2 - 125;
                if (width < 500)
                {
                    width = 500;
                }
                if (width > Screen.width)
                {
                    width = Screen.width;
                }

                int height = Screen.height / 2 - 200;
                if (height < 400)
                {
                    height = 400;
                }
                if (height > Screen.height)
                {
                    height = Screen.height;
                }

                GUILayout.Window(0, new Rect(Screen.width / 2 - (width / 2), Screen.height / 2 - (height / 2), width, height), OnWindow, "brainCloud Login");
            }
        }
Exemple #19
0
 public void FinishEditName()
 {
     GameObject.Find("BrainCloudStats").GetComponent <BrainCloudStats>().m_playerName = GameObject.Find("PlayerName").GetComponent <InputField>().text;
     BrainCloudWrapper.GetBC().PlayerStateService.UpdatePlayerName(GameObject.Find("PlayerName").GetComponent <InputField>().text);
     GameObject.Find("PlayerName").GetComponent <InputField>().interactable = false;
     GameObject.Find("PlayerName").GetComponent <Image>().enabled           = false;
 }
Exemple #20
0
    public override void Activate()
    {
        BrainCloudWrapper.GetBC().EntityFactory.RegisterEntityClass <Player>(Player.ENTITY_TYPE);

        BrainCloudWrapper.GetBC().PlayerStateService.ReadPlayerState(ReadPlayerStateSuccess, Failure_Callback);
        m_mainScene.AddLogNoLn("[ReadPlayerState]... ");
    }
    // Use this for initialization
    void Awake()
    {
        DontDestroyOnLoad(gameObject);
        _bc = gameObject.AddComponent <BrainCloudWrapper>();

        _bc.WrapperName = gameObject.name; // Optional: Set a wrapper name
        _bc.Init();                        // Init data is taken from the brainCloud Unity Plugin
    }
Exemple #22
0
 private void Awake()
 {
     DontDestroyOnLoad(gameObject);
     _bc             = gameObject.AddComponent <BrainCloudWrapper>();
     _bc.WrapperName = name;
     _bc.Init();
     _eventSystem = EventSystem.current;
 }
Exemple #23
0
 public Player() : base(BrainCloudWrapper.GetBC().EntityService)
 {
     // set up some defaults
     m_entityType = "player";
     Name         = "";
     Age          = 0;
     Hobbies      = new List <Hobby>();
 }
Exemple #24
0
 // Uninitialize brainCloud
 void UninitBC()
 {
     if (m_bcWrapper != null)
     {
         m_bcWrapper.Client.ShutDown();
         m_bcWrapper = null;
     }
 }
        void RetrieveLeaderboard(string leaderboardId)
        {
            m_lb.Clear();

            BrainCloudWrapper.GetBC().SocialLeaderboardService.GetGlobalLeaderboardPage(
                leaderboardId, BrainCloud.BrainCloudSocialLeaderboard.SortOrder.HIGH_TO_LOW, 0, 100, false,
                ReadLeaderboardSuccess, ReadLeaderboardFailure);
        }
Exemple #26
0
        void RetrieveLeaderboard(string leaderboardId)
        {
            m_lb.Clear();

            BrainCloudWrapper.GetBC().SocialLeaderboardService.GetGlobalLeaderboard(
                leaderboardId, BrainCloud.BrainCloudSocialLeaderboard.FetchType.HIGHEST_RANKED, 100,
                ReadLeaderboardSuccess, ReadLeaderboardFailure);
        }
    ////////////////////////////////////////////
    // BrainCloud integration code
    ////////////////////////////////////////////

    private void ReadStatistics()
    {
        // Ask brainCloud for statistics
        BrainCloudWrapper.GetBC().PlayerStatisticsService.ReadAllPlayerStats(StatsSuccess_Callback, StatsFailure_Callback, null);

        brainCloudStatusText.text = "Reading statistics from brainCloud...";
        brainCloudStatusText.gameObject.SetActive(true);
    }
Exemple #28
0
 public void ReadStatistics()
 {
     // Ask brainCloud for statistics
     BrainCloudWrapper.GetBC().PlayerStatisticsService.ReadAllPlayerStats(StatsSuccess_Callback, StatsFailure_Callback, null);
     BrainCloudWrapper.GetBC().PlayerStateService.ReadPlayerState(StateSuccess_Callback, StateFailure_Callback, null);
     BrainCloudWrapper.GetBC().GamificationService.ReadXpLevelsMetaData(LevelsSuccess_Callback, LevelsFailure_Callback, null);
     BrainCloudWrapper.GetBC().GamificationService.ReadAchievements(true, AchievementSuccess_Callback, AchievementFailure_Callback, null);
 }
 void OnGUIBottom()
 {
     GUILayout.BeginHorizontal();
     GUILayout.Box("Game Id: " + BrainCloudWrapper.GetBC().GameId);
     GUILayout.Box("Game Version: " + BrainCloudWrapper.GetBC().GameVersion);
     GUILayout.Box("Profile Id: " + BrainCloudWrapper.GetBC().AuthenticationService.ProfileId);
     GUILayout.FlexibleSpace();
     GUILayout.EndHorizontal();
 }
Exemple #30
0
 void OnPostScoreSuccess(string postResponseData, object cbPostObject)
 {
     // Now we fetch the leaderboards to see were we stand
     BrainCloudWrapper.GetBC().SocialLeaderboardService.GetLeaderboard(
         "spacegame_highscores",                     // Leaderboard Id
         true,                                       // If true, your name will be replaced with "You"
         OnGetLeaderboardsSuccess,                   // Success callback
         OnGetLeaderboardsFailed);                   // Failed callback
 }
    public static BrainCloudWrapper GetInstance()
    {
        if (s_applicationIsQuitting)
        {
            return null;
        }

        lock (s_lock)
        {
            if (s_instance == null)
            {

                s_instance = (BrainCloudWrapper) FindObjectOfType(typeof(BrainCloudWrapper));
                if (s_instance != null)
                {
                    s_instance.Reauthenticate();
                }

                if ( FindObjectsOfType(typeof(BrainCloudWrapper)).Length > 1 )
                {
                    Debug.LogError("[Singleton] Something went really wrong " +
                        " - there should never be more than 1 singleton!" +
                        " Reopenning the scene might fix it.");
                    return s_instance;
                }

                if (s_instance == null)
                {
                    GameObject go = new GameObject(GAMEOBJECT_BRAINCLOUD);
                    s_instance = go.AddComponent<BrainCloudWrapper>();
                    DontDestroyOnLoad(go);
                }
            }
            return s_instance;
        }
    }