public Layer CreateLayer(LayersInfo info, int depth, int skip, bool forceTreasure) { var layer = new DirtLayer(); Sprite sprite = default; if (depth == 0) { sprite = info.TopVariants.GetRandomElement(); } else if (depth == _maxDepth - 1) { sprite = info.BottomVariants.GetRandomElement(); } else { sprite = info.MiddleVariants.GetRandomElement(); } if (depth != 0) { if (forceTreasure || (skip == 0 && Random.Range(0f, 1f) < info.TreasureProbability)) { var treasure = new Treasure(); treasure.Initialize(info.TreasureVariants.GetRandomElement(), _treasurePool.GetTreasure); layer.SetTreasure(treasure); } } var color = info.DepthGradient.Evaluate((float)depth / _maxDepth); layer.Initialize(sprite, color, depth == _maxDepth - 1); return(layer); }
public LayersBuilder(LayersInfo info, int depth) { _treasurePool = new TreasurePool(info.TreasurePrefab, 5); _maxDepth = depth; _info = info; }