Beispiel #1
0
        public IEnumerator FetchCoroutine(string tableName, string objectId, Action <FetchDataResult> communicationCallback)
        {
            bool            isConnecting = true;
            FetchDataResult fr           = new FetchDataResult();

            NCMBObject ncmbObject = new NCMBObject(tableName);

            ncmbObject.ObjectId = objectId;
            ncmbObject.FetchAsync((NCMBException e) =>
            {
                isConnecting = false;

                if (e != null)
                {
                    fr.IsSuccess   = false;
                    fr.ErroMessage = e.ErrorMessage;
                    fr.ErrorCode   = e.ErrorCode;
                }
                else
                {
                    fr.IsSuccess = true;
                    fr.Data      = MapDictFromNCMBObject(ncmbObject);
                }
            });

            while (isConnecting)
            {
                yield return(null);
            }

            communicationCallback(fr);
        }
Beispiel #2
0
    public IEnumerator FetchAsyncAuthenticationError()
    {
        // テストデータ作成
        NCMBUser.LogInAsync("tarou", "tarou", (e) => {
            Assert.Null(e);

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

            NCMBObject testObject = new NCMBObject("testclass");
            testObject.ObjectId   = "testclassDummyObjectId";

            testObject.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);
    }
Beispiel #3
0
 public void UpdateObject()
 {
     if (lastedObjectID != null)
     {
         NCMBObject obj2 = new NCMBObject("TestClass");
         obj2.ObjectId = lastedObjectID;
         obj2.FetchAsync((NCMBException e) => {
             if (e != null)
             {
                 //エラー処理
                 Debug.LogError(e);
             }
             else
             {
                 obj2["message"] = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                 obj2.SaveAsync((NCMBException e2) => {
                     if (e2 != null)
                     {
                         //エラー処理
                         Debug.LogError(e2);
                     }
                     else
                     {
                         //成功時の処理
                         lastedObjectID = obj2.ObjectId;
                         Debug.Log("Update object success " + lastedObjectID);
                     }
                 });
             }
         });
     }
 }
        /// <summary>
        /// 非同期処理でオブジェクトの取得を行います。
        /// </summary>
        /// <returns>取得したオブジェクト</returns>
        public static IObservable <NCMBObject> FetchAsyncAsStream(this NCMBObject origin)
        {
            return(Observable.Create <NCMBObject>(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;
                    }
                });
            }));
        }
Beispiel #5
0
    public void OnStartButtonClicked()
    {
        state = State.TOSTANDBY;
        animator.Play(ttl2StbHash);

        // プレイカウント加算
        playCount++;

#if OJU_ATSUMARU
        // イベントトリガー
        am.OnEventRaised("Start");
#else
        // ObjectIdをもとにデータ取得を行う
        NCMBObject obj = new NCMBObject("Count");
        obj.ObjectId = startCountObjId;
        obj.FetchAsync((NCMBException e) =>
        {
            if (e != null)
            {
                // 取得失敗時の処理
            }
            else
            {
                // 取得成功時の処理
                // スタートカウント加算
                obj.Increment("count");
                obj.SaveAsync();
            }
        });
#endif
    }
Beispiel #6
0
    public void OnQuitButtonClicked()
    {
        switch (state)
        {
        case State.SCORE:
            OnRankButtonClicked();
            animator.Play(rankHash);
            break;

        default:
            animator.Play(quitHash);
            break;
        }

#if OJU_ATSUMARU
        // プレイカウント取得
        //am.GetScoreboardData(playCountBoardId, (data, isError2) =>
        //{
        //    if (isError2)
        //    {
        //        // 取得失敗時の処理
        //    }
        //    else
        //    {
        //        // 取得成功時の処理
        //        // プレイカウント取得
        //        if (data.myBestRecor.Available)
        //        {
        //            long count = playCount + data.myBestRecor.score;
        //            // プレイカウントを加算
        //            am.SendScore(playCountBoardId, count);
        //        }
        //        else
        //        {
        //            // プレイカウントを登録
        //            am.SendScore(playCountBoardId, playCount);
        //        }
        //    }
        //});
#else
        // ObjectIdをもとにデータ取得を行う
        NCMBObject obj = new NCMBObject("Count");
        obj.ObjectId = playCountObjId;
        obj.FetchAsync((NCMBException e) =>
        {
            if (e != null)
            {
                // 取得失敗時の処理
            }
            else
            {
                // 取得成功時の処理
                // プレイカウント加算
                obj.Increment("count", playCount);
                obj.SaveAsync();
            }
        });
#endif
    }
Beispiel #7
0
    void Update()
    {
        if (Input.GetMouseButtonDown(0))
        {
            A = Input.mousePosition;
        }
        if (Input.GetMouseButtonUp(0))
        {
            B = Input.mousePosition;
            if (A == B)
            {
                SelectNode = null;

                Ray          ray   = Camera.main.ScreenPointToRay(Input.mousePosition);
                RaycastHit2D hit2d = Physics2D.Raycast((Vector2)ray.origin, (Vector2)ray.direction);

                if (hit2d)
                {
                    SelectNode = hit2d.transform.gameObject;
                    NodeMaster NodeScript = SelectNode.GetComponent <NodeMaster>();
                    Titile = NodeScript.pub_Title;
                    ID     = NodeScript.pub_ID;
                    int Count = NodeScript.pub_Count;
                    Debug.Log(Count);

                    NCMBObject data = new NCMBObject("MusicData");
                    data.ObjectId = ID;
                    // Debug.Log(data.ObjectId);
                    data.FetchAsync((NCMBException e) => {
                        if (e != null)
                        {
                            Debug.Log("Error");
                        }
                        else
                        {
                            // Debug.Log(data[Titile]);
                            data["PlayCount"] = Count + 1;
                            data.SaveAsync();
                        }
                    });

                    // Debug.Log(NodeScript.pub_Title);
                    SceneManager.LoadScene("PlayMusic");
                }
            }
        }
    }
Beispiel #8
0
        //ID発行
        void CreateUserID()
        {
            //検索条件を0でない値にセット
            NCQ_server.WhereNotEqualTo("LastUserId", 0);
            //検索し、リスト化して処理実行
            NCQ_server.FindAsync((List <NCMBObject> objList, NCMBException e) => {
                if (e != null)
                {
                    //検索失敗時の処理
                }
                else
                {
                    //検索成功時、見つかったObjを変数として保持
                    foreach (NCMBObject obj in objList)
                    {
                        NCMB_server          = obj;
                        NCMB_server.ObjectId = obj.ObjectId;

                        NCMB_server.FetchAsync((NCMBException f) => {
                            if (f == null)
                            {
                                //成功時の処理
                                //自身をユーザーとして登録
                                num_id  = System.Convert.ToInt32(NCMB_server["LastUserId"]);
                                num_id += 1;

                                NCMB_["UserId"]           = num_id;
                                NCMB_server["LastUserId"] = num_id;
                                NCMB_["ClickCount"]       = 0;

                                NCMB_.SaveAsync();
                                NCMB_server.SaveAsync();

                                //ローカルにユーザーIdを保存
                                PlayerPrefs.SetInt("UserId", num_id);
                                PlayerPrefs.Save();

                                flg_accept = true;
                            }
                        });
                    }
                }
            });
        }
Beispiel #9
0
        /// <summary>
        /// IDを発行する
        /// </summary>
        private void CreateUserID()
        {
            //検索条件を0でない値にセット
            m_NCQ_server.WhereNotEqualTo("LastUserId", 0);
            //検索し、リスト化して処理実行
            m_NCQ_server.FindAsync((List <NCMBObject> objList, NCMBException e) => {
                if (e != null)
                {
                    //再接続用モーダルを表示
                    UIManager.Instance.PopupNetworkErrorModal(() => { this.Start(); });
                    //検索失敗時の処理
                }
                else
                {
                    //検索成功時、見つかったObjを変数として保持
                    m_NCMB_server          = objList[0];
                    m_NCMB_server.ObjectId = objList[0].ObjectId;

                    m_NCMB_server.FetchAsync((NCMBException f) => {
                        if (f == null)
                        {
                            //成功時の処理
                            //自身をユーザーとして登録
                            CreateDataToServer();
                            //ローカルにユーザーIdを保存
                            CreateDataToLocal();
                            m_flg_accept = true;

                            Debug.Log("アカウントを作成しました : UserID = " + AppManager.Instance.user.m_id);

                            //取得したデータはDictionary型で保持
                            AppManager.Instance.user.m_temp.m_dic_.Add(m_NCMB_["data_Stage1"] as Dictionary <string, object>);
                            AppManager.Instance.user.m_temp.m_dic_.Add(m_NCMB_["data_Stage2"] as Dictionary <string, object>);
                        }
                        else if (f != null)
                        {
                            //再接続用モーダルを表示
                            UIManager.Instance.PopupNetworkErrorModal(() => { this.Start(); });
                        }
                    });
                }
            });
        }
Beispiel #10
0
    public IEnumerator FetchAsyncDataNotAvailable()
    {
        // テストデータ作成
        NCMBObject testObject = new NCMBObject("testclass");

        testObject.ObjectId = "testclassInvalidObjectId";

        testObject.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);
    }
    public void FetchObject(Action <NCMBObject> act)
    {
        if (!_created)
        {
            return;
        }
        var obj = new NCMBObject("NCMB_RTC");

        obj.ObjectId = _objectID;
        obj.FetchAsync((NCMBException e) => {
            if (e != null)
            {
            }
            else
            {
                var json         = GetJson_connectState(obj);
                _serverNCMBState = JsonConverter.FromJson <NCMBStateData>(json).myNCMBstate;
                act?.Invoke(obj);
            }
        });
    }
Beispiel #12
0
 public void GetObject()
 {
     if (lastedObjectID != null)
     {
         NCMBObject obj2 = new NCMBObject("TestClass");
         obj2.ObjectId = lastedObjectID;
         obj2.FetchAsync((NCMBException e) =>
         {
             if (e != null)
             {
                 //エラー処理
                 Debug.LogError(e);
             }
             else
             {
                 //成功時の処理
                 Debug.Log("Get object success " + lastedObjectID);
             }
         });
     }
 }
Beispiel #13
0
    public IEnumerator FetchObjectAfterLogin()
    {
        // テストデータ作成
        NCMBUser.LogInAsync("tarou", "tarou", (e) => {
            Assert.Null(e);
            NCMBObject obj = new NCMBObject("TestClass");
            obj.ObjectId   = "testclassDummyObjectId";
            obj.FetchAsync((NCMBException ex) => {
                Assert.Null(ex);

                NCMBTestSettings.CallbackFlag = true;
            });
        });

        yield return(NCMBTestSettings.AwaitAsync());

        // 登録成功の確認
        Assert.True(NCMBTestSettings.CallbackFlag);
        Assert.AreEqual("tarou", NCMBUser.CurrentUser.UserName);
        Assert.AreEqual("dummySessionToken", NCMBUser._getCurrentSessionToken());
        Assert.AreEqual("*****@*****.**", NCMBUser.CurrentUser.Email);
    }
Beispiel #14
0
    void Read()
    {
        Debug.Log("read");
        NCMBObject obj = new NCMBObject("HighScore");

        obj.ObjectId = "CJ3FoEZuSPAZasL4";
        obj.FetchAsync((NCMBException e) => {
            if (e != null)
            {
                //エラー処理

                Debug.Log("失敗");
            }
            else
            {
                //成功時の処理
                Debug.Log("成功");
                Debug.Log(obj ["name"]);
                Debug.Log(obj ["score"]);
            }
        });
    }
    void Awake()
    {
        GoDic.Add("floor", floor);

        NCMBQuery <NCMBObject> query = new NCMBQuery <NCMBObject>("Stage");

        query.OrderByDescending("createDate");
        query.Limit = 1;
        query.FindAsync((List <NCMBObject> objList, NCMBException err) =>
        {
            if (err == null)
            {
                objectId = objList[0].ObjectId;
                Debug.Log(objectId);
                NCMBObject obj = new NCMBObject("Stage");
                obj.ObjectId   = objectId;
                obj.FetchAsync((NCMBException e) => {
                    if (e != null)
                    {
                        //エラー処理
                        Debug.Log("errrrrrrrrr(create stage)");
                    }
                    else
                    {
                        //成功時の処理
                        Debug.Log("success(create stage)");
                        InstantiateObjects((ArrayList)obj["objects"]);
                    }
                });
            }
            else
            {
                Debug.Log("ERROR!ネットワーク接続に問題が発生しました。");
            }
        });
    }