/// <summary> /// Called by children when they were pressed /// </summary> public void ButtonPressed(string name) { if (OnEmojiChosen != null) { OnEmojiChosen(EmojiSprites.GetEmoji(name), currentSlot); } SetEnabled(name); }
/// <summary> /// Send a message via bluetooth /// </summary> public virtual void SendMessage(MessagePickerMessageWithUI mpm) { // Show it for yourself // Not emoji -> show text message BluetoothMessageManager.ShowEmojiMessage(EmojiSprites.GetEmoji(mpm.message), true); // Send it vie bluetooth Bluetooth.Instance().Send(BluetoothMessageStrings.SEND_MESSAGE + "#" + mpm.message); }
public override void SendMessage(MessagePickerMessageWithUI mpm) { // Show it for yourself // Not emoji -> show text message BluetoothMessageManager.ShowEmojiMessage(EmojiSprites.GetEmoji(mpm.message), true); // Send it via gp PlayGamesPlatform.Instance.RealTime.SendMessageToAll(true, System.Text.Encoding.Unicode.GetBytes(GPMessageStrings.SEND_MSG + "#" + mpm.message)); }
public Sprite[] GetEmojiSprites() { Sprite[] s = new Sprite[EMOJI_COUNT]; for (int i = 0; i < s.Length; i++) { s[i] = EmojiSprites.GetEmoji(PlayerPrefs.GetString(EMOJI_NAME + i)); } return(s); }
public void SetUnlockable(Unlockable unlockable) { this.unlockable = unlockable; switch (unlockable.type) { case UnlockableType.Emoji: openParticle = Instantiate(Resources.Load <GameObject>("Prefabs/Particles/EmojiParticle"), brokenParticle.gameObject.transform, false) .GetComponent <ParticleSystem>(); rewardImage.sprite = EmojiSprites.GetEmoji(unlockable.extra); text.text = "New emoji!"; break; case UnlockableType.Bluetooth: openParticle = Instantiate(Resources.Load <GameObject>("Prefabs/Particles/BluetoothParticle"), brokenParticle.gameObject.transform, false) .GetComponent <ParticleSystem>(); rewardImage.sprite = Resources.Load <Sprite>("Textures/GUI/BluetoothIcob"); rewardImage.color = new Color(0.24706f, 0.31765f, 0.7098f); text.text = "Bluetooth mode unlocked!"; break; // TODO change these to something else because this sucks case UnlockableType.EmojiSlot: openParticle = Instantiate(Resources.Load <GameObject>("Prefabs/Particles/EmojiParticle"), brokenParticle.gameObject.transform, false) .GetComponent <ParticleSystem>(); rewardImage.sprite = Resources.Load <Sprite>("Textures/emojiSlotUnlock"); text.text = "New slot for emojis!"; break; case UnlockableType.LocalMulti: rewardImage.sprite = Resources.Load <Sprite>("Textures/localMultiUnlock"); rewardImage.color = Color.white; text.text = "Local multiplayer unlocked!"; break; case UnlockableType.GooglePlay: rewardImage.sprite = Resources.Load <Sprite>("Textures/gpUnlock"); rewardImage.color = Color.white; text.text = "Google play multiplayer unlocked!"; break; } }
void InitMessagePickerUI() { float oneMessageRad = Mathf.PI / messages.Length; // How much degree of a half circle one message gets float radOfMessage = Mathf.PI / 2 - oneMessageRad / 2f; // Where the first message is for (int i = 0; i < messages.Length; i++) { // this is caluclated by trigonometry, the x coordinate of the message float x = Mathf.Sqrt(textCircleRadius * textCircleRadius / (1 + Mathf.Pow(Mathf.Tan(radOfMessage), 2))); // the y coordinate of the message float y = Mathf.Tan(radOfMessage) * x; // Make text gameobject GameObject go; go = Instantiate(imgPrefab, transform, false); go.name = messages[i].message; // set image Image img = go.GetComponent <Image>(); img.sprite = EmojiSprites.GetEmoji(messages[i].message); messages[i].rectTransform = go.GetComponent <RectTransform>(); messages[i].rectTransform.localScale = new Vector3(); // By default the messages are inside the the message icon so we can animate them out // Store message's pos messages[i].onCirclePosition = new Vector3(x, y); // Store message's degrees messages[i].toRad = radOfMessage + oneMessageRad / 2f; messages[i].fromRad = messages[i].toRad - oneMessageRad; // Shift next message this amount radOfMessage -= oneMessageRad; } }
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; } }
/// <summary> /// Done reading the message event /// </summary> /// <param name="readMessage"></param> void DoneReadingEvent(string readMessage) { string[] differentMessages = readMessage.Split(new string[] { "|||" }, StringSplitOptions.None); for (int i = 0; i < differentMessages.Length - 1; i++) { string[] splitMessage = differentMessages[i].Split('#'); // SERVER SERVER SERVER SERVER SERVER SERVER SERVER SERVER SERVER SERVER // SERVER SERVER SERVER SERVER SERVER SERVER SERVER SERVER SERVER SERVER if (isServer) { switch (splitMessage[0]) { case "CLIENTREADY": // client sends he is ready isClientReady = bool.Parse(splitMessage[1]); CheckAllReady(); break; case "TRYPLACEAT": // 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; case "WHOSETURN": // Client is asking for whose turn it is Bluetooth.Instance().Send(BluetoothMessageStrings.TURN_OF + "#" + gameLogic.WhoseTurn.ToString()); break; case "SMB": // Client is asking for latest border data Bluetooth.Instance().Send(BluetoothMessageStrings.ADD_BORDER + "#" + lastBorder.ToString() + "#" + lastBorderID); break; } // CLIENT CLIENT CLIENT CLIENT CLIENT CLIENT CLIENT CLIENT CLIENT // CLIENT CLIENT CLIENT CLIENT CLIENT CLIENT CLIENT CLIENT CLIENT } else { switch (splitMessage[0]) { case "STARTGAME": // Server sends that the game has been started // Switch scenes ScaneManager.Instance.GoToScene("ClientBluetoothGame"); break; case "WLP": // Server sends where last sign has been placed int[] lastPos = new int[] { int.Parse(splitMessage[1]), int.Parse(splitMessage[2]) }; if (!(lastPos[0] == lastSignPlaced[0] && lastPos[1] == lastSignPlaced[1])) { secondToLastSignPlaced[0] = lastSignPlaced[0]; secondToLastSignPlaced[1] = lastSignPlaced[1]; lastSignPlaced[0] = lastPos[0]; lastSignPlaced[1] = lastPos[1]; // Store new sign pos as last sign Cell.CellOcc lastType = (Cell.CellOcc)Enum.Parse(typeof(Cell.CellOcc), splitMessage[3]); // Place sign locally ClientCellStrg.PlaceCellAt(lastPos, lastType); } break; case "LBI": // Server sends what the last border's bluetooth id is // The server has a newer border placed if (lastBorderID != int.Parse(splitMessage[1])) { Bluetooth.Instance().Send(BluetoothMessageStrings.SEND_ME_BORDER); } break; case "TURNOF": // Server sends whose turn it is Cell.CellOcc whoseTurn = (Cell.CellOcc)Enum.Parse(typeof(Cell.CellOcc), splitMessage[1]); ClientUIInScript.UpdateImage(whoseTurn); break; case "ADDBORDER": // Server sends border data // set lates bluetooth border id lastBorderID = int.Parse(splitMessage[splitMessage.Length - 1]); // 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)Enum.Parse(typeof(Cell.CellOcc), splitMessage[6 + countOfPoints * 2]); BluetoothClientBorder.AddBorderPoints(points, winLine, winType); // Because a border was added someone won the game so call the event ClientCellStrg.SomeoneWon(winType); break; case "JPT": // Server sends to jump to this pos because new game has been started 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 "SSCR": int xScore = int.Parse(splitMessage[1]); int oScore = int.Parse(splitMessage[2]); Scoring.SetScore(xScore, oScore); 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 switch (splitMessage[0]) { case "SMSG": BluetoothMessageManager.ShowEmojiMessage(EmojiSprites.GetEmoji(splitMessage[1])); break; } } }
void Start() { rect = GetComponent <RectTransform>(); messageOnDrawerPrefab = Resources.Load <GameObject>("Prefabs/Bluetooth/Messaging/MessageOnDrawer"); scrollRect = transform.parent.GetComponent <ScrollRect>(); emojisByText = transform.GetChild(0).GetComponent <TextMeshProUGUI>(); // adding images to drawer fomr here // only include unlocked emojis List <string> unlockedEmojis = new List <string>(); for (int i = 0; i < EmojiSprites.emojiPaths.Length; i++) { if (PreferencesScript.Instance.IsEmojiUnlocked(i)) { unlockedEmojis.Add(EmojiSprites.emojiPaths[i]); } } colCount = (int)(rect.rect.width / widthHeight) - 1; // -1 so we can have some padding around the images rowCount = Mathf.CeilToInt((float)unlockedEmojis.Count / colCount); // Height of whole thing realHeight = (rowCount + 1) * widthHeight + emojisByText.rectTransform.rect.height; rect.sizeDelta = new Vector2(rect.rect.width, realHeight); imagePadding = (rect.rect.width - (widthHeight * colCount)) / (colCount + 1); // plus one so we can have pad on the most left side as well int at = 0; float xPos; float yPos = -imagePadding; // Going from left to right, top to bottom for (int i = 0; i < rowCount && at < unlockedEmojis.Count; i++) { xPos = imagePadding; for (int k = 0; k < colCount && at < unlockedEmojis.Count; k++) { // making gameobject GameObject msg = Instantiate(messageOnDrawerPrefab, transform, false); msg.name = unlockedEmojis[at]; // Setting size and pos RectTransform msgrect = msg.GetComponent <RectTransform>(); msgrect.sizeDelta = new Vector2(widthHeight, widthHeight); msgrect.anchoredPosition = new Vector2(xPos, yPos); // Setting sprite Image img = msg.transform.GetChild(1).GetComponent <Image>(); img.sprite = EmojiSprites.GetEmoji(msg.name); img.color = disabledColor; // Incrementing variables at++; xPos += (widthHeight + imagePadding); } yPos -= (widthHeight + imagePadding); } // Set it to top scrollRect.verticalNormalizedPosition = 0.95f; }
public Sprite GetEmojiSpriteInSlot(int slot) { return(EmojiSprites.GetEmoji(PlayerPrefs.GetString(EMOJI_NAME + slot))); }