Пример #1
0
        public void SetHeight(float fNewHeight)
        {
            // doesn't support textmeshpro text...

            TextMesh tm = go.GetComponent <TextMesh>();

            tm.transform.localScale = Vector3f.One;
            Vector2f size    = UnityUtil.EstimateTextMeshDimensions(tm);
            float    fScaleH = fNewHeight / size.y;

            tm.transform.localScale = new Vector3(fScaleH, fScaleH, fScaleH);
            size = new Vector2f(fScaleH * size.x, fNewHeight);
        }
Пример #2
0
        public List <fGameObject> Generate()
        {
            var gameObj = new GameObject("label");

            TextMesh tm = gameObj.AddComponent <TextMesh>();

            tm.text      = Text;
            tm.color     = Color;
            tm.fontSize  = 50;
            tm.offsetZ   = ZOffset;
            tm.alignment = TextAlign;

            // [RMS] this isn't quite right, on the vertical centering...
            Vector2f size         = UnityUtil.EstimateTextMeshDimensions(tm);
            Vector3  vCenterShift = Vector3f.Zero;

            if (Align == Alignment.HCenter || Align == Alignment.HVCenter)
            {
                vCenterShift.x -= size.x * 0.5f;
            }
            if (Align == Alignment.VCenter || Align == Alignment.HVCenter)
            {
                vCenterShift.y += size.y * 0.5f;
            }

            // apply orientation
            float useScale = Scale;

            tm.transform.localScale     = new Vector3(useScale, useScale, useScale);
            tm.transform.localPosition += useScale * vCenterShift;
            tm.transform.localPosition += Translate;

            // ignore material changes when we add to GameObjectSet
            gameObj.AddComponent <IgnoreMaterialChanges>();

            // use our textmesh material instead
            // [TODO] can we share between texts?
            MaterialUtil.SetTextMeshDefaultMaterial(tm);

            return(new List <fGameObject>()
            {
                gameObj
            });
        }
Пример #3
0
        public void SetHeight(float fNewHeight)
        {
            switch (eType)
            {
            case TextType.UnityTextMesh: {
                TextMesh tm = (text_component as TextMesh);
                tm.transform.localScale = Vector3f.One;
                Vector2f size    = UnityUtil.EstimateTextMeshDimensions(tm);
                float    fScaleH = fNewHeight / size.y;
                tm.transform.localScale = new Vector3(fScaleH, fScaleH, fScaleH);
                size = new Vector2f(fScaleH * size.x, fNewHeight);
            }
            break;

            case TextType.TextMeshPro:
#if G3_ENABLE_TEXT_MESH_PRO
                (text_component as TextMeshProExt).SetTextSizeFromHeight(fNewHeight);
#endif
                break;
            }
        }
Пример #4
0
        public static fTextGameObject CreateUnityTextMeshGO(
            string sName, string sText,
            Colorf textColor, float fTextHeight,
            BoxPosition textOrigin = BoxPosition.Center,
            float fOffsetZ         = -0.1f)
        {
            GameObject textGO = new GameObject(sName);
            TextMesh   tm     = textGO.AddComponent <TextMesh>();

            tm.text      = sText;
            tm.color     = textColor;
            tm.fontSize  = 50;
            tm.offsetZ   = fOffsetZ;
            tm.alignment = TextAlignment.Left;
            // ignore material changes when we add to GameObjectSet
            textGO.AddComponent <IgnoreMaterialChanges>();
            // use our textmesh material instead
            MaterialUtil.SetTextMeshDefaultMaterial(tm);

            Vector2f size    = UnityUtil.EstimateTextMeshDimensions(tm);
            float    fScaleH = fTextHeight / size.y;

            tm.transform.localScale = new Vector3(fScaleH, fScaleH, fScaleH);
            float fTextWidth = fScaleH * size.x;

            // by default text origin is top-left
            if (textOrigin == BoxPosition.Center)
            {
                tm.transform.Translate(-fTextWidth / 2.0f, fTextHeight / 2.0f, 0);
            }
            else if (textOrigin == BoxPosition.BottomLeft)
            {
                tm.transform.Translate(0, fTextHeight, 0);
            }
            else if (textOrigin == BoxPosition.TopRight)
            {
                tm.transform.Translate(-fTextWidth, 0, 0);
            }
            else if (textOrigin == BoxPosition.BottomRight)
            {
                tm.transform.Translate(-fTextWidth, fTextHeight, 0);
            }
            else if (textOrigin == BoxPosition.CenterLeft)
            {
                tm.transform.Translate(0, fTextHeight / 2.0f, 0);
            }
            else if (textOrigin == BoxPosition.CenterRight)
            {
                tm.transform.Translate(-fTextWidth, fTextHeight / 2.0f, 0);
            }
            else if (textOrigin == BoxPosition.CenterTop)
            {
                tm.transform.Translate(-fTextWidth / 2.0f, 0, 0);
            }
            else if (textOrigin == BoxPosition.CenterBottom)
            {
                tm.transform.Translate(-fTextWidth / 2.0f, fTextHeight, 0);
            }

            textGO.GetComponent <Renderer>().material.renderQueue = SceneGraphConfig.TextRendererQueue;

            return(new fTextGameObject(textGO, new fText(tm, TextType.UnityTextMesh),
                                       new Vector2f(fTextWidth, fTextHeight)));
        }