void Update() { if (_inAnErrorState) { // Something has broken, stop running for nows return; } Fragment.Tick(); Fragment.Message msg = new Fragment.Message(); Fragment.Result result = new Fragment.Result(); while (Fragment.PollMessageQueue(ref msg, ref result)) { // Handle the message // .. if (result == Fragment.Result.SR_ERROR) { string errorDesc = ""; int errorCode = Fragment.GetLastError(ref errorDesc); Debug.Log("Fragment error description: " + errorDesc); Debug.Log("Fragment error code: " + errorCode); // Typically you'd want to handle any errors elegantly, but in this instance we'll halt the program // flow since this is a learning example Debug.Log("Carz will now stop ticking internally. Please rectify the errors above and run again."); _inAnErrorState = true; return; } else { // Pass it into sub-systems to handle _playerManager.HandleFragmentMessage(msg); _carLibrary.HandleFragmentMessage(msg); } } _playerManager.Update(); GameState.GetActiveState().Tick(); }
void Start() { Fragment.Result result = Fragment.Initialise(GameID, LocalServerURL); if (result != Fragment.Result.SR_OK) { string detailedErrorDesc = ""; Fragment.GetLastError(ref detailedErrorDesc); Debug.Log("Fragment error desc: " + detailedErrorDesc); } Fragment.AuthRequestCode code = new Fragment.AuthRequestCode(); result = Fragment.PlayerAuthRequest(0, ref code); if (result != Fragment.Result.SR_OK) { string detailedErrorDesc = ""; Fragment.GetLastError(ref detailedErrorDesc); Debug.Log("Fragment error desc: " + detailedErrorDesc); } AuthUI.Show(code, "Player 1", "Join the game"); }
void Update() { Fragment.Tick(); if (AuthUITimer > 0) { AuthUITimer -= Time.deltaTime; if (AuthUITimer <= 0.0) { AuthUI.Hide(); } } Fragment.Result result = new Fragment.Result(); Fragment.Message msg = new Fragment.Message(); while (Fragment.PollMessageQueue(ref msg, ref result)) { // Handle the message Debug.Log("Fragment Message received. Type: " + msg.type); switch (msg.type) { case Fragment.MessageType.PlayerAuthComplete: { AuthUI.SetSignedInState(true, "Welcome to the game", "Please wait a moment..."); AuthUITimer = 2.0f; Debug.Log("Player index: " + msg.playerAuthComplete.playerIndex); Debug.Log("Auth result: " + msg.playerAuthComplete.result); break; } case Fragment.MessageType.PlayerInfo: { playerInfoReady = true; Debug.Log("Player index: " + msg.playerInfo.playerIndex); Debug.Log("Player handle: " + msg.playerInfo.playerHandle); playerHandle = msg.playerInfo.playerHandle; break; } case Fragment.MessageType.GameInfo: { gameInfoReady = true; Debug.Log("Game handle: " + msg.gameInfo.gameHandle); gameHandle = msg.gameInfo.gameHandle; break; } case Fragment.MessageType.Error: { Debug.Log("Error context: " + msg.error.context); string detailedErrorDesc = ""; int code = Fragment.GetLastError(ref detailedErrorDesc); Debug.Log("Detailed error desc: " + detailedErrorDesc); Debug.Log("Error code: " + code); break; } } } if ((playerInfoReady && gameInfoReady) && !haveLoggedInfo) { LogInfo(); haveLoggedInfo = true; } }