Exemple #1
0
        public static async void updateCloud(string foodname, string type)
        {
            if (type.Equals("11"))
            {
                AVQuery <AVObject> delete = new AVQuery <AVObject>("Fruit");
                delete = delete.WhereEqualTo("name", foodname);

                await delete.FindAsync().ContinueWith(s =>
                {
                    IEnumerable <AVObject> boys = s.Result;

                    AVObject ob = boys.ElementAt(0);
                    ob.SaveAsync().ContinueWith(t =>
                    {
                        // 保存成功之后,修改一个已经在服务端生效的数据,这里我们修改age
                        // LeanCloud 只会针对指定的属性进行覆盖操作,本例中的name不会被修改
                        ob["state"] = false;
                        ob.SaveAsync();
                    });
                });
            }
            if (type.Equals("22"))
            {
                AVQuery <AVObject> delete = new AVQuery <AVObject>("Vegetable");
                delete = delete.WhereEqualTo("name", foodname);

                await delete.FindAsync().ContinueWith(s =>
                {
                    IEnumerable <AVObject> boys = s.Result;

                    AVObject ob = boys.ElementAt(0);
                    ob.SaveAsync().ContinueWith(t =>
                    {
                        // 保存成功之后,修改一个已经在服务端生效的数据,这里我们修改age
                        // LeanCloud 只会针对指定的属性进行覆盖操作,本例中的name不会被修改
                        ob["state"] = false;
                        ob.SaveAsync();
                    });
                });
            }
            if (type.Equals("33"))
            {
                AVQuery <AVObject> delete = new AVQuery <AVObject>("Food");
                delete = delete.WhereEqualTo("name", foodname);

                await delete.FindAsync().ContinueWith(s =>
                {
                    IEnumerable <AVObject> boys = s.Result;

                    AVObject ob = boys.ElementAt(0);
                    ob.SaveAsync().ContinueWith(t =>
                    {
                        // 保存成功之后,修改一个已经在服务端生效的数据,这里我们修改age
                        // LeanCloud 只会针对指定的属性进行覆盖操作,本例中的name不会被修改
                        ob["state"] = false;
                        ob.SaveAsync();
                    });
                });
            }
        }
        public async void SaveFile(byte[] data, string name)
        {
            AVFile file = new AVFile(name, data, new Dictionary <string, object>()
            {
                { "author", "AVOSCloud" }
            });


            AVObject photo = AVObject.CreateWithoutData("photo", "55acdce0e4b044ac283609af");
            await photo.SaveAsync().ContinueWith(t =>
            {
                // 保存成功之后,修改一个已经在服务端生效的数据,这里我们修改age
                // LeanCloud 只会针对指定的属性进行覆盖操作,本例中的name不会被修改
                photo["ss"] = file;
                photo.SaveAsync();
            });


            /*await photo.SaveAsync().ContinueWith(t =>
             * {
             *  // 保存成功之后,修改一个已经在服务端生效的数据,这里我们修改age
             *  // LeanCloud 只会针对指定的属性进行覆盖操作,本例中的name不会被修改\
             *
             *  photo["ss"] = file;
             *  photo.SaveAsync();
             *
             *  MessageBox.Show("ok");
             * });*/
        }
Exemple #3
0
        private async void Button_Click_2(object sender, RoutedEventArgs e)
        {
            #region 一对多的关系,在保存在服务端之前,所有对象必须已经存在于服务端。
            AVObject weibo = new AVObject("Weibo");
            weibo["content"] = "AVOS Cloud 什么的最萌了!";
            //weibo["user"] = new AVUser() { Username = "******", Password = "******" };
            //王校长的用户名已被别人抢注了,所以要正确关联用户,请开发者自定义个名字。

            AVObject comment1 = new AVObject("Comment");
            comment1["words"] = "第一条,好鸡冻!";

            AVObject comment2 = new AVObject("Comment");
            comment2["words"] = "点赞必回粉!";

            AVObject comment3 = new AVObject("Comment");
            comment3["words"] = "优质新西兰奶粉代购,请加q12345789";

            AVObject comment4 = new AVObject("Comment");
            comment4["words"] = "5元千粉,需要的请联系138XXXX";
            await Task.WhenAll(new Task[] { weibo.SaveAsync(), comment1.SaveAsync(), comment2.SaveAsync(), comment3.SaveAsync(), comment4.SaveAsync() }).ContinueWith(t =>
            {
                AVRelation <AVObject> weiboRelation = weibo.GetRelation <AVObject>("comments");
                weiboRelation.Add(comment1);
                weiboRelation.Add(comment2);
                weiboRelation.Add(comment3);
                weiboRelation.Add(comment4);
                return(weibo.SaveAsync());
            });

            #endregion
        }
        private async void Button_Click_2(object sender, RoutedEventArgs e)
        {
            #region 一对多的关系,在保存在服务端之前,所有对象必须已经存在于服务端。
            AVObject weibo = new AVObject("Weibo");
            weibo["content"] = "AVOS Cloud 什么的最萌了!";
            //weibo["user"] = new AVUser() { Username = "******", Password = "******" };
            //王校长的用户名已被别人抢注了,所以要正确关联用户,请开发者自定义个名字。

            AVObject comment1 = new AVObject("Comment");
            comment1["words"] = "第一条,好鸡冻!";

            AVObject comment2 = new AVObject("Comment");
            comment2["words"] = "点赞必回粉!";

            AVObject comment3 = new AVObject("Comment");
            comment3["words"] = "优质新西兰奶粉代购,请加q12345789";

            AVObject comment4 = new AVObject("Comment");
            comment4["words"] = "5元千粉,需要的请联系138XXXX";
            await Task.WhenAll(new Task[] { weibo.SaveAsync(), comment1.SaveAsync(), comment2.SaveAsync(), comment3.SaveAsync(), comment4.SaveAsync() }).ContinueWith(t =>
            {
                AVRelation<AVObject> weiboRelation = weibo.GetRelation<AVObject>("comments");
                weiboRelation.Add(comment1);
                weiboRelation.Add(comment2);
                weiboRelation.Add(comment3);
                weiboRelation.Add(comment4);
                return weibo.SaveAsync();
            });
            #endregion

        }
Exemple #5
0
        public async void SaveObj()
        {
            //新建一个class结构
            AVObject footballl = new AVObject("Sport");

            Console.WriteLine("footballl:" + footballl);

            //插入数据
            footballl["totalTime"] = 90;
            footballl["name"]      = "Football";
            footballl.Add("grade", "1");

            //保存数据
            var saveTask = footballl.SaveAsync().ContinueWith((t) =>
            {
                //获取数据
                System.Console.WriteLine("ObjectId:" + footballl.ObjectId);
                Console.WriteLine("Id:" + t.Id);
                Console.WriteLine("AsyncState:" + t.AsyncState);
                Console.WriteLine("CreationOptions:" + t.CreationOptions);
                Console.WriteLine("Exception:" + t.Exception);
                Console.WriteLine("IsCompleted:" + t.IsCompleted);

                //更新对象的列值
                footballl["totalTime"] = 100;
                footballl["name"]      = "Basketball";
                //footballl.Add("grade", "1"); //调用失败:不能再添加grade属性
                footballl.SaveAsync();
            });
            await saveTask;
        }
Exemple #6
0
 public async void saveToCloud2(string name, string data)
 {
     AVObject Humidity = AVObject.CreateWithoutData("Humidity", "5575072de4b0f22726a105af");
     await Humidity.SaveAsync().ContinueWith(t =>
     {
         // 保存成功之后,修改一个已经在服务端生效的数据,这里我们修改age
         // LeanCloud 只会针对指定的属性进行覆盖操作,本例中的name不会被修改
         Humidity["humidity"] = data;
         Humidity.SaveAsync();
     });
 }
Exemple #7
0
 /// <summary>
 /// 上云传温湿度
 /// </summary>
 public async void saveToCloud(string name, string data)
 {
     AVObject Temperature = AVObject.CreateWithoutData("Temperature", "5575072de4b0f22726a105b0");
     await Temperature.SaveAsync().ContinueWith(t =>
     {
         // 保存成功之后,修改一个已经在服务端生效的数据,这里我们修改age
         // LeanCloud 只会针对指定的属性进行覆盖操作,本例中的name不会被修改
         Temperature["temperature"] = data;
         Temperature.SaveAsync();
     });
 }
Exemple #8
0
    private void QueryList()
    {
        var data = new AVObject("List");

        data["name"]       = "hello";
        data["Parameters"] = new List <int>(new int[] { 3, 2, 1 });

        data.SaveAsync().ContinueWith(t => {
            if (t.IsFaulted || t.IsCanceled)
            {
                Debug.Log("Failed");
                Debug.Log(t.Exception.Message);
            }
            else
            {
                Debug.Log("Success");
            }
        }).ContinueWith(t => {
            var query = new AVQuery <AVObject>("List").FindAsync().ContinueWith(t2 => {
                foreach (var result in t2.Result)
                {
//					var hello = result.Get<string>("name");
//					Debug.Log(hello);
                    var list = result.Get <IList <int> >("Parameters");
                    Debug.Log(list.ToString());
                }
            });
        });
    }
        public async Task Delete()
        {
            var f  = false;
            var go = new AVObject("Todo");
            await go.SaveAsync();

            var objectId  = go.ObjectId;
            var query     = new AVQuery <AVObject>("Todo").WhereEqualTo("objectId", objectId);
            var liveQuery = await query.SubscribeAsync();

            liveQuery.OnLiveQueryReceived += (sender, e) => {
                Console.WriteLine(e.Scope);
                Assert.AreEqual(e.Scope, "delete");
                f = true;
            };

            await go.DeleteAsync();

            Console.WriteLine("object delete done");

            while (!f)
            {
                await Task.Delay(100);

                f = true;
            }
            Console.WriteLine("Test delete done!");
        }
Exemple #10
0
    void OnTriggerEnter2D(Collider2D other)
    {
        if (other.gameObject.tag == "scoreMaker")
        {
            GameManager.score += 1;
            Destroy(other.gameObject);
        }
        else
        {
            AVAnalytics.StopEvent("OneGame");//本局结束,只要调用一下事件终止方法,SDK会自动计算开始到结束之间的间隔发送到服务端。

            #region 把这次的分数记录到AVOS Cloud的服务端

            AVObject gameScore = new AVObject("GameScore");
            gameScore["score"]      = GameManager.score;
            gameScore["playerName"] = "DemoUser";
            gameScore["deviceID"]   = SystemInfo.deviceUniqueIdentifier;
            gameScore.SaveAsync();

            #endregion

            gameObject.collider2D.isTrigger = false;
            AudioSource.PlayClipAtPoint(hit, Camera.main.transform.position);
            if (GameManager.score > PlayerPrefs.GetInt("highscore"))
            {
                guiManager.medal = true;
            }
            GameManager.gameOver = true;
        }
    }
Exemple #11
0
    void OnGUI()
    {
        if (GUILayout.Button("创建一个士兵"))
        {
            AVUser.LogInAsync("games", "123").ContinueWith(loginTask => {
                Debug.Log("login success!");
                user = (AVUser)loginTask.Result;

                AVUser otherUser = null;
                AVUser.Query.GetAsync("55220263e4b07952a95fbf7a").ContinueWith(t => {
                    otherUser = (AVUser)t.Result;

                    AVObject soldier = new AVObject("Soldier")
                    {
                        { "type", 3 },
                        { "lv", 1 },
                        { "exp", 50 },
                        { "user2", new List <AVUser>()
                          {
                              user,
                              otherUser
                          } }
                    };

                    soldier.SaveAsync().ContinueWith(saveTask =>
                    {
                        Debug.Log("solider created!");
                    });
                });
            });
        }
    }
Exemple #12
0
    public int SlotID;                  // 位置

    public static void DB_CreateBuilding(int slotId, EBuildingType type)
    {
        AVObject obj = new AVObject("Building");

        obj["UserID"] = AVUser.CurrentUser.ObjectId;
        obj["Type"]   = (int)type;
        obj["Level"]  = 1;
        obj["Value"]  = 1;
        obj["SlotID"] = slotId;

        obj.SaveAsync().ContinueWith(t => {
            BuildingData newBuilding = new BuildingData();
            newBuilding.UserID       = AVUser.CurrentUser.ObjectId;
            newBuilding.Type         = type;
            newBuilding.Level        = 1;
            newBuilding.Value        = 1;
            newBuilding.SlotID       = slotId;

            GameManager.Instance.LastCreatedBuilding = newBuilding;
            GameManager.Instance.EventQueue.Queue.Enqueue(new EventItem()
            {
                Type = EEventItemType.BuildCommandOK
            });
        });
    }
Exemple #13
0
        public Task RelationReverseQueryTest()
        {
            var hangzhou = new AVObject("City");

            hangzhou["name"] = "杭州";

            var wenzhou = new AVObject("City");

            wenzhou["name"] = "温州";

            var zhejiang = new AVObject("Province");

            zhejiang.Set("name", "浙江");
            return(AVObject.SaveAllAsync(new AVObject[] { hangzhou, wenzhou }).ContinueWith(t =>
            {
                var relation = zhejiang.GetRelation <AVObject>("includedCities");
                relation.Add(hangzhou);
                relation.Add(wenzhou);

                return zhejiang.SaveAsync();
            }).Unwrap().ContinueWith(s =>
            {
                var reverseQuery = hangzhou.GetRelationRevserseQuery <AVObject>("Province", "includedCities");
                return reverseQuery.FindAsync();
            }).Unwrap().ContinueWith(x =>
            {
                var provinces = x.Result;
                Assert.IsTrue(provinces.Count() == 1);
                return Task.FromResult(0);
            }));
        }
Exemple #14
0
    void OnGUI()
    {
        if (GUILayout.Button("创建一个士兵"))
        {
            AVUser.LogInAsync("games", "123").ContinueWith(loginTask=>{
                Debug.Log("login success!");
                user = (AVUser)loginTask.Result;

                AVUser otherUser = null;
                AVUser.Query.GetAsync("55220263e4b07952a95fbf7a").ContinueWith(t=>{
                    otherUser = (AVUser)t.Result;

                    AVObject soldier = new AVObject("Soldier"){
                        {"type", 3},
                        {"lv", 1},
                        {"exp", 50},
                        {"user2", new List<AVUser>(){
                            user,
                            otherUser
                        }}
                    };

                    soldier.SaveAsync().ContinueWith(saveTask =>
                        {
                            Debug.Log("solider created!");
                        });
                    });
            });
        }
    }
        public async Task Create()
        {
            Init();

            var f         = false;
            var query     = new AVQuery <AVObject>("GameObject").WhereExists("objectId");
            var liveQuery = await query.SubscribeAsync();

            liveQuery.OnLiveQueryReceived += (sender, e) => {
                Console.WriteLine(e.Scope);
                f = true;
            };

            var go = new AVObject("GameObject");
            await go.SaveAsync();

            Console.WriteLine(go.ObjectId);

            while (!f)
            {
                await Task.Delay(100);
            }

            Console.WriteLine("Test create done!");
        }
Exemple #16
0
        public async void lol(string name)    //上传不足物品信息
        {
            AVObject overdue = new AVObject("overdue");

            overdue["name"] = name;
            Task  saveTask = overdue.SaveAsync();
            await saveTask;
        }
    public void SaveObject()
    {
        AVClient.HttpLog(Debug.Log);
        var todo = new AVObject("Todo");

        todo["title"] = "XD";
        todo.SaveAsync();
    }
Exemple #18
0
        public MainPage()
        {
            this.InitializeComponent();

            AVObject leancloud = new AVObject("Company");

            leancloud["name"] = "LeanCloud";
            leancloud.SaveAsync();
        }
 private async void Button_Click_1(object sender, RoutedEventArgs e)
 {
     var gameScore = new AVObject("GameScore")
     {
     { "score", 1338 },
     { "playerName", "Peter Burke" },
     { "cheatMode", false },
     { "skills", new List<string> { "FBI", "Agent Leader" } },
     };
     await gameScore.SaveAsync().ContinueWith(t =>
     {
         // 保存成功之后,修改一个已经在服务端生效的数据,这里我们修改cheatMode和score
         // AVOSCloud只会针对指定的属性进行覆盖操作,本例中的playerName不会被修改
         gameScore["cheatMode"] = true;
         gameScore["score"] = 9999;
         return gameScore.SaveAsync();
     });
 }
        private async void Application_Startup(object sender, StartupEventArgs args)
        {
            //await AVAnalytics.TrackAppOpenedAsync();
            var avObject = new AVObject("TestObject");
            avObject["key"] = "value";
            await avObject.SaveAsync();

            Console.WriteLine(avObject.ObjectId);
        }
    /// <summary>
    /// News the item upload.
    /// </summary>
    /// <param name="itemData">Item data.</param>
    public void NewItemUpload(ToDoListItemData itemData)
    {
        AVObject toDoListItemData = new AVObject("ToDoListItemData");

        toDoListItemData ["Title"]    = itemData.Title;
        toDoListItemData ["Content"]  = itemData.Content;
        toDoListItemData ["Complete"] = itemData.Complete;
        Task saveTask = toDoListItemData.SaveAsync();
    }
 private async void Button_Click(object sender, RoutedEventArgs e)
 {
     AVObject girlType = new AVObject("GirlType");
     girlType["typeName"] = "Hot";
     AVObject beckham = new AVObject("Boy");
     beckham["name"] = "AVOS Cloud User 1";
     beckham["age"] = 38;
     beckham["focusType"] = girlType;//这样使得在AVOS Cloud 的控制台Web上显示的就是:Boy的字段focusType 是一个 指向 GirlType 的Pointer的类型。Pointer 可以理解为一个指向AVObject 指针。
     await beckham.SaveAsync();//保存beckham的时候会自动将girlType也保存到服务器。
 }
Exemple #23
0
	public static void DB_CreateTestData(string input)
	{
		AVObject obj = new AVObject("Test");
		obj["TestA"] = input;
		
		obj.SaveAsync().ContinueWith(t => {
			TestData testObject = new TestData();
			testObject.testA = input;
		});
	}
Exemple #24
0
    void make1()
    {
        AVObject gameScore = new AVObject("GameScore");

        gameScore["score"]      = 1337;
        gameScore["playerName"] = "Neal Caffrey";
        Task saveTask = gameScore.SaveAsync();

        Debug.Log(gameScore);
    }
Exemple #25
0
    /// <summary>
    /// 新建数据
    /// </summary>
    private void UpDataRole()
    {
        AVObject gameScore = new AVObject("GameScore");

        gameScore["score"]      = 1337;
        gameScore["playerName"] = "Neal Caffrey";
        Task saveTask = gameScore.SaveAsync();

        Debug.Log("store data end ....");
    }
Exemple #26
0
 private async void Button_Click_1(object sender, RoutedEventArgs e)
 {
     var gameScore = new AVObject("GameScore")
     {
         { "score", 1338 },
         { "playerName", "Peter Burke" },
         { "cheatMode", false },
         { "skills", new List <string> {
               "FBI", "Agent Leader"
           } },
     };
     await gameScore.SaveAsync().ContinueWith(t =>
     {
         // 保存成功之后,修改一个已经在服务端生效的数据,这里我们修改cheatMode和score
         // AVOSCloud只会针对指定的属性进行覆盖操作,本例中的playerName不会被修改
         gameScore["cheatMode"] = true;
         gameScore["score"]     = 9999;
         return(gameScore.SaveAsync());
     });
 }
Exemple #27
0
        public Task TestSave()
        {
            var avObject = new AVObject("TestObject");

            avObject["key"] = "value";
            return(avObject.SaveAsync().ContinueWith(t =>
            {
                Console.WriteLine(avObject.ObjectId);
                Assert.IsNotNull(avObject.ObjectId);
                return Task.FromResult(0);
            }).Unwrap());
        }
Exemple #28
0
        private async void Button_Click(object sender, RoutedEventArgs e)
        {
            AVObject girlType = new AVObject("GirlType");

            girlType["typeName"] = "Hot";
            AVObject beckham = new AVObject("Boy");

            beckham["name"]      = "AVOS Cloud User 1";
            beckham["age"]       = 38;
            beckham["focusType"] = girlType; //这样使得在AVOS Cloud 的控制台Web上显示的就是:Boy的字段focusType 是一个 指向 GirlType 的Pointer的类型。Pointer 可以理解为一个指向AVObject 指针。
            await beckham.SaveAsync();       //保存beckham的时候会自动将girlType也保存到服务器。
        }
Exemple #29
0
        public static void Main(string[] args)
        {
            AVClient.Initialize("r7WOBCoFgBlpuRoBTIWjb7XI-gzGzoHsz", "PT4FpSvABfO0wKCD4WYA0wdK");

            AVObject football = new AVObject("Sport");

            football["totalTime"] = 90;
            football["name"]      = "Football";
            Task saveTask = football.SaveAsync();

            saveTask.Wait();
        }
Exemple #30
0
        /// <summary>
        /// 删除属性
        /// </summary>
        public async void DeletePropertiesWithId()
        {
            AVObject character = AVObject.CreateWithoutData("Sport", "5b446160fe88c20035fd9dcc");
            await character.FetchAsync().ContinueWith(t =>
            {
                Console.WriteLine("FetchAsync:ID:" + t.Id);
                Console.WriteLine("character:ID:" + character.ObjectId);

                character.Remove("grade");
                character.SaveAsync();
            });
        }
        /// <summary>
        /// 存储数据
        /// </summary>
        /// <param name="table">表</param>
        /// <param name="data">数据</param>
        public static Task StorageData(DataTable table, Dictionary <string, string> data)
        {
            AVObject gameScore = new AVObject(table.ToString());

            foreach (var key in data.Keys)
            {
                gameScore[key] = data[key];
            }
            Task saveTask = gameScore.SaveAsync();

            return(saveTask);
        }
Exemple #32
0
        /// <summary>
        /// 删除
        /// </summary>
        public async void DeleteObjWithId()
        {
            AVObject character = AVObject.CreateWithoutData("Sport", "5b44644aee920a003b2eb726");
            await character.DeleteAsync().ContinueWith(t =>
            {
                Console.WriteLine("Delete:ID:" + t.Id);
                Console.WriteLine("character:ID:" + character.ObjectId);

                character.Remove("grage");
                character.SaveAsync();
            });
        }
Exemple #33
0
    void updateData()
    {
        var gameScore = new AVObject("GameScore")
        {
            { "score", 1338 },
            { "playerName", "Peter Burke" },
            { "cheatMode", false },
            { "skills", new List <string> {
                  "FBI", "Agent Leader"
              } },
        };                                      //创建一个全新的 GameScore 对象

        gameScore.SaveAsync().ContinueWith(t => //第一次调用 SaveAsync 是为了增加这个全新的对象
        {
            // 保存成功之后,修改一个已经在服务端生效的数据,这里我们修改 cheatMode 和 score
            // LeanCloud 只会针对指定的属性进行覆盖操作,本例中的 playerName 不会被修改
            gameScore["cheatMode"] = true;
            gameScore["score"]     = 9999;
            gameScore.SaveAsync();//第二次调用是为了把刚才修改的2个属性发送到服务端生效。
        });
    }
Exemple #34
0
    void OnClickSaveButton()
    {
        var nickname = Namefield.text;

        AVObject gameScore = new AVObject("GameScore");

        gameScore ["score"]      = _score;
        gameScore ["playerName"] = nickname;
        gameScore.SaveAsync().ContinueWith(_ => {
            ShowRankPanel();
        });
        SaveScorePanel.SetActive(false);
    }
 private async void Button_Click_1(object sender, RoutedEventArgs e)
 {
     AVQuery<AVObject> findGirlType = new AVQuery<AVObject>("GirlType").WhereEqualTo("typeName", "Hot");
     await findGirlType.FindAsync().ContinueWith(t => 
     {
         var hot = t.Result.First();//可能有多个标记为Hot的GirType,但是“弱水三千只取一瓢”。
         var myself = new AVObject("Boy");
         myself["name"] = "AVOS Cloud User 2";
         myself["age"] = 18;
         myself["focusType"] = hot;//关联被查询出来的对象。
         return myself.SaveAsync();
     });
 }
Exemple #36
0
 private async void Button_Click_1(object sender, RoutedEventArgs e)
 {
     AVQuery <AVObject> findGirlType = new AVQuery <AVObject>("GirlType").WhereEqualTo("typeName", "Hot");
     await findGirlType.FindAsync().ContinueWith(t =>
     {
         var hot             = t.Result.First();//可能有多个标记为Hot的GirType,但是“弱水三千只取一瓢”。
         var myself          = new AVObject("Boy");
         myself["name"]      = "AVOS Cloud User 2";
         myself["age"]       = 18;
         myself["focusType"] = hot;//关联被查询出来的对象。
         return(myself.SaveAsync());
     });
 }
    //
    //点击保存按钮
    //
    void OnClickSaveButton()
    {
        AVObject gameScore = new AVObject("GameScore");

        gameScore["score"]      = _score;
        gameScore["playerName"] = _nowUsername;
        gameScore.SaveAsync().ContinueWith(_ =>
        {
            ShowRankPanel();
        });

        SaveScorePanel.SetActive(false);
    }
        private async void Button_Click(object sender, RoutedEventArgs e)
        {
            #region 数据的存储是 LeanCloud 提供的最基础的服务,它在客户端只需要如下简单的操作就可以。

            AVObject player = new AVObject("Player");//表的名字为:Player,在AVOS Cloud 网站上控制台里面可以查看表的信息。web:https://cn.avoscloud.com/applist.html#/apps 需要登录。
            //AVOS Cloud 支持最常用的几种数据类型,详细的请查看:https://cn.avoscloud.com/docs/data_security.html#数据
            player["name"] = txb_playerName.Text.Trim();//字符串
            player["age"] = int.Parse(txb_age.Text.Trim());//整型
            player["isAdult"] = int.Parse(txb_age.Text.Trim()) >= 18 ? true : false;//bool 布尔类型
            Task saveTask = player.SaveAsync();//
            await saveTask;//采用.NET 4.5之后推荐的异步保存到服务端。

            #endregion
        }
Exemple #39
0
	public static void DB_CreateVillage()
	{
		AVObject obj = new AVObject("Village");
		obj["UserID"] = AVUser.CurrentUser.ObjectId;
		obj["Defence"] = 10;
		obj["Power"] = 10;
		obj["Trick"] = 0;
		obj["Belief"] = 0;
		obj["BeliefAll"] = 0;
		
		obj.SaveAsync().ContinueWith(t => {
			GameManager.Instance.EventQueue.Queue.Enqueue(new EventItem(){Type = EEventItemType.CreateVillageSuccess});
		});
	}
    void OnGUI()
    {
        GUI.Label (new Rect (270, 50, 200, 80), msg);

        if (GUI.Button (new Rect (50, 50, 200, 80), "添加GameScore"))
        {
            AVObject gameScore =new AVObject("GameScore");
            gameScore["score"] = 1337;
            gameScore["playerName"] = "Neal Caffrey";
            gameScore.SaveAsync().ContinueWith(t=>
                                               {
                if(!t.IsFaulted)
                {
                    msg="保存成功";
                }
            });
        }
    }
	private void Query () {
		var model = new AVObject ("Model1");
		model ["name"] = "TestModel";
		model ["cpucount"] = 3;
		model.SaveAsync().ContinueWith(t=>{
			if (!t.IsFaulted) {
				Debug.Log("Success!");
			}
			else {
				Debug.Log("Error!");
			}

			var query = new AVQuery<AVObject>("Model1");
			return query.GetAsync("551d1952e4b062519520cf96");
		}).Unwrap().ContinueWith(t => {
			var modelGot = t.Result;
			Debug.Log(modelGot.Get<string>("name"));
			Debug.Log(modelGot.Get<int>("cpucount"));
		});
	}
Exemple #42
0
	public int SlotID;			// 位置

	public static void DB_CreateBuilding(int slotId, EBuildingType type)
	{
		AVObject obj = new AVObject("Building");
		obj["UserID"] = AVUser.CurrentUser.ObjectId;
		obj["Type"] = (int)type;
		obj["Level"] = 1;
		obj["Value"] = 1;
		obj["SlotID"] = slotId;

		obj.SaveAsync().ContinueWith(t => {
			BuildingData newBuilding = new BuildingData();
			newBuilding.UserID = AVUser.CurrentUser.ObjectId;
			newBuilding.Type = type;
			newBuilding.Level = 1;
			newBuilding.Value = 1;
			newBuilding.SlotID = slotId;

			GameManager.Instance.LastCreatedBuilding = newBuilding;
			GameManager.Instance.EventQueue.Queue.Enqueue(new EventItem(){Type = EEventItemType.BuildCommandOK});
		});
	}
Exemple #43
0
	public static void DB_UpdateTestData(string changedData)
	{
		/**
		string objectUpdateId = string.Empty;
		AVQuery<AVObject> query=new AVQuery<AVObject>("Test");
		query.WhereEqualTo("TestA","testa").FirstAsync().ContinueWith(t =>{
			objectUpdateId=t["TestA"];
		}
		);**/

		var obj = new AVObject ("Test");
		
		obj.ObjectId = "53b7bc82e4b0cdeb6e249b7a";
		obj["TestA"] = changedData;
		obj.SaveAsync().ContinueWith(t =>
		                                   {
			// 保存成功之后,修改一个已经在服务端生效的数据,这里我们修改cheatMode和score
			// AVOSCloud只会针对指定的属性进行覆盖操作,本例中的playerName不会被修改
			//obj["TestA"] = "changedTesta";
			//obj.SaveAsync();
		});
	}
Exemple #44
0
	// 网络-注册
	public void NetDoRegist(string userName, string password, string email)
	{
		AVUser user = new AVUser();
		user.Username = userName;
		user.Password = password;
		user.Email = email;

		GameManager.Instance.AsyncBeginWait();
		user.SignUpAsync().ContinueWith(t => {
			// TODO 创建玩家的Village
			GameManager.Instance.AsyncBeginWait();

			AVObject obj = new AVObject("Village");
			obj["UserID"] = AVUser.CurrentUser.ObjectId;
			obj["Belief"] = 0;
			obj["BeliefAll"] = 0;
			
			obj.SaveAsync().ContinueWith(t2 => {
				
				// 创建玩家神庙
				BuildingData newBuilding = new BuildingData();
				newBuilding.AVObject = new AVObject("Building");
				newBuilding.UserID = AVUser.CurrentUser.ObjectId;
				newBuilding.Type = EBuildingType.Altar;
				newBuilding.Level = 1;
				newBuilding.SlotID = 4;
				newBuilding.Sibling = 1;

				newBuilding.AVObject.SaveAsync().ContinueWith(t3=>{
					// 进入登录界面
					// TODO 将用户名和密码拷贝过去
					GameManager.Instance.AsyncEndWait(()=>{
						UIManager.Instance.ChangeScreen(EScreen.Login);
					});
				});
			});
		});
	}
Exemple #45
0
void OnTriggerEnter2D(Collider2D other)
{
    if (other.gameObject.tag == "scoreMaker")
    {
        GameManager.score += 1;
        Destroy(other.gameObject);
    }
    else
    {

        AVAnalytics.StopEvent("OneGame");//本局结束,只要调用一下事件终止方法,SDK会自动计算开始到结束之间的间隔发送到服务端。

        #region 把这次的分数记录到AVOS Cloud的服务端

        AVObject gameScore = new AVObject("GameScore");
        gameScore["score"] = GameManager.score;
        gameScore["playerName"] = "DemoUser";
        gameScore["deviceID"] = SystemInfo.deviceUniqueIdentifier;
        gameScore.SaveAsync();

        #endregion

        gameObject.collider2D.isTrigger = false;
        AudioSource.PlayClipAtPoint(hit, Camera.main.transform.position);
        if (GameManager.score > PlayerPrefs.GetInt("highscore"))
        {
            guiManager.medal = true;
        }
        GameManager.gameOver = true;
    }
}
	private void QueryList () {
		var data = new AVObject("List");
		data["name"] = "hello";
		data["Parameters"] = new List<int>(new int[] {3, 2, 1});

		data.SaveAsync().ContinueWith(t => {
			if (t.IsFaulted || t.IsCanceled) {
				Debug.Log("Failed");
				Debug.Log(t.Exception.Message);
			}
			else {
				Debug.Log("Success");
			}
		}).ContinueWith(t => {
			var query = new AVQuery<AVObject>("List").FindAsync().ContinueWith(t2 => {
				foreach (var result in t2.Result) {
//					var hello = result.Get<string>("name");
//					Debug.Log(hello);
					var list = result.Get<IList<int>>("Parameters");
					Debug.Log(list.ToString());
				}

			});
		});
	}
Exemple #47
0
	// 网络-提交战斗结果
	public void NetSubmitBattleResult(string invader, string defender, bool isWin, Action<AVObject> callback)
	{
		AVObject battleData = new AVObject("Battle");
		battleData["Invader"] = invader;
		battleData["Defender"] = defender;
		battleData["IsWin"] = isWin;
		battleData["Time"] = DateTime.Now;

		battleData.SaveAsync().ContinueWith(t=>{
			if(callback != null)
				callback(battleData);
		});
	}