Bmob云服务端的学习

网友投稿 283 2022-10-17

Bmob云服务端的学习

首先我先说下什么叫Bmob  ,我理解为他可以是移动云服务端加数据库。开发小游戏用这个很方便。可以实现用户的登入注册,聊天,计分。非常好用的一个东西

这里是他的官网,他是免费的 ;

记住这个必须绑定

然后我们在这个物体身上加入一个脚本 Bmob Helllo

代码如下:

using UnityEngine;using System.Collections;using cn.bmob.api;public class BmobHelllo : MonoBehaviour{    private BmobUnity Bmob;    void Awake ()    {        Bmob = this.GetComponent ();    }    void Update ()    {        if (Input.GetKeyDown (KeyCode.A)) {            Add();        }    }    //用来添加一条数据    void Add ()    {        //创建数据对象        var data = new BmobScore ();        //设置值            int score = Random.Range (0, 100);        data.score = score;        data.playerName="huangqiaoping";            //添加一行数据        Bmob.Create ("Score", data, (resp, exception) => {            if (exception != null) {                print ("保存失败, 失败原因为: " + exception.Message);                return;            }            print ("保存成功, @" + resp.createdAt);        });                  //添加一个名字    }}

然后我们创建一个脚本BmobScore

代码如下:

using UnityEngine;using System.Collections;using cn.bmob.io;public class BmobScore : BmobTable{           //score、playerName、cheatMode是后台数据表对应的字段名称    public BmobInt score { get; set; }    public string playerName{ get; set; }    //读字段值    public override void readFields (BmobInput input)    {        base.readFields (input);        this.score = input.getInt ("score");        this.playerName=input.getString("playerName");    }    //写字段值    public override void write (BmobOutput output, bool all)    {        base.write (output, all);        output.Put ("score", this.score);        output.Put("playerName",this.playerName);     } }

记住这里我们需要继承下BmobTable 要继承这个类,我们需要把他的库拿过来,using cn.bmob.io;

然后我们回到我们的Bmob里面看下这个数据有没有生成

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:闹乌龙!京东云辟谣:停止云服务?根本没那回事儿
下一篇:spring注解 @PropertySource配置数据源全流程
相关文章

 发表评论

暂时没有评论,来抢沙发吧~