GamePreparationManager Class Reference
+ Inheritance diagram for GamePreparationManager:

Public Member Functions

void startLoadingGameResourcesFor (string gameId)
 
void provideGameControllerWithStartGameInfo (EAZGameStartInfo startGameInfo)
 
void didEndGame ()
 
void didReceiveOpponentsScore (long opponentScore)
 
void waitingForOpponent ()
 
void didStartPlaying ()
 
void SendScore (long gameScore)
 
void FinishGame (long finalScore)
 
void LeaveGame ()
 

Static Public Member Functions

static void EndGame ()
 

Static Public Attributes

static GamePreparationManager instance
 
static List< int > levelList = new List<int>()
 
static int currentLevel = 0
 
static long currentScore = 0
 
static long oppScore = 0
 
static bool playing = false
 
static int endDate = 0
 
static int gameDuration = 0
 

Events

static System.Action DidEndGameEvent
 
static System.Action WaitingForOpponentEvent
 
static System.Action< long > DidReceiveOpponentsScoreEvent
 
static System.Action< EAZGameStartInfoDidReceiveStartGameInfo
 

Private Member Functions

void Awake ()
 
void OnSceneLoaded (Scene arg0, LoadSceneMode arg1)
 
void gameDidLoad ()
 
void OnApplicationPause (bool pause)
 

Static Private Member Functions

static void OnTokenReceived (object sender, TokenReceivedEventArgs token)
 

Detailed Description

Definition at line 26 of file GamePreparationManager.cs.

Member Function Documentation

◆ Awake()

void GamePreparationManager.Awake ( )
private

Following code snippet sets the GamePreparationDelegate that indicates the start of game preparation sequence and manages it.

EazeGames.shared.gamePreparationManager.setPreparationDelegate(this);

Definition at line 86 of file GamePreparationManager.cs.

87  {
88  PlayerPrefs.DeleteAll();
89  if (instance == null)
90  {
91  instance = this;
92  DontDestroyOnLoad(instance);
93 
94 #if FCM_PRESENT
95  FirebaseMessaging.TokenReceived += OnTokenReceived;
96 #endif
97 
98 #if MULTIPLE_SCENES_LEVELS
99  SceneManager.sceneLoaded += OnSceneLoaded;
100 #endif
101 
102  EazeGames.shared.gamePreparationManager.setPreparationDelegate(this);
103  }
104  else if (instance != this)
105  //Prevents multiple API calls on Initial scene reload
106  Destroy(gameObject);
107  }

◆ didEndGame()

void GamePreparationManager.didEndGame ( )

Callback from Platform about final completion gameplay sequence.

Definition at line 196 of file GamePreparationManager.cs.

197  {
198  if (DidEndGameEvent != null)
199  {
200  DidEndGameEvent();
201  }
202  }

◆ didReceiveOpponentsScore()

void GamePreparationManager.didReceiveOpponentsScore ( long  opponentScore)

Informs about opponent’s score. In case of tournament ( multiple opponents), it will send the highest score among all the opponents.

Parameters
long$opponentScoreopponent’s score.

Definition at line 208 of file GamePreparationManager.cs.

209  {
210  oppScore = opponentScore;
211  if (DidReceiveOpponentsScoreEvent != null)
212  {
213  DidReceiveOpponentsScoreEvent(opponentScore);
214  }
215  }

◆ didStartPlaying()

void GamePreparationManager.didStartPlaying ( )

Method that lets platform know that player has started gameplay sequence so it should handle gameplay messages

Definition at line 233 of file GamePreparationManager.cs.

234  {
235  EazeGames.shared.gamePlayManager.didStartPlaying();
236  }

◆ EndGame()

static void GamePreparationManager.EndGame ( )
static

Method which defines every runtime gameplay variables with default values.

Definition at line 297 of file GamePreparationManager.cs.

297  {
298  currentLevel = 0;
299  currentScore = 0;
300  oppScore = 0;
301  playing = false;
302  endDate = 0;
303  gameDuration = 0;
304  }

◆ FinishGame()

void GamePreparationManager.FinishGame ( long  finalScore)

Informs Platform that user finished playing with provided final score.

Parameters
long$finalScoreThe last acquired score in current game sequence.

Definition at line 253 of file GamePreparationManager.cs.

254  {
255  EazeGames.shared.gamePlayManager.finishPlayingWithFinalScore(finalScore);
256  }

◆ gameDidLoad()

void GamePreparationManager.gameDidLoad ( )
private

Application is ready to launch gameplay sequence

Definition at line 133 of file GamePreparationManager.cs.

134  {
135  EazeGames.shared.gamePreparationManager.gameDidLoad();
136  }

◆ LeaveGame()

void GamePreparationManager.LeaveGame ( )

Triggers GamePlayManager leaveGame event for user to leave game sequence.

Definition at line 261 of file GamePreparationManager.cs.

262  {
263  EazeGames.shared.gamePlayManager.leaveGame();
264  }

◆ OnApplicationPause()

void GamePreparationManager.OnApplicationPause ( bool  pause)
private

Code snippet, written to handle situation when user lost focus on application but haven't fold it.

Load initial or loading scene when user opens game window after collapsing so game could run from scratch on starting new game sequence without showing last game scene.

Definition at line 282 of file GamePreparationManager.cs.

283  {
284  if (!pause)
285  {
286 #if LOADING_SCENE
287  SceneManager.LoadScene("{LoadingSceneName}");
288 #else
289  SceneManager.LoadScene("{InitSceneName}");
290 #endif
291  EndGame();
292  }
293  }

◆ OnSceneLoaded()

void GamePreparationManager.OnSceneLoaded ( Scene  arg0,
LoadSceneMode  arg1 
)
private

Definition at line 110 of file GamePreparationManager.cs.

111  {
112  #if LOADING_SCENE
113  if (arg0.name == "{Loading scene name}")
114  {
115  SceneManager.LoadSceneAsync("Level" + levelList[currentLevel]);
116  }
117  #endif
118 
119  if (levelList.Count > 0 && arg0.name == "Level" + levelList[0])
120  {
122  didStartPlaying();
123  playing = true;
124  }
125  }

◆ OnTokenReceived()

static void GamePreparationManager.OnTokenReceived ( object  sender,
TokenReceivedEventArgs  token 
)
staticprivate

Custom event handler, that fires when Firebase token has been received.

Definition at line 271 of file GamePreparationManager.cs.

272  {
273  EazeGames.shared.setFCMToken( token.Token );
274  }

◆ provideGameControllerWithStartGameInfo()

void GamePreparationManager.provideGameControllerWithStartGameInfo ( EAZGameStartInfo  startGameInfo)

Callback from server with gameplay start configuration telling that application should launch gameplay sequence

Parameters
EAZGameStartInfostartGameInfo Contains information about game, that is about to start.

In this callback string level sequence must be parsed into list of integer levels indexes levelList.

Note
  • Level sequence list must be re-assigned, not added to already existing.
  • Saved values of player's, opponent's score must be erased on new gameplay sequence.
  • You receive new game duration and time left for current sequence, for game timer, only from startGameInfo. No custom timer should be implemented on new gameplay sequence.

In order to show user the proper time left, in case an application collapses or loses focus, sequence endDate can be saved for timer and compared with current game sequence initial start date, using provided Epoch class.

Note
Either you use PlayerPrefs for this purposes or static GamePreparationManager instance fields necessarily delete all saved values before new game sequence launch.

Executed in order to start receive callbacks from platform regarding runtime gameplay sequence.

EazeGames.shared.gamePlayManager.setGamePlayDelegate(this);

Definition at line 166 of file GamePreparationManager.cs.

168  {
169  currentLevel = 0;
170  gameDuration = startGameInfo.gameDuration;
171 
172  #if MULTIPLE_SCENES_LEVELS
173  levelList = startGameInfo.levels.Split('-').Select(int.Parse).ToList();
174  #endif
175 
176  EazeGames.shared.gamePlayManager.setGamePlayDelegate(this);
177 
178  #if MULTIPLE_SCENES_LEVELS
179  #if LOADING_SCENE
180  SceneManager.LoadScene("{Loading scene name}");
181  #else
182  SceneManager.LoadScene("Level" + levelList[currentLevel]);
183  #endif
184  #else
187  playing = true;
188  #endif
189  }

◆ SendScore()

void GamePreparationManager.SendScore ( long  gameScore)

Updates player score on platform

Parameters
long$gameScoreThe current score aсquired in current game sequence.

Definition at line 243 of file GamePreparationManager.cs.

244  {
245  currentScore = gameScore;
246  EazeGames.shared.gamePlayManager.sendScore(gameScore);
247  }

◆ startLoadingGameResourcesFor()

void GamePreparationManager.startLoadingGameResourcesFor ( string  gameId)

Ability to load additional necessary resources before gameplay sequence launch

Parameters
gameIdgives id of game to load resources for

Definition at line 141 of file GamePreparationManager.cs.

142  {
143  gameDidLoad();
144  }

◆ waitingForOpponent()

void GamePreparationManager.waitingForOpponent ( )

This callback will fire in case when there is a need to wait for opponent to finish playing in Live game.

Definition at line 220 of file GamePreparationManager.cs.

221  {
222  if (WaitingForOpponentEvent != null)
223  {
225  }
226  }

Member Data Documentation

◆ currentLevel

int GamePreparationManager.currentLevel = 0
static

Current level index.

Definition at line 55 of file GamePreparationManager.cs.

◆ currentScore

long GamePreparationManager.currentScore = 0
static

Current player's score.

Definition at line 59 of file GamePreparationManager.cs.

◆ endDate

int GamePreparationManager.endDate = 0
static

Calculated ending point of gameplay sequence.

Definition at line 71 of file GamePreparationManager.cs.

◆ gameDuration

int GamePreparationManager.gameDuration = 0
static

Game duration provided by Platform to find out how long should game sequence last in seconds.

Definition at line 75 of file GamePreparationManager.cs.

◆ instance

GamePreparationManager GamePreparationManager.instance
static

Static GamePreparationManager instance.

Definition at line 31 of file GamePreparationManager.cs.

◆ levelList

List<int> GamePreparationManager.levelList = new List<int>()
static

Parsed into list of integer indexes level sequence string.

Definition at line 51 of file GamePreparationManager.cs.

◆ oppScore

long GamePreparationManager.oppScore = 0
static

Current opponent's score

Definition at line 63 of file GamePreparationManager.cs.

◆ playing

bool GamePreparationManager.playing = false
static

Indicates that application is ready to launch gameplay sequence

Definition at line 67 of file GamePreparationManager.cs.

Event Documentation

◆ DidEndGameEvent

System.Action GamePreparationManager.DidEndGameEvent
static

Custom didEndGame callback handler for GamePlayManager.

Definition at line 35 of file GamePreparationManager.cs.

◆ DidReceiveOpponentsScoreEvent

System.Action<long> GamePreparationManager.DidReceiveOpponentsScoreEvent
static

Custom didReceiveOpponentsScoreEvent callback handler for GamePlayManager.

Definition at line 43 of file GamePreparationManager.cs.

◆ DidReceiveStartGameInfo

System.Action<EAZGameStartInfo> GamePreparationManager.DidReceiveStartGameInfo
static

Custom didReceiveStartGameInfo callback handler for GamePlayManager.

Definition at line 47 of file GamePreparationManager.cs.

◆ WaitingForOpponentEvent

System.Action GamePreparationManager.WaitingForOpponentEvent
static

Custom waitingForOpponent callback handler for GamePlayManager.

Definition at line 39 of file GamePreparationManager.cs.

GamePreparationManager.OnTokenReceived
static void OnTokenReceived(object sender, TokenReceivedEventArgs token)
Definition: GamePreparationManager.cs:271
GamePreparationManager.OnSceneLoaded
void OnSceneLoaded(Scene arg0, LoadSceneMode arg1)
Definition: GamePreparationManager.cs:110
GamePreparationManager.WaitingForOpponentEvent
static System.Action WaitingForOpponentEvent
Definition: GamePreparationManager.cs:39
GamePreparationManager.gameDidLoad
void gameDidLoad()
Definition: GamePreparationManager.cs:133
GamePreparationManager.endDate
static int endDate
Definition: GamePreparationManager.cs:71
GamePreparationManager.currentLevel
static int currentLevel
Definition: GamePreparationManager.cs:55
GamePreparationManager.EndGame
static void EndGame()
Definition: GamePreparationManager.cs:297
EAZGameStartInfo.levels
string levels
Definition: EAZGameStartInfo.cs:20
EAZGameStartInfo.gameDuration
int gameDuration
Definition: EAZGameStartInfo.cs:12
GamePreparationManager.instance
static GamePreparationManager instance
Definition: GamePreparationManager.cs:31
GamePreparationManager.oppScore
static long oppScore
Definition: GamePreparationManager.cs:63
Epoch.Current
static int Current()
Definition: Epoch.cs:8
GamePreparationManager.gameDuration
static int gameDuration
Definition: GamePreparationManager.cs:75
GamePreparationManager.playing
static bool playing
Definition: GamePreparationManager.cs:67
GamePreparationManager.DidReceiveOpponentsScoreEvent
static System.Action< long > DidReceiveOpponentsScoreEvent
Definition: GamePreparationManager.cs:43
EazeGames
Definition: EazeGames.cs:2
GamePreparationManager.DidEndGameEvent
static System.Action DidEndGameEvent
Definition: GamePreparationManager.cs:35
Epoch
Definition: Epoch.cs:3
GamePreparationManager.didStartPlaying
void didStartPlaying()
Definition: GamePreparationManager.cs:233
GamePreparationManager.levelList
static List< int > levelList
Definition: GamePreparationManager.cs:51
GamePreparationManager.currentScore
static long currentScore
Definition: GamePreparationManager.cs:59