Bomb云备忘

在看文档的过程中,最重要的一点是查找不能使用直接Update(),这个函数的参数是直接使用主键来修改,而这个主键我们现在并不知道。我们应该使用Find()来通过name来查找。

IEnumerator FindQuery(string name,BmobGameObject mydata)//查询函数
    {
        BmobQuery query = new BmobQuery();
        List<BmobGameObject> list = null;//存储查找出来的东西
        query.WhereEqualTo("playerName", name);//查找于名字相等的对象
        completeLoad = 0;
        Bmob.Find<BmobGameObject>(TABLENAME, query, (resp, exception) =>
        {
            if (exception != null)
            {
                print("查询失败, 失败原因为: " + exception.Message);
                thisTemp = null;
                completeLoad = -1;
                return;
            }

            list = resp.results;
            foreach (var game in list)
            {
                print("获取的对象为: " + game.ToString());
                thisTemp = game;
                completeLoad = 1;
            }
        });
        while (completeLoad == 0)
        {
            yield return new WaitForSeconds(0.5f);
        }
        if (thisTemp == null)
        {
            Debug.Log("this temp is null!");
            Bmob.Create(TABLENAME, mydata, (resp, exception) =>
            {
                if (exception != null)
                {
                    print("保存失败, 失败原因为: " + exception.Message);
                    return;
                }

                print("保存成功, @" + resp.createdAt);

            });
        }
        else
        {
            Debug.Log("this temp is Find!");
            mydata.objectId = thisTemp.objectId;
            Bmob.Update(TABLENAME, thisTemp.objectId, mydata, (resp, exception) =>
            {
                if (exception != null)
                {
                    print("保存失败, 失败原因为: " + exception.Message);
                    return;
                }

                print("保存成功, @" + resp.updatedAt);
            });
        }
    }

    public void UpLoadAll()
    {
        if (PlayerPrefs.GetString("_NAME") != null)
        {
            var data = new BmobGameObject();
            data.score = PlayerPrefs.GetInt("_SCORE");
            data.playerName = PlayerPrefs.GetString("_NAME");
            data.cheatMode = false;
            StartCoroutine(FindQuery(data.playerName,data));
            
            
        }
    }


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值