This document will study in details the PlayMaker refactoring of GameAnalytics Integration Demo.
The demo itself is a simple Breakout Game. Remember that within the fsm inspector, there is a little blue book icon. Click on it to launch the related Wiki page and fall back into this section.
The Game Development
For users interested in how the game was designed, the following will explain each features, not related to GameAnalytics Integration, simply how the game was developed.
This is a simple break out type of game, where a ball is freely moving around the scene, the user has a pad he can move side ways to prevent th eball from touching the ground, which would ends the game. As the ball touches the rotating cubes at the top, the player gains points.
The game is relying on the physics engine:
- Each cubes is constraints physically to only be able to rotate around.
- the ball is free to move around, but constraints in its velocity to not loose or gain speed during the game play
- the walls and floors have colliders to contraint the ball within the scene.
- The Pad is also a collider, but it's movement are totally constraint and controlled by the user's input.
- The user is only expected to press the left and right input ( A,D or Left and right arrows)
- Menus are using the mouse and keyboard.
- During the game, scores is kept and compared to the highscore. Highscores are saved in PlayerPrefs, so that it survives between sessions,
GameAnalytics Integration in Game
The following concentrate exclusively on the integration of GameAnalytics within this BreakOut game. It's important to understand first how the game works, so glancing over the Game developement section may be beneficial to fully understand the implications of this integration.
GameAnalytics has a Setup wizard that let's you conveniently setup the project, store your game and secret keys so that data is sent to your GameAnalytics account.
It is strongly advice to go through the GameAnalyticsUnity quick start guide documentation
GameAnalytics comes with several prefabs and behavior to provide the fundation for data acquisition common to all Unity projects as well as specifics to your game.
- GA_manager : this is only for the purpose of the game sample as it turns on the sandbox mode for GamaAnalytics. It's not needed for real world integration.
In Game Data acquisition
Inside the game logic and feature implementation, we are going to acquire specific data related to this game. GameAnalytics comes with several categories to help structuring and organize data during analysis. When sending data to GameAnalytics, you can structure your events. It is strongly recommended you go through the GameAnalytics documentation on Events creation before you dive further in this demo.
- Business Event
To send a Business Event, use the playmaker action Send Business Event
We don't use this event in this game as there is no In App Purchase or advertising, but if you had, you would use this.
You can learn more in the GameAnalytics documentation on tracking business events.
- Design Event
To send a Design Event, use the playmaker action Send Design Event
We use Design event to record when the user scores in GAME MANAGER : Score. So everytime we add to the score, we fire this design event. We create a specific event id, composed with "Score:" followed by the name of the ball. We only have one ball, but if you expand this game and have two players, then you would be able to know what player 1 and 2 scores, when and how. So the final event id looks like "Score:Ball". We also pass the current score value as well as the position of the score.
We also use a Design event when the game is over in fsm GAME MANAGER : Game Over, so when the ball falls on the floor, we fire a design event with id "GameOver", with no values, but just the position of the ball where it hits the floor.
You can learn more in the GameAnalytics documentation on tracking design events.
- Quality Event
To send a Quality Event, use the playmaker action Send Quality Event
We don't use this event in this game, but you should use this event to track issues in your game, say you catch an error in your code, you should fire a quality event to track it properly.
You can learn more in the GameAnalytics documentation on tracking quality events.
- User Event
to send a User Event, use the playmaker action Send User Event
We use this event when the user saves his score in GAME MANAGER : Menu UI. It's highly recommanded to keep track of users for useful analysis.
You can learn more in the GameAnalytics documentation on tracking users.
- GAME MANAGER : Start
- GAME MANAGER : Score
- GAME MANAGER : Menu UI
- GAME MANAGER : Game Over
- Ball : Ball controller ( Prefab)
- Lave : Floor
- PlayerCube : Player Controller (Prefab)
- Target : Target (Prefab)
Fsm Listing using Game Analytics
Only these Fsm's actually implement Game Analytics. The rest focuses on the game logic and features.
These global events are created specifically for this game, they allow Fsm's to communicate together on specific game states and user actions. It's very important to understand what fsm is firing these events and what fsm's actually implements these events to react, they form the high level flow of the game play and menu logic. Some events are only implemented by one fsm, so one could simply direclty reference that fsm and send that event directly, but that defeats the very essence of global events. By simply broadcasting a global event, any fsm' interested in this event can implement it without the sender having to keep track of who is interested, it enables very powerful and simple design and great flexibility and scalability.
ADD SCORE is fired by Target : Target (Prefab) when the ball hit this target.
GAME MANAGER : Score is listening to this event to add to the current score.
GAME OVER is fired by Lave : Floor when the ball touches the floor.
GAME MANAGER : Score implements it to refresh the high score.
GAME MANAGER : Menu UI implements it to display the highscore, the restart button and the user saving options menu.
GAME MANAGER : Game Over implements it to send a GameAnalyitcs Design Event.
RESTART GAME is fired by GAME MANAGER : Menu UI when the user press the restart button.
GAME MANAGER : Score implements it to reset the score and start over.
GAME MANAGER : Start implements it to instantiate a new ball.
PlayerCube : Player Controller (Prefab) implements it to reset its position back to the center of the screen
NEW HIGH SCORE
NEW HIGH SCORE is fired by GAME MANAGER : Score when it detects that the score is higher than the current one ( stored in the player preferences).
GAME MANAGER : Menu UI implements it to make sure it shows the new high score when the game ends.
SAVE HIGH SCORE
SAVE HIGH SCORE is fired by GAME MANAGER : Menu UI when the user press the save button
GAME MANAGER : Score implements it to store the new high score in the player preferences.
If you have questions and issues, don't hesitate to post on the PlayMaker Forum