Example #1
0
    private Toy CreateToy(ToyData toyData)
    {
        Toy toy = Instantiate(toyPrefab);

        toy.data = toyData;
        return(toy);
    }
Example #2
0
    public void AddScore(ToyData toyType)
    {
        int index = Array.IndexOf(ToyManager.Instance.toys, toyType);

        if (index == -1)
        {
            Debug.LogError($"Failed to add score: Toy not found {toyType}");
            return;
        }

        toyCounts[index] += 1;
        onPointAdded.Invoke(index);
    }
Example #3
0
        public async Task AddToyAsync(ToyData toyUnit)
        {
            Toy      toy      = Mapper.Map <Toy>(toyUnit);
            Category category = Context.PSContext.Category.FirstOrDefault(x => x.CategoryId == toyUnit.CategoryId);

            if (category != null)
            {
                category.Toy.Add(toy);
            }
            else
            {
                toy.CategoryId = null;
                Context.Table.Add(toy);
            }
            await Context.SaveChangesAsync();
        }
Example #4
0
    public Toy CreateRandom()
    {
        float sumOfWeights = toys.Sum(x => x.randomWeight);
        float rand         = Random.Range(0, sumOfWeights);
        float current      = sumOfWeights;

        ToyData toyData = toys[0];

        for (int i = toys.Length - 1; i >= 0; i--)
        {
            current -= toys[i].randomWeight;
            if (current <= rand)
            {
                toyData = toys[i];
                break;
            }
        }

        return(CreateToy(toyData));
    }
Example #5
0
        public async Task UpdateToyAsync(ToyData toyData, int id)
        {
            Toy toy = Mapper.Map <Toy>(toyData);

            toy.ToyId = id;

            if (toyData.CategoryId != null)
            {
                Category category = await Context.PSContext.Category.FirstOrDefaultAsync(x => x.CategoryId == toyData.CategoryId);

                if (category == null)
                {
                    toy.CategoryId = null;
                }
            }
            else
            {
                toy.CategoryId = null;
            }

            Context.Table.Update(toy);
            await Context.SaveChangesAsync();
        }
Example #6
0
 public async Task UpdateToyAsync(ToyData toy, int id)
 {
     await ToyRepository.UpdateToyAsync(toy, id);
 }
Example #7
0
 public async Task AddToyAsync(ToyData toyUnit)
 {
     await ToyRepository.AddToyAsync(toyUnit);
 }
Example #8
0
 public async Task AddToy([FromBody] ToyData toyUnit)
 {
     await ToyService.AddToyAsync(toyUnit);
 }
Example #9
0
 public async Task UpdateToy([FromBody] ToyData toy, int id)
 {
     await ToyService.UpdateToyAsync(toy, id);
 }