This flow is responsible for displaying the score during the game. So it first process the score to make it as a plain string, and then move to the "Show Score" state which will show this score on screen. We do this in two steps to avoid parsing the score each frames, there is no need for this, we only parse it when the score changed.
Restart the game simply reset the score back to 0, nothing more.
RESTART GAME is fired by GAME MANAGER : Menu UI when the user press the restart button.
The flow following a "ADD SCORE" global event takes care of two distinct features, tho it's done in one flow because the data used is identical.
- It gets the score data stored in this global event, namely the score position and the name of the object that scored, in our case, the ball. Then it creates a GameAnalytics Id "Score:$ScoreName" where $scoreName is the name of the object that scored ( the ball). and it eventually fires a GameAnalytics Design Event to record this score event, position and value.
- It checks if the new score is higher than the current high score, and if so, broadcast a global event "NEW HIGH SCORE" for all interested Fsm's to know about it.
ADD SCORE is fired by Target : Target (Prefab) when the ball hit this target.
SAVE HIGH SCORE
This flow simply waits for the user to be willing to save his new high score and store this new high score in the PlayerPrefs. The PlayerPrefs is a very powerful way of storing permanent data within the Game environment, on the device or computer. If the user quits the game, the data stored in the PlayerPrefs is not lost, it will persists from sessions to sessions. This is how we keep track of the current highest score done by this user on this device. Amore advanced system would store highscore online or via the IOS game center system for example if deploying for the IOS devices.
SAVE HIGH SCORE is fired by GAME MANAGER : Menu UI when the user press the save button
Retrieve the high score from the PlayerPrefs to always be up to date.
GAME OVER is fired by Lave : Floor when the ball touches the floor.