Bomb云备忘

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

IEnumerator FindQuery(string name,BmobGameObject mydata)//查询函数
    {
        BmobQuery query = new BmobQuery();
        List list = null;//存储查找出来的东西
        query.WhereEqualTo("playerName", name);//查找于名字相等的对象
        completeLoad = 0;
        Bmob.Find(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));
            
            
        }
    }


你可能感兴趣的:(Unity学习日志)