Esempio n. 1
0
        public static void CreatePopupText(
            string text,
            float popupSpeed      = 20f,
            float disappearSpeed  = 1f,
            Transform parent      = null,
            Vector3 localPosition = default(Vector3),
            Camera?cameraToFace   = null,
            int fontSize          = 15,
            Color?color           = null,
            Color?outlineColor    = null,
            float outlineWidth    = 0.2f,
            Vector2 textAnchor    = default(Vector2),
            TMPro.TextAlignmentOptions textAlignment = TMPro.TextAlignmentOptions.Midline,
            int sortingOrder = 5000)
        {
            Color textColor        = (color == null) ? Color.white : (Color)color;
            Color textOutlineColor = (outlineColor == null) ? Color.black : (Color)color;

            GameObject popupText = new GameObject("Popup_Text", typeof(TextMeshPro));

            if (cameraToFace != null)
            {
                popupText.transform.LookAt(cameraToFace.transform);
                popupText.transform.rotation = Quaternion.LookRotation(cameraToFace.transform.forward);
            }

            Transform transform = popupText.transform;

            transform.SetParent(parent, false);

            TextMeshPro textMeshPro = popupText.GetComponent <TextMeshPro>();

            textMeshPro.rectTransform.sizeDelta        = new Vector2(0.1f, 0.1f);
            textMeshPro.enableWordWrapping             = false;
            textMeshPro.rectTransform.position         = localPosition;
            textMeshPro.rectTransform.anchoredPosition = textAnchor;
            textMeshPro.alignment    = textAlignment;
            textMeshPro.fontSize     = fontSize;
            textMeshPro.text         = text;
            textMeshPro.overflowMode = TextOverflowModes.Overflow;
            textMeshPro.faceColor    = textColor;
            Material mat = textMeshPro.fontSharedMaterial;

            mat.shaderKeywords       = new string[] { "OUTLINE_ON" };
            textMeshPro.outlineColor = textOutlineColor;
            textMeshPro.outlineWidth = outlineWidth;
            textMeshPro.color        = Color.white;
            textMeshPro.GetComponent <MeshRenderer>().sortingOrder = sortingOrder;

            popupText.AddComponent <PopupText>().StartPopup(textMeshPro, localPosition, popupSpeed, disappearSpeed);
        }
Esempio n. 2
0
        static TextAnchor TMPTextAlignToTextAnchor(TMPro.TextAlignmentOptions align)
        {
            if (align == TMPro.TextAlignmentOptions.Bottom)
            {
                return(TextAnchor.LowerCenter);
            }
            else if (align == TMPro.TextAlignmentOptions.BottomLeft)
            {
                return(TextAnchor.LowerLeft);
            }
            else if (align == TMPro.TextAlignmentOptions.BottomRight)
            {
                return(TextAnchor.LowerRight);
            }
            if (align == TMPro.TextAlignmentOptions.Top)
            {
                return(TextAnchor.UpperCenter);
            }
            else if (align == TMPro.TextAlignmentOptions.TopLeft)
            {
                return(TextAnchor.UpperLeft);
            }
            else if (align == TMPro.TextAlignmentOptions.TopRight)
            {
                return(TextAnchor.UpperRight);
            }
            else if (align == TMPro.TextAlignmentOptions.Left)
            {
                return(TextAnchor.MiddleLeft);
            }
            else if (align == TMPro.TextAlignmentOptions.Right)
            {
                return(TextAnchor.MiddleRight);
            }

            return(TextAnchor.MiddleCenter);
        }