private Toy CreateToy(ToyData toyData) { Toy toy = Instantiate(toyPrefab); toy.data = toyData; return(toy); }
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); }
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(); }
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)); }
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(); }
public async Task UpdateToyAsync(ToyData toy, int id) { await ToyRepository.UpdateToyAsync(toy, id); }
public async Task AddToyAsync(ToyData toyUnit) { await ToyRepository.AddToyAsync(toyUnit); }
public async Task AddToy([FromBody] ToyData toyUnit) { await ToyService.AddToyAsync(toyUnit); }
public async Task UpdateToy([FromBody] ToyData toy, int id) { await ToyService.UpdateToyAsync(toy, id); }