public void Initialize(LevelData data) { int levelLength = data.length; ItemDeposit depositPrefab = Resources.Load <ItemDeposit>("prefabs/items/ItemDeposit"); GameObject finishLinePrefab = Resources.Load <GameObject>("prefabs/misc/FinishLine"); CollectedItems = new List <ItemData>(); // todo define start and end, deploy deposits at correct locations foreach (DepositProbability prob in data.depositProbability) { ItemData depositData = prob.deposit; int amount = (int)Random.Range(prob.minAppearence, prob.maxAppearence); float verticalStep = levelLength * .9f / Mathf.Max(2f, amount + 1); for (int j = 0; j < amount; j++) { float randomHorizontal = Random.Range(-1f, 1f) * HORIZONTAL_DEPOSIT_SPREAD; // limit vertical spread to vertical step so nothing is generated after the finish line float randomVertical = Random.Range(-1f, 1f) * Mathf.Min(verticalStep, VERTICAL_DEPOSIT_SPREAD); ItemDeposit deposit = Instantiate(depositPrefab, new Vector3(randomHorizontal, verticalStep * j + randomVertical), Quaternion.identity, transform); deposit.Initialize(depositData, Random.Range(prob.minContent, prob.maxContent)); deposit.ItemCollected += item => CollectedItems.Add(item); } } Instantiate(finishLinePrefab, Vector3.up * levelLength, Quaternion.identity, transform); ServiceLocator.Get <GameStateService>().GameFinishing += OnGameFinishing; }
private void RemoveVisibleDeposit(ItemDeposit deposit) { if (!deposit.CanBeCollectedBy(_toolData)) { return; } _depositsInSight.Remove(deposit); }
public override void Executed(NoteQuality noteQuality, int streak) { // do nothing if current target still has health // otherwise search deposits on screen (closest first) and pick a target // pick targets depending on unit equipment (tier, type) _closestDeposit = unit.GetClosestDeposit(); _initPosition = unit.transform.position; unit.Agent.isStopped = false; unit.Agent.speed = unit.MovementSpeed + unit.MovementSpeed * streakBonus; if (_closestDeposit) { Vector3 direction = (_closestDeposit.transform.position - unit.transform.position).normalized; unit.Agent.destination = _closestDeposit.transform.position - direction * GATHER_DISTANCE; } }
private void UpdateClosestDeposit() { _closestDeposit = unit.GetClosestDeposit(); }