示例#1
0
        static public GameObject AddUnderlineByText(GameObject parent, GameObject prefab,
                                                    UIEventTriggerListener.VoidDelegate _Click)
        {
            GameObject res = Resources.Load("Prefabs/MouseBlock") as GameObject;

            GameObject go         = AddChild(parent, prefab);
            GameObject mouseBlock = AddChild(go, res); //刷入的是换鼠标的碰撞

            UnityEngine.UI.Text _underline = go.GetComponent <UnityEngine.UI.Text>();
            UnityEngine.UI.Text parenttext = parent.GetComponent <UnityEngine.UI.Text>();
            int length = parenttext.text.Length;

            _underline.text = "";
            for (int i = 0; i < length * 2; i++)
            {
                _underline.text += "_";
            }
            //Debug.Log(" _underline.flexibleHeight" + _underline.flexibleHeight);

            TextGenerator          m_TextGenerator          = _underline.cachedTextGeneratorForLayout;
            TextGenerationSettings m_TextGenerationSettings = _underline.GetGenerationSettings(Vector2.zero);
            float fWidth = m_TextGenerator.GetPreferredWidth(_underline.text, m_TextGenerationSettings);

            m_TextGenerationSettings =
                _underline.GetGenerationSettings(new Vector2(_underline.rectTransform.rect.x, 0.0f));
            float fHeight = m_TextGenerator.GetPreferredHeight(_underline.text, m_TextGenerationSettings);

            // mouseBlock.GetComponent<MouseImageControl>()._callback = _Click;
            SetTransformSize(mouseBlock, new Vector2(fWidth, fHeight));
            //mouseBlock.GetComponent<Rect>()
            _underline.rectTransform.anchorMin = Vector2.zero;
            _underline.rectTransform.anchorMax = Vector2.one;
            _underline.rectTransform.offsetMax = Vector2.zero;
            _underline.rectTransform.offsetMin = Vector2.zero;
            return(go);
        }
示例#2
0
 /// <summary>
 /// 给label添加下划线
 /// </summary>
 /// <param name="label"></param>
 /// <returns></returns>
 static public GameObject AddUnderlineByText(GameObject label, UIEventTriggerListener.VoidDelegate _Click)
 {
     return(AddUnderlineByText(label, label, _Click));
 }