免费无限制的公有云服务Bmob之二 创建表添加行

创建表添加行

using UnityEngine;
using System.Collections;
using cn.bmob.io;

public class MyGameObject : BmobTable
{
    public const string TABLENAME = "MyGameTable";

    public string playerName { get; set; }
    public BmobInt score { 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("socre", this.score);
        output.Put("playerName", this.playerName);
    }
}

  

using UnityEngine;
using System.Collections;
using cn.bmob.api;
using cn.bmob.tools;

public class BombTest : MonoBehaviour
{
    private BmobUnity Bmob;
    // Use this for initialization
    void Start()
    {
        BmobDebug.Register(print);
        Bmob = gameObject.GetComponent<BmobUnity>();
    }


    // Update is called once per frame
    void Update()
    {

    }

    void OnGUI()
    {
        if (GUILayout.Button("Creat"))
        {
            Creat();
        }
    }

    void Creat()
    {
        MyGameObject mg = new MyGameObject();
        mg.score = 100;
        mg.playerName = "testBmob";

        Bmob.Create(MyGameObject.TABLENAME, mg, (resp, exception) =>
        {
            if (exception != null)
            {
                Debug.Log("保存失败,原因: " + exception.Message);
            }
            else
            {
                Debug.Log("保存成功" + resp.createdAt);
            }
        });
    }
}

免费无限制的公有云服务Bmob之二 创建表添加行_第1张图片


免费无限制的公有云服务Bmob之二 创建表添加行_第2张图片

你可能感兴趣的:(免费无限制的公有云服务Bmob之二 创建表添加行)