Exemplo n.º 1
0
 public void TestFetchLimitASync()
 {
     Task.Run(async() =>
     {
         for (var i = 0; i < 5; i++)
         {
             var item = new NCMBObject("QueryTest");
             item.Set("message", "Test message");
             item.Set("number", 500 + i);
             await item.Save();
         }
         var query = new NCMBQuery("QueryTest");
         query.EqualTo("message", "Test message");
         var results = await query.FetchAll();
         Assert.AreEqual(results.Length, 5);
         query = new NCMBQuery("QueryTest");
         query.EqualTo("message", "Test message").Limit(2);
         results = await query.FetchAll();
         Assert.AreEqual(results.Length, 2);
         query   = new NCMBQuery("QueryTest");
         results = await query.FetchAll();
         foreach (var obj in results)
         {
             await obj.Delete();
         }
     }).GetAwaiter().GetResult();
 }
Exemplo n.º 2
0
        public void TestFetchPointerASync()
        {
            Task.Run(async() =>
            {
                var item1 = new NCMBObject("QueryTest");
                item1.Set("message", "Test message");
                item1.Set("number", 500);
                await item1.Save();

                var item2 = new NCMBObject("QueryTest");
                item2.Set("message", "Test message");
                item2.Set("number", 500);
                item2.Set("obj", item1);
                await item2.Save();

                var query = new NCMBQuery("QueryTest");
                query
                .EqualTo("objectId", item2.Get("objectId"))
                .Include("obj");
                var obj = await query.Fetch();
                Assert.AreEqual(obj.Get("objectId"), item2.Get("objectId"));
                Assert.AreEqual(((NCMBObject)obj.Get("obj")).Get("objectId"), item1.Get("objectId"));

                await obj.Delete();
                await item1.Delete();
            }).GetAwaiter().GetResult();
        }
Exemplo n.º 3
0
        public void TestFetchWithCount()
        {
            Task.Run(async() =>
            {
                for (var i = 0; i < 5; i++)
                {
                    var item = new NCMBObject("QueryTest");
                    item.Set("message", "Test message");
                    item.Set("number", i);
                    await item.Save();
                }

                var query = new NCMBQuery("QueryTest");
                query.GreaterThan("number", 3);
                var items = await query.Count().FetchAll();
                Assert.AreEqual(1, query.GetCount());
                query = new NCMBQuery("QueryTest");
                query.GreaterThanOrEqualTo("number", 3);
                items = await query.Count().FetchAll();
                Assert.AreEqual(2, query.GetCount());

                query = new NCMBQuery("QueryTest");
                items = await query.FetchAll();
                foreach (var item in items)
                {
                    await item.Delete();
                }
            }).GetAwaiter().GetResult();
        }
Exemplo n.º 4
0
    private void OnEnable()
    {
        //スコアをRapireから持ってくる。
        score = Rapire.Getscore();

        NCMBObject scoreClass = new NCMBObject("Score");

        scoreClass["score"] = score;
        scoreClass.Save();
    }
Exemplo n.º 5
0
 public void TestSaveAndDeleteASync()
 {
     Task.Run(async() =>
     {
         var message = "Hello, world";
         var item    = new NCMBObject("DataStoreTest");
         item.Set("message", message);
         await item.Save();
         Assert.NotNull(item.Get("objectId"));
         Assert.AreEqual(item.Get("message").ToString(), message);
         await item.Delete();
     }).GetAwaiter().GetResult();
 }
Exemplo n.º 6
0
 public void TestSaveGeoPoint()
 {
     Task.Run(async() =>
     {
         var latitude  = 35.6585805;
         var longitude = 139.7454329;
         var geo       = new NCMBGeoPoint(latitude, longitude);
         var item      = new NCMBObject("Item");
         item.Set("geo", geo);
         await item.Save();
         Assert.NotNull(item.Get("objectId"));
         await item.Delete();
     }).GetAwaiter().GetResult();
 }
Exemplo n.º 7
0
 public void TestSaveGetBoolean()
 {
     Task.Run(async() =>
     {
         var message = "Hello, world";
         var item    = new NCMBObject("DataStoreTest");
         item.Set("message", message);
         item.Set("bol1", true);
         item.Set("bol2", false);
         await item.Save();
         Assert.NotNull(item.Get("objectId"));
         await item.Fetch();
         Assert.IsTrue(item.GetBoolean("bol1"));
         Assert.IsTrue(!item.GetBoolean("bol2"));
         await item.Delete();
     }).GetAwaiter().GetResult();
 }
    void SaveLikeData(string user, string doodle)
    {
        NCMBObject obj = new NCMBObject("LikeRecord");

        obj.Add("doodle", doodle);
        obj.Add("user", user);
        obj.Save((NCMBException e) => {
            if (e != null)
            {
                Debug.Log("save like data error");
            }
            else
            {
                //成功時の処理
            }
        });
    }
Exemplo n.º 9
0
    void saveImageData(string filename)
    {
        NCMBObject obj = new NCMBObject("DoodleRecord");

        obj.Add("username", Configuration.username);
        obj.Add("filename", filename);
        obj.Add("date", DateTime.Now.Date);
        obj.Add("theme", Configuration.theme);
        obj.Add("likes", 0);
        if (Configuration.status == Status.newDoodle)
        {
            obj.Add("type", "doodle");
        }
        else if (Configuration.status == Status.newTheme)
        {
            obj.Add("type", "theme");
        }
        obj.Save((NCMBException e) => {
            if (e != null)
            {
                Debug.Log("save data error");
                showError(e);
            }
            else
            {
                //成功時の処理
                //TODO
                if (Configuration.status == Status.newTheme)
                {
#if UNITY_2019_3_OR_NEWER
                    SceneManager.LoadScene("themes");
#else
                    Application.LoadLevel("themes");
#endif
                }
                else if (Configuration.status == Status.newDoodle)
                {
#if UNITY_2019_3_OR_NEWER
                    SceneManager.LoadScene("doodles");
#else
                    Application.LoadLevel("doodles");
#endif
                }
            }
        });
    }
Exemplo n.º 10
0
 public void TestSaveAndDeleteWithAclSync()
 {
     Task.Run(async() =>
     {
         var message = "Hello, world";
         var item    = new NCMBObject("DataStoreTest");
         item.Set("message", message);
         var acl = new NCMBAcl();
         acl.SetPublicReadAccess(true);
         acl.SetPublicWriteAccess(false);
         acl.SetRoleReadAccess("admin", true);
         acl.SetRoleWriteAccess("admin", true);
         item.SetAcl(acl);
         await item.Save();
         Assert.NotNull(item.Get("objectId"));
         Assert.AreEqual(item.Get("message").ToString(), message);
     }).GetAwaiter().GetResult();
 }
Exemplo n.º 11
0
        public void TestFetchSelect()
        {
            Task.Run(async() =>
            {
                for (var i = 0; i < 5; i++)
                {
                    var item = new NCMBObject("Test");
                    item.Set("message", "Test message");
                    item.Set("number", i);
                    await item.Save();

                    var item2 = new NCMBObject("Test2");
                    item2.Set("message", "Test message");
                    item2.Set("num", i);
                    await item2.Save();
                }

                var q1 = new NCMBQuery("Test");
                var q2 = new NCMBQuery("Test2");

                q2.InString("num", new int[] { 1, 4 });

                var t     = q2.FetchAll();
                var items = await q1.Select("number", "num", q2).FetchAll();
                foreach (var item in items)
                {
                    var num = item.GetInt("number");
                    Assert.IsTrue(num == 4 || num == 1);
                }

                var query = new NCMBQuery("Test");
                items     = await query.FetchAll();
                foreach (var item in items)
                {
                    await item.Delete();
                }
                query = new NCMBQuery("Test2");
                items = await query.FetchAll();
                foreach (var item in items)
                {
                    await item.Delete();
                }
            }).GetAwaiter().GetResult();
        }
Exemplo n.º 12
0
    /// <summary>
    /// PlayerNameの変更
    /// </summary>
    /// <param name="playerNameAfterChange"></param>
    /// <param name="objectId">PlayerPrefs("AccountToken")</param>
    /// <param name="onUpdate"></param>
    /// <returns></returns>
    public IEnumerator UpdatePlayerName(string playerNameAfterChange, string objectId, Action onUpdate)
    {
        NCMBQuery <NCMBObject> query  = new NCMBQuery <NCMBObject>("User");
        NCMBObject             result = null;
        NCMBException          error  = null;

        query.GetAsync(objectId, (NCMBObject _result, NCMBException _error) =>
        {
            result = _result;
            error  = _error;
        });

        //resultもしくはerrorが入るまで待機
        yield return(new WaitWhile(() => result == null && error == null));

        //後続処理
        if (error == null)
        {
            result["PlayerName"] = playerNameAfterChange;
            result.Save(); //非同期通信にしてもいいかも
            onUpdate();
        }
    }
Exemplo n.º 13
0
        public void TestFetchOr()
        {
            Task.Run(async() =>
            {
                for (var i = 0; i < 5; i++)
                {
                    var item = new NCMBObject("QueryTest");
                    item.Set("message", "Test message");
                    item.Set("number", i);
                    await item.Save();
                }

                var q1 = new NCMBQuery("QueryTest");
                var q2 = new NCMBQuery("QueryTest");

                q1.EqualTo("number", 0);
                q2.EqualTo("number", 1);
                var query = new NCMBQuery("QueryTest");
                query.Or(new NCMBQuery[2] {
                    q1, q2
                });
                var items = await query.FetchAll();

                Assert.AreEqual(2, items.Length);
                var num0 = items[0].Get("number") as JValue;
                var num1 = items[1].Get("number") as JValue;

                Assert.AreEqual(0, num0.ToObject <int>());
                Assert.AreEqual(1, num1.ToObject <int>());
                query = new NCMBQuery("QueryTest");
                items = await query.FetchAll();
                foreach (var item in items)
                {
                    await item.Delete();
                }
            }).GetAwaiter().GetResult();
        }
Exemplo n.º 14
0
    /// <summary>
    /// 一番初めのアカウント登録
    /// </summary>
    /// <param name="registPlayerName">登録するPlayerName</param>
    /// <param name="onRegist">登録成功時。objectIdを引数とした処理</param>
    public IEnumerator RegistAccountFirst(string registPlayerName, Action <string> onRegist)
    {
        NCMBObject obj = new NCMBObject("User");

        obj["PlayerName"]            = registPlayerName;
        obj["HighScore"]             = 0;
        obj["TotalGoalToEnemyCount"] = 0;
        obj["TotalPlayCount"]        = 0;
        obj["TotalScore"]            = 0;
        obj.Save();

        NCMBQuery <NCMBObject> query  = new NCMBQuery <NCMBObject>("User");
        List <NCMBObject>      result = null;
        NCMBException          error  = null;

        query.OrderByDescending("createDate"); //降順
        query.WhereEqualTo("PlayerName", registPlayerName);
        query.Limit = 1;

        query.FindAsync((List <NCMBObject> _result, NCMBException _error) =>
        {
            result = _result;
            error  = _error;
        });

        //resultもしくはerrorが入るまで待機
        yield return(new WaitWhile(() => result == null && error == null));

        if (error == null)
        {
            onRegist(obj.ObjectId.ToString());
        }
        else
        {
            Debug.Log(error);
        }
    }
Exemplo n.º 15
0
        /// <summary>
        /// 疎通テストのプロセス
        /// </summary>
        /// <param name="i_callback">完了コールバック</param>
        /// <returns></returns>
        private IEnumerator CommunicateTestProcess(Action i_callback)
        {
            this.IsRunning = true;

            UnityEngine.Object settingprefab = Resources.Load(PATH_NCMBSETTING_PREFAB);
            GameObject         settingObject = GameObject.Instantiate <GameObject>(settingprefab as GameObject);
            NCMBSettings       settings      = settingObject != null?settingObject.GetComponent <NCMBSettings>() : null;

            if (settings == null)
            {
                yield break;
            }

            // マルチシーンで意図しないシーンにインスタンス化しないように親子付け
            settingObject.transform.SetParent(this.transform);

            // アプリケーションキー、クライアントキー設定確認(空かどうかだけ)
            if (string.IsNullOrEmpty(settings.applicationKey) || string.IsNullOrEmpty(settings.clientKey))
            {
                EditorUtility.DisplayDialog("Error", "NCMBSettingsの設定不備があります。\n講師へ申し出をして下さい。", "OK");
                yield break;
            }

            // 疎通用送信データとしてローカルIPアドレスを取得
            string ipAddress = GetIpAddress();

            if (ipAddress == string.Empty)
            {
                EditorUtility.DisplayDialog("Error", "ローカルIPアドレスの取得に失敗しました。\nネットワークに未接続の可能性があります。", "OK");
                yield break;
            }

            bool isFinshed = false;
            NCMBQuery <NCMBObject> query = new NCMBQuery <NCMBObject>("CommunicateTest");

            query.WhereEqualTo("IP", ipAddress);
            query.FindAsync((List <NCMBObject> i_objectList, NCMBException i_exception) =>
            {
                if (i_exception != null)
                {
                    EditorUtility.DisplayDialog("Error", string.Format("NCMB接続時にエラーが発生しました。\n講師へ申し出をして下さい。\n(エラーメッセージ:{0})", i_exception.Message), "OK");
                    return;
                }

                if (i_objectList.Count > 0)
                {
                    i_objectList[0]["IP"] = ipAddress;
                    i_objectList[0].Save();
                }
                else
                {
                    NCMBObject newObject = new NCMBObject("CommunicateTest");
                    newObject["IP"]      = ipAddress;
                    newObject.Save();
                }

                EditorUtility.DisplayDialog("完了", "疎通テストが正常に完了しました。", "OK");

                isFinshed = true;
            });

            while (isFinshed == false)
            {
                yield return(null);
            }

            if (i_callback != null)
            {
                i_callback();
            }

            this.IsRunning = false;
        }