public void CreateRandomElement(GridPosition position) { var typeCount = _contexts.Config.GetUnique <TypeCountComponent>().Value; int maxType = typeCount; if (typeCount - 1 < 1) { maxType = 1; } else if (typeCount >= 100) { maxType = 100; } // Unity's Random class can't be used outside of the Unity environment. //var maxType = Mathf.Clamp(typeCount - 1, 1, 100); //var randomType = Random.Range(0, maxType + 1); var randomType = Random.Value.Next(0, maxType + 1); var normalizedType = Mathf.InverseLerp(0, maxType, randomType); var entity = _game.CreateEntity(); _game.SetFlag <ElementComponent>(entity, true); _game.SetFlag <MovableComponent>(entity, true); _game.Set(entity, new IdComponent { value = _entityCounter }); _game.Set(entity, new ElementTypeComponent { value = randomType }); _game.Set(entity, new AssetComponent { value = "Element", id = (int)ActorType.Element }); _game.Set(entity, new ColorComponent { value = new Color(normalizedType, normalizedType, normalizedType) }); entity.Set <PositionComponent>(c => c.value = position); _entityCounter++; }
/// <summary> /// Initializes a new instance of the <see cref="GenericRepository{TEntity}"/> class. /// </summary> /// <param name="dbContext">The dbContext<see cref="SupplyOfProductsContext"/></param> protected GenericRepository(IGenericContext dbContext, IMapper mapper = null) { DbContext = dbContext; _Current = DbContext.Set <TEntity>(); _Mapper = mapper; }