public void SetupSession(TrainingSessionData sessionData) { shotSession = (ShotSessionData)sessionData; shootInterval = shotSession.shootInterval; shotTasks = shotSession.shotTaskList.ToArray(); currentShotTaskIndex = 0; previousShotTask = null; currentShotTask = shotTasks[currentShotTaskIndex]; nextShotTask = currentShotTaskIndex + 1 < shotTasks.Length ? shotTasks[currentShotTaskIndex + 1] : null; shotSession.MaximumScore = GetMaxScore(shotSession); queuedBalls = Utility.CreateMonoBehaviourPool <TennisBall>(ballPrefab, numberPooledBalls, trainingBallsParent); ballMachine.MoveTo(currentShotTask.BallMachineShot.StartPosition); ballMachine.AimAt(currentShotTask.BallMachineShot.TargetPosition); shotZoneHighlighter.ScaleAndPositionZone(currentShotTask.TaskCourtZone); shotZoneHighlighter.ColourZone(currentShotTask.TaskShotType); shotSessionEventRelay.ChangeTask(currentShotTask); shotSessionEventRelay.ChangeProgress(0); shotSessionEventRelay.ChangeScore(0); shotSessionEventRelay.ChangeCombo(0); gameObject.SetActive(true); }
private void UpdateScore(ShotTask shotTask) { if (shotTask == null) { return; } int increment = 0; if (shotTask.ShotZoneTaskAccomplished) { currentCombo += 1; increment += hitZoneReward; } else { currentCombo = 0; } bestCombo = Mathf.Max(currentCombo, bestCombo); if (shotTask.ShotTypeTaskAccomplished) { increment += correctShotReward; } int scoreMultiplier = GetScoreMultiplier(currentCombo); currentScore += increment * scoreMultiplier; shotSession.Score = currentScore; shotSessionEventRelay.ChangeScore(currentScore); shotSessionEventRelay.ChangeCombo(currentCombo); }
private IEnumerator ShotSessionRoutine() { while (currentShotTaskIndex < shotTasks.Length) { currentPlayBall = queuedBalls.Dequeue(); queuedBalls.Enqueue(currentPlayBall); ballMachine.ShootBall(currentPlayBall, currentShotTask.BallMachineShot); nextShotTask = currentShotTaskIndex + 1 < shotTasks.Length ? shotTasks[currentShotTaskIndex + 1] : null; if (nextShotTask != null) { yield return(new WaitForSeconds(shootInterval * 0.75f)); ballMachine.MoveTo(nextShotTask.BallMachineShot.StartPosition, true, shootInterval * 0.25f); ballMachine.AimAt(nextShotTask.BallMachineShot.TargetPosition, true, shootInterval * 0.25f); shotZoneHighlighter.ScaleAndPositionZone(nextShotTask.TaskCourtZone, true, shootInterval * 0.25f); shotZoneHighlighter.ColourZone(nextShotTask.TaskShotType, true, shootInterval * 0.25f); shotSessionEventRelay.ChangeTask(nextShotTask); yield return(new WaitForSeconds(shootInterval * 0.25f)); } yield return(new WaitWhile(() => currentPlayBall.CanBeHit)); if (!currentShotTask.Played) { currentShotTask.Played = true; UpdateScore(currentShotTask); shotSessionEventRelay.ChangeProgress((currentShotTaskIndex + 1f) / shotTasks.Length); } previousShotTask = currentShotTask; if (nextShotTask != null) { currentShotTask = nextShotTask; } currentShotTaskIndex += 1; yield return(new WaitForEndOfFrame()); } yield return(new WaitWhile(() => currentPlayBall.CanBeHit)); CompleteSession(); }
public void CleanupSession() { shotSession = null; shootInterval = 0; shotTasks = null; currentShotTaskIndex = 0; previousShotTask = null; currentShotTask = null; nextShotTask = null; currentScore = 0; currentCombo = 0; bestCombo = 0; currentPlayBall = null; foreach (TennisBall ball in queuedBalls) { Destroy(ball.gameObject); } queuedBalls.Clear(); gameObject.SetActive(false); }
private void UpdateTask(ShotTask task) { SetTaskShotText(task.TaskShotType, true); SetTaskShotBackgroundImageColour(task.TaskShotType, true); }
public void ChangeTask(ShotTask shotTask) { OnTaskChanged?.Invoke(shotTask); }