/// <summary>
        /// 非同期処理でオブジェクトの取得を行います。
        /// </summary>
        /// <returns>取得したオブジェクト</returns>
        public static IObservable <NCMBUser> FetchAsyncAsStream(this NCMBUser origin)
        {
            return(Observable.Create <NCMBUser>(observer =>
            {
                var gate = new object();
                var isDisposed = false;
                origin.FetchAsync(error =>
                {
                    lock (gate)
                    {
                        if (isDisposed)
                        {
                            return;
                        }

                        if (error == null)
                        {
                            observer.OnNext(origin);
                            observer.OnCompleted();
                        }
                        else
                        {
                            observer.OnError(error);
                        }
                    }
                });
                return Disposable.Create(() =>
                {
                    lock (gate)
                    {
                        isDisposed = true;
                    }
                });
            }));
        }
    /// <summary>
    /// オブジェクトIDをキーにしてプレイヤー情報をデータベースから作成する
    /// </summary>
    /// <param name="objectId"></param>
    private void initializePlayerInfo(string objectId)
    {
        NCMBUser user = new NCMBUser();

        user.ObjectId = objectId;
        user.FetchAsync((NCMBException e) => {
            if (e != null)
            {
                Debug.Log("データベース登録失敗");
                //エラー処理
            }
            else
            {
                //成功時の処理
                string name = user.UserName;
                int rate    = 0;
                int coins   = 0;
                var tmpVal1 = (string)user["PossessingItemsPage1"];
                var tmpVal2 = (string)user["PossessingItemsPage2"];
                float possessingItemsPage1 = float.Parse(tmpVal1);
                float possessingItemsPage2 = float.Parse(tmpVal2);
                float alignInfo            = float.Parse((string)user["AlignInfo"]);
                PossessingItems items      = new PossessingItems(possessingItemsPage1, possessingItemsPage2);
                GameManager.Instance.SetPlayerInfo(0, name, rate, coins, items, alignInfo);

                Debug.Log("データベース登録完了");
                //GameManager.Instance.SetUserData(user);
                //メニューシーンへ
                GameManager.Instance.LoadScene("MenuScene");
            }
        });
    }
Exemplo n.º 3
0
    public IEnumerator LogInWithAuthDataAsyncFacebookThenFetchOtherUser()
    {
        // テストデータ作成
        NCMBUser user = new NCMBUser();

        user.AuthData = facebookParams.param;

        // authData登録
        user.LogInWithAuthDataAsync((NCMBException e) => {
            Assert.Null(e);

            user          = new NCMBUser();
            user.ObjectId = "anotherObjectId";
            user.FetchAsync();

            NCMBTestSettings.CallbackFlag = true;
        });
        yield return(NCMBTestSettings.AwaitAsync());

        user = NCMBUser.CurrentUser;
        Assert.AreEqual("dummyObjectId", user.ObjectId);

        // facebookパラメータ確認
        Dictionary <string, object> authData = user.GetAuthDataForProvider("facebook");

        Assert.AreEqual("facebookDummyId", authData ["id"]);
        Assert.AreEqual("facebookDummyAccessToken", authData ["access_token"]);
        Assert.AreEqual("2017-02-07T01:02:03.004Z", authData ["expiration_date"]);

        // 登録成功の確認
        Assert.IsNotEmpty(NCMBUser._getCurrentSessionToken());
        Assert.True(user.IsLinkWith("facebook"));
        Assert.True(NCMBTestSettings.CallbackFlag);
    }
Exemplo n.º 4
0
    public IEnumerator FetchAsyncUserAuthenticationError()
    {
        // テストデータ作成
        NCMBUser.LogInAsync("tarou", "tarou", (e) => {
            Assert.Null(e);

            NCMBUser.CurrentUser.SessionToken = "invalidToken";
            NCMBUser.CurrentUser._currentOperations.Clear();

            NCMBUser user = new NCMBUser();
            user.ObjectId = "dummyObjectIdError";
            user.FetchAsync((NCMBException ex) =>
            {
                Assert.NotNull(ex);
                Assert.AreEqual("E401001", ex.ErrorCode);
                Assert.AreEqual("Authentication error by header incorrect.", ex.ErrorMessage);
                NCMBTestSettings.CallbackFlag = true;
            });
        });

        yield return(NCMBTestSettings.AwaitAsync());

        // 登録成功の確認
        Assert.True(NCMBTestSettings.CallbackFlag);
    }
Exemplo n.º 5
0
    public IEnumerator FetchAsyncCurrentUserDataNotAvailable()
    {
        // テストデータ作成
        NCMBUser.LogInAsync("tarou", "tarou", (e) => {
            Assert.Null(e);

            NCMBUser.CurrentUser.SessionToken = "invalidToken";
            NCMBUser.CurrentUser.ObjectId     = "invalidObjectId";
            NCMBUser.CurrentUser._currentOperations.Clear();

            NCMBUser user = NCMBUser.CurrentUser;
            user.FetchAsync((NCMBException ex) =>
            {
                Assert.NotNull(ex);
                Assert.AreEqual("E404001", ex.ErrorCode);
                Assert.AreEqual("No data available.", ex.ErrorMessage);
                NCMBTestSettings.CallbackFlag = true;
            });
        });

        yield return(NCMBTestSettings.AwaitAsync());

        // 登録成功の確認
        Assert.True(NCMBTestSettings.CallbackFlag);
    }
Exemplo n.º 6
0
    public IEnumerator LoginLogoutFetchUser()
    {
        // テストデータ作成
        NCMBUser.LogInAsync("tarou", "tarou", (e1) =>
        {
            Assert.Null(e1);
            NCMBTestSettings.CallbackFlag = true;
            NCMBUser.LogOutAsync();
            NCMBUser.LogInAsync("tarou", "tarou", (e2) =>
            {
                Assert.Null(e2);
                NCMBUser user = new NCMBUser();
                user.ObjectId = "anotherObjectId";
                user.FetchAsync((NCMBException e3) =>
                {
                    Assert.Null(e3);
                    NCMBTestSettings.CallbackFlag = true;
                });
            });
        });

        yield return(NCMBTestSettings.AwaitAsync());

        Assert.True(NCMBTestSettings.CallbackFlag);
        Assert.AreEqual("dummySessionToken", NCMBUser._getCurrentSessionToken());
        Assert.AreEqual("tarou", NCMBUser.CurrentUser.UserName);
    }
Exemplo n.º 7
0
        /// <summary>
        /// 非同期処理でオブジェクトの取得を行います。
        /// </summary>
        public static Task <NCMBUser> FetchTaskAsync(this NCMBUser user)
        {
            var tcs = new TaskCompletionSource <NCMBUser>();

            user.FetchAsync(error =>
            {
                if (error != null)
                {
                    tcs.SetException(error);
                }
                else
                {
                    tcs.SetResult(user);
                }
            });
            return(tcs.Task);
        }
Exemplo n.º 8
0
    public IEnumerator FetchAsyncUserDataNotAvailable()
    {
        // テストデータ作成
        NCMBUser user = new NCMBUser();

        user.ObjectId = "invalidObjectId";
        user.FetchAsync((NCMBException ex) =>
        {
            Assert.NotNull(ex);
            Assert.AreEqual("E404001", ex.ErrorCode);
            Assert.AreEqual("No data available.", ex.ErrorMessage);
            NCMBTestSettings.CallbackFlag = true;
        });

        yield return(NCMBTestSettings.AwaitAsync());

        // 登録成功の確認
        Assert.True(NCMBTestSettings.CallbackFlag);
    }
Exemplo n.º 9
0
    public IEnumerator LogInWithAuthDataAsyncTwitterThenFetchOtherUser()
    {
        // テストデータ作成
        NCMBUser user = new NCMBUser();

        user.AuthData = twitterParams.param;

        // authData登録
        user.LogInWithAuthDataAsync((NCMBException e) => {
            Assert.Null(e);

            user          = new NCMBUser();
            user.ObjectId = "anotherObjectId";
            user.FetchAsync((NCMBException e1) => {
                Assert.Null(e1);
                Assert.AreEqual("anotherObjectId", user.ObjectId);
                NCMBTestSettings.CallbackFlag = true;
            });
        });
        yield return(NCMBTestSettings.AwaitAsync());

        user = NCMBUser.CurrentUser;
        Assert.AreEqual("dummyObjectId", user.ObjectId);

        // twitterパラメータ確認
        Dictionary <string, object> authData = user.GetAuthDataForProvider("twitter");

        Assert.AreEqual("twitterDummyId", authData ["id"]);
        Assert.AreEqual("twitterDummyScreenName", authData ["screen_name"]);
        Assert.AreEqual("twitterDummyConsumerKey", authData ["oauth_consumer_key"]);
        Assert.AreEqual("twitterDummyConsumerSecret", authData ["consumer_secret"]);
        Assert.AreEqual("twitterDummyAuthToken", authData ["oauth_token"]);
        Assert.AreEqual("twitterDummyAuthSecret", authData ["oauth_token_secret"]);

        // 登録成功の確認
        Assert.NotNull(NCMBUser._getCurrentSessionToken());
        Assert.True(user.IsLinkWith("twitter"));
        Assert.True(NCMBTestSettings.CallbackFlag);
    }
Exemplo n.º 10
0
    private void LoginCallback(ILoginResult result)
    {
        if (FB.IsLoggedIn)
        {
            // facebook ログインの情報を使って NCMB にログインする
            var aToken = Facebook.Unity.AccessToken.CurrentAccessToken;
            NCMBFacebookParameters parameters = new NCMBFacebookParameters(aToken.UserId, aToken.TokenString, aToken.ExpirationTime);
            NCMBUser user = new NCMBUser();
            user.AuthData = parameters.param;

            user.LogInWithAuthDataAsync((NCMBException e) =>
            {
                if (e != null)
                {
                    Debug.LogError("Failed to login: "******"Failed to fetch: " + ex.ErrorMessage);
                        }
                        else
                        {
                            if (string.IsNullOrEmpty(user.Email))
                            {
                                Dictionary <string, string> formData = new Dictionary <string, string>()
                                {
                                };
                                FB.API("/me?fields=id,email", HttpMethod.GET, (IGraphResult r) =>
                                {
                                    if (r.Error != null)
                                    {
                                        Debug.Log(r.Error);
                                    }
                                    else
                                    {
                                        Debug.Log(r.ResultDictionary.ToJson());
                                        string email = r.ResultDictionary["email"].ToString();
                                        user.Email   = email;
                                        user.SaveAsync((NCMBException exc) =>
                                        {
                                            if (exc != null)
                                            {
                                                Debug.LogError("Failed to save: " + ex.ErrorMessage);
                                            }
                                            else
                                            {
                                                Debug.Log("Saved email data successfully.");
                                            }
                                        });
                                    }
                                }
                                       , formData);
                            }
                        }
                    });
                }
            });
        }
        else
        {
            Debug.Log("User cancelled login");
        }
    }