예제 #1
0
    void FitScreen(GameObject tempGo)
    {
        //适应聊天框
        InlieText tempChatText = tempGo.transform.Find("content").GetComponent <InlieText>();

        if (tempChatText.preferredWidth + 10.0f < minWidth)  //单行长度太短
        {
            tempGo.GetComponent <RectTransform>().sizeDelta       = new Vector2(minWidth, tempChatText.preferredHeight + 20.0f);
            tempChatText.GetComponent <RectTransform>().sizeDelta = new Vector2(minWidth, tempChatText.preferredHeight + 20.0f);
        }
        else if (tempChatText.preferredWidth + 10.0f > maxWidth)  //单行长度太长
        {
            tempGo.GetComponent <RectTransform>().sizeDelta       = new Vector2(maxWidth, tempChatText.preferredHeight + 20.0f);
            tempChatText.GetComponent <RectTransform>().sizeDelta = new Vector2(maxWidth - 10.0f, tempChatText.preferredHeight + 20.0f);
        }
        else  //让文字自适应聊天框
        {
            tempGo.GetComponent <RectTransform>().sizeDelta       = new Vector2(tempChatText.preferredWidth + 10.0f, tempChatText.preferredHeight + 20.0f);
            tempChatText.GetComponent <RectTransform>().sizeDelta = new Vector2(tempChatText.preferredWidth, tempChatText.preferredHeight + 20.0f);
        }

        tempChatText.SetVerticesDirty();                                                       //???作用未知
        tempGo.GetComponent <RectTransform>().anchoredPosition = new Vector3(0f, -chatHeight); //设置anchored,别人的在左边,自己的在右边
        chatHeight += (tempChatText.preferredHeight + 20.0f) + iconHeight + 10.0f;             //增加chatHeight高度,包括文字背景,icon和间隔
        if (chatHeight > chatItemParent.GetComponent <RectTransform>().sizeDelta.y)            //超出父容器,让父容器扩大
        {
            chatItemParent.GetComponent <RectTransform>().sizeDelta = new Vector2(chatItemParent.GetComponent <RectTransform>().sizeDelta.x, chatHeight);
        }
    }
예제 #2
0
    void ClickSendMessageBtn()
    {
        if (inputText.text.Trim() == null || inputText.text.Trim() == "")
        {
            return;
        }

        GameObject tempChatItem = Instantiate(goprefab) as GameObject;

        tempChatItem.transform.parent     = goContent.transform;
        tempChatItem.transform.localScale = Vector3.one;
        InlieText tempChatText = tempChatItem.transform.FindChild("Text").GetComponent <InlieText>();

        #region 解析输入表情正则
        string _TempInputText  = "";
        int    _TempMatchIndex = 0;
        foreach (Match match in m_inputTagRegex.Matches(inputText.text.Trim()))
        {
            _TempInputText += inputText.text.Trim().Substring(_TempMatchIndex, match.Index - _TempMatchIndex);
            _TempInputText += "<quad name=" + match.Groups[1].Value + " size=56 width=1" + " />";
            _TempMatchIndex = match.Index + match.Length;
        }
        _TempInputText += inputText.text.Trim().Substring(_TempMatchIndex, inputText.text.Trim().Length - _TempMatchIndex);
        #endregion

        tempChatText.text = _TempInputText;
        if (tempChatText.preferredWidth + 20.0f < 105.0f)
        {
            tempChatItem.GetComponent <RectTransform>().sizeDelta = new Vector2(105.0f, tempChatText.preferredHeight + 50.0f);
        }
        else if (tempChatText.preferredWidth + 20.0f > tempChatText.rectTransform.sizeDelta.x)
        {
            tempChatItem.GetComponent <RectTransform>().sizeDelta = new Vector2(tempChatText.rectTransform.sizeDelta.x + 20.0f, tempChatText.preferredHeight + 50.0f);
        }
        else
        {
            tempChatItem.GetComponent <RectTransform>().sizeDelta = new Vector2(tempChatText.preferredWidth + 20.0f, tempChatText.preferredHeight + 50.0f);
        }

        tempChatItem.SetActive(true);
        tempChatText.SetVerticesDirty();
        tempChatItem.GetComponent <RectTransform>().anchoredPosition = new Vector3(-10.0f, -chatHeight);
        chatHeight += tempChatText.preferredHeight + 50.0f + PlayerHight + 10.0f;
        if (chatHeight > goContent.GetComponent <RectTransform>().sizeDelta.y)
        {
            goContent.GetComponent <RectTransform>().sizeDelta = new Vector2(goContent.GetComponent <RectTransform>().sizeDelta.x, chatHeight);
        }
        //while (scrollbarVertical.value > 0.01f)
        //{
        //    scrollbarVertical.value = 0.0f;
        //}
        isAddMessage   = true;
        inputText.text = "";
    }
예제 #3
0
    void AutoTalk()
    {
        string[] emojiTextName = new string[] { "sick", "watermelon", "run", "die", "angry", "bleeding", "nurturing", "idle" };
        string   strTalk       = "按下F1,我会自动说话:<quad name=" + emojiTextName[Random.Range(0, emojiTextName.Length)] + " size=56 width=1 />,show一个emoji";

        GameObject tempChatItem = Instantiate(goprefab_left) as GameObject;

        tempChatItem.transform.parent     = goContent.transform;
        tempChatItem.transform.localScale = Vector3.one;
        InlieText tempChatText = tempChatItem.transform.FindChild("Text").GetComponent <InlieText>();

        tempChatText.text = strTalk;
        if (tempChatText.preferredWidth + 20.0f < 105.0f)
        {
            tempChatItem.GetComponent <RectTransform>().sizeDelta = new Vector2(105.0f, tempChatText.preferredHeight + 50.0f);
        }
        else if (tempChatText.preferredWidth + 20.0f > tempChatText.rectTransform.sizeDelta.x)
        {
            tempChatItem.GetComponent <RectTransform>().sizeDelta = new Vector2(tempChatText.rectTransform.sizeDelta.x + 20.0f, tempChatText.preferredHeight + 50.0f);
        }
        else
        {
            tempChatItem.GetComponent <RectTransform>().sizeDelta = new Vector2(tempChatText.preferredWidth + 20.0f, tempChatText.preferredHeight + 50.0f);
        }

        tempChatItem.SetActive(true);
        tempChatText.SetVerticesDirty();
        tempChatItem.GetComponent <RectTransform>().anchoredPosition = new Vector3(10.0f, -chatHeight);
        chatHeight += tempChatText.preferredHeight + 50.0f + PlayerHight + 10.0f;
        if (chatHeight > goContent.GetComponent <RectTransform>().sizeDelta.y)
        {
            goContent.GetComponent <RectTransform>().sizeDelta = new Vector2(goContent.GetComponent <RectTransform>().sizeDelta.x, chatHeight);
        }
        //while (scrollbarVertical.value > 0.01f)
        //{
        //    scrollbarVertical.value = 0.0f;
        //}
        isAddMessage = true;
    }