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); }
private void Initialize() { moveForward = FindObjectOfType <MoveForward>(); if (moveForward != null) { moveForward.Initialize(mainConfig.Speed); } tilePool = GetComponent <RoadTilePool>(); if (tilePool != null) { tilePool.Initialize(mainConfig.Speed); } roadGenerator = GetComponent <RoadGenerator>(); if (roadGenerator != null) { roadGenerator.Initialize(mainConfig.Speed); } playerMover = FindObjectOfType <PlayerMover>(); if (playerMover != null) { playerMover.Initialize(mainConfig.Speed); } treasure = FindObjectOfType <Treasure>(); if (treasure != null) { treasure.Initialize(); } towerController = FindObjectOfType <PlayerTowerController>(); if (towerController != null) { towerController.Initialize(); } }