/// <summary> /// Called when scene is changed /// </summary> private static void ScreenChanged(string from, string to) { TTTGameLogic gameLogic = GameObject.FindObjectOfType <TTTGameLogic>(); ClientCellStorage clientCellStrg = GameObject.FindObjectOfType <ClientCellStorage>(); // if we found one of those abve we are on a game screen if (gameLogic != null) { if (to == "GameAI") { gameLogic.SomeoneWonGameEvent += GameWonAI; } else { gameLogic.SomeoneWonGameEvent += GameWon; } } else if (clientCellStrg != null) { ClientCellStorage.SomeoneWonEvent += GameWon; } }
public void OnRealTimeMessageReceived(bool isReliable, string senderId, byte[] data) { string message = System.Text.Encoding.Unicode.GetString(data); string[] splitMessage = message.Split('#'); switch (splitMessage[0]) { // CLIENT CLIENT CLIENT CLIENT CLIENT CLIENT CLIENT CLIENT CLIENT // CLIENT CLIENT CLIENT CLIENT CLIENT CLIENT CLIENT CLIENT CLIENT case GPMessageStrings.JUMP_TO: // server sends that we have to jump somewhere with camera Vector3 jumpTo = new Vector3(int.Parse(splitMessage[1]), int.Parse(splitMessage[2]), Camera.main.transform.position.z); Camera.main.transform.DOMove(jumpTo, Vector2.Distance(Camera.main.transform.position, jumpTo) * JUMP_TIME_PER_ONE); break; case GPMessageStrings.SIGN_PLACED: // Server sends that a sign was placed int[] lastPos = new int[] { int.Parse(splitMessage[1]), int.Parse(splitMessage[2]) }; Cell.CellOcc lastType = (Cell.CellOcc)System.Enum.Parse(typeof(Cell.CellOcc), splitMessage[3]); // Place sign locally ClientCellStorage.PlaceCellAt(lastPos, lastType); break; case GPMessageStrings.ADD_BORDER: // Server sends that a border was added // Get data and add a border locally int countOfPoints = int.Parse(splitMessage[1]); int[,] points = new int[countOfPoints, 2]; float[,] winLine = new float[2, 2]; for (int k = 0; k < countOfPoints; k++) { points[k, 0] = int.Parse(splitMessage[2 * (k + 3)]); points[k, 1] = int.Parse(splitMessage[2 * (k + 3) + 1]); } winLine[0, 0] = float.Parse(splitMessage[2]); winLine[0, 1] = float.Parse(splitMessage[3]); winLine[1, 0] = float.Parse(splitMessage[4]); winLine[1, 1] = float.Parse(splitMessage[5]); Cell.CellOcc winType = (Cell.CellOcc)System.Enum.Parse(typeof(Cell.CellOcc), splitMessage[6 + countOfPoints * 2]); BluetoothClientBorder.AddBorderPoints(points, winLine, winType); // Someone won the game so call it in clientcellstorage ClientCellStorage.SomeoneWon(winType); break; case GPMessageStrings.SEND_SCORE: // Server sends score int xScore = int.Parse(splitMessage[1]); int oScore = int.Parse(splitMessage[2]); Scoring.SetScore(xScore, oScore); break; case GPMessageStrings.TURN_OF: // Server sends whose turn it is Cell.CellOcc whoseTurn = (Cell.CellOcc)System.Enum.Parse(typeof(Cell.CellOcc), splitMessage[1]); ClientUIInScript.UpdateImage(whoseTurn); break; // SERVER SERVER SERVER SERVER SERVER SERVER SERVER SERVER SERVER SERVER // SERVER SERVER SERVER SERVER SERVER SERVER SERVER SERVER SERVER SERVER case GPMessageStrings.TRY_PLACE_AT: // client is trying to place at pos Vector2 pos = new Vector2(int.Parse(splitMessage[1]), int.Parse(splitMessage[2])); // If it's not server's turn try placing at pos if (!GameLogic.IsItServersTurn()) { GameLogic.WantToPlaceAt(pos); } break; // BOTH BOTH BOTH BOTH BOTH BOTH BOTH BOTH BOTH BOTH BOTH BOTH BOTH BOTH BOTH BOTH BOTH BOTH BOTH BOTH BOTH BOTH BOTH BOTH // BOTH BOTH BOTH BOTH BOTH BOTH BOTH BOTH BOTH BOTH BOTH BOTH BOTH BOTH BOTH BOTH BOTH BOTH BOTH BOTH BOTH BOTH BOTH BOTH case GPMessageStrings.SEND_MSG: BluetoothMessageManager.ShowEmojiMessage(EmojiSprites.GetEmoji(splitMessage[1])); break; } }