/// <summary>
    /// Metodo que muestra los mensajes recibidos de otros jugadores
    /// </summary>
    /// <returns>The player message.</returns>
    /// <param name="msg">Message.</param>
    IEnumerator DisplayReceivedMessage(string msg)
    {
        GameObject chatObj = Instantiate(chatBarPrefab, Vector3.zero, Quaternion.identity) as GameObject;

        chatObj.transform.SetParent(content.transform, false);

        chatObj.SetActive(true);

        ChatListObject clb = chatObj.GetComponent <ChatListObject>();

        //string[] split  = msg.Split('~');
        //msg = split[0];

        clb.parentText.fontSize = fontSize;
        clb.childText.fontSize  = fontSize;

        clb.parentText.text = msg;

        clb.childText.color = Color.black;

        yield return(new WaitForEndOfFrame());

        float height = chatObj.GetComponent <RectTransform>().rect.height;
        float width  = chatObj.GetComponent <RectTransform>().rect.width;

        clb.chatbarImage.rectTransform.sizeDelta = new Vector2(width + 5, height + 6);
        clb.childText.rectTransform.sizeDelta    = new Vector2(width, height);

        clb.childText.text = msg;

        clb.chatbarImage.rectTransform.anchoredPosition = new Vector2(-3f,
                                                                      clb.chatbarImage.rectTransform.anchoredPosition.y);
    }
    IEnumerator ShowUserMsgCoroutine(string msg)
    {
        GameObject chatObj = Instantiate(chatBarPrefab, Vector3.zero, Quaternion.identity) as GameObject;

        chatObj.transform.SetParent(content.transform, false);

        chatObj.SetActive(true);

        ChatListObject clb = chatObj.GetComponent <ChatListObject>();

        string[] split = msg.Split('~');
        msg = split[0];

        clb.parentText.fontSize = fontSize;
        clb.childText.fontSize  = fontSize;

        clb.parentText.text = msg;

        clb.childText.color = Color.black;

        yield return(new WaitForEndOfFrame());

        float height = chatObj.GetComponent <RectTransform>().rect.height;
        float width  = chatObj.GetComponent <RectTransform>().rect.width;

        clb.chatbarImage.rectTransform.sizeDelta = new Vector2(width + 5, height + 6);
        clb.childText.rectTransform.sizeDelta    = new Vector2(width, height);

        //clb.senderName.text = "Santa Claus";
        clb.childText.text = msg;
        // clb.childText.rectTransform.anchoredPosition();

        if (split[1] == "0")
        {
            clb.chatbarImage.color = user1ImageColor;

            clb.chatbarImage.sprite = user1ChatBarSprite;

            clb.chatbarImage.rectTransform.anchoredPosition = new Vector2(-3f,
                                                                          clb.chatbarImage.rectTransform.anchoredPosition.y);
        }
        else if (split[1] == "1")
        {
            clb.chatbarImage.color = user2ImageColor;

            clb.chatbarImage.sprite = user2ChatBarSprite;

            clb.chatbarImage.rectTransform.anchoredPosition = new Vector2(
                ((content.GetComponent <RectTransform>().rect.width -
                  (verticalLayoutGroup.padding.left + verticalLayoutGroup.padding.right))
                 - chatObj.GetComponent <RectTransform>().rect.width)
                , clb.chatbarImage.rectTransform.anchoredPosition.y);
        }
    }
示例#3
0
    IEnumerator ShowUserMsgCoroutine(string msg)
    {
        GameObject chatObj = Instantiate(chatBarPrefab, Vector3.zero, Quaternion.identity) as GameObject;

        chatObj.transform.SetParent(content.transform, false);

        chatObj.SetActive(true);

        ChatListObject clb = chatObj.GetComponent <ChatListObject>();

        fontSize = (int)(Screen.height * 0.025f); //FontSize

        clb.parentText.fontSize = fontSize;
        clb.childText.fontSize  = fontSize;

        clb.parentText.text = msg;

        clb.childText.color = Color.black;

        yield return(new WaitForEndOfFrame());

        float height = chatObj.GetComponent <RectTransform>().rect.height;
        float width  = chatObj.GetComponent <RectTransform>().rect.width;

        clb.chatbarImage.rectTransform.sizeDelta = new Vector2(width + 80, height + 80);

        clb.childText.rectTransform.sizeDelta = new Vector2(width, height);
        clb.childText.rectTransform.position  = new Vector2(clb.childText.rectTransform.position.x + 30, clb.childText.rectTransform.position.y - 30);

        clb.childText.text = msg;

        clb.chatbarImage.color = new Color(userImageColor.r, userImageColor.g, userImageColor.b, 1);
        clb.userImage.sprite   = userSprite;

        clb.chatbarImage.sprite = userChatBarSprite;

        clb.userImage.transform.parent.GetComponent <RectTransform>().anchoredPosition = new Vector2(0, clb.userImage.transform.parent.GetComponent <RectTransform>().anchoredPosition.y);
        clb.chatbarImage.rectTransform.anchoredPosition = new Vector2(-3f, clb.chatbarImage.rectTransform.anchoredPosition.y);
    }