Beispiel #1
0
 IEnumerator StartSpawnFoods()
 {
     while (true)
     {
         var spawnFoodCount = Constants.INIT_FOOD_COUNT - battle.IdToFoods.Count;
         // 获取最大食物 id
         PlayArray spawnFoods = new PlayArray();
         var       nextFoodId = battle.NextFoodId;
         for (int i = 0; i < spawnFoodCount; i++)
         {
             var foodId  = nextFoodId + i;
             var foodPos = BattleHelper.RandomPos();
             var food    = new Food {
                 Id   = foodId,
                 Type = i % 3,
                 X    = foodPos.X,
                 Y    = foodPos.Y
             };
             spawnFoods.Add(food);
         }
         var eventData = new PlayObject {
             { "foods", spawnFoods },
             { "nextFoodId", nextFoodId + spawnFoodCount }
         };
         var client = LeanCloudUtils.GetClient();
         client.SendEvent(Constants.SPAWN_FOOD_EVENT, eventData);
         yield return(new WaitForSeconds(Constants.SPWAN_FOOD_DURATION));
     }
 }
Beispiel #2
0
    public PlayArray GetFoods()
    {
        var foods = new PlayArray();

        foreach (var food in IdToFoods)
        {
            foods.Add(food.Value.Data);
        }
        return(foods);
    }