Beispiel #1
0
    public override void gaxb_init()
    {
        gameObject = new GameObject("<Text/>", typeof(RectTransform));

        canvasRenderer = gameObject.AddComponent <CanvasRenderer> ();
        text           = gameObject.AddComponent <Text> ();

        if (onLinkClick != null || OnLinkClickAction != null || GlobalOnLinkClickAction != null)
        {
            gameObject.AddComponent <DetectTextClick> ();
            DetectTextClick script = gameObject.GetComponent <DetectTextClick> ();
            script.entity = this;
        }

        if (title == null && value != null)
        {
            gameObject.name = string.Format("\"{0}\"", value);
        }

        if (fontColor != null)
        {
            text.color = fontColor.Value;
        }

        if (font != null)
        {
            text.font = PlanetUnityResourceCache.GetFont(font);
        }
        else
        {
            text.font = PlanetUnityResourceCache.GetFont(PlanetUnityOverride.defaultFont());
        }

        if (fontSize != null)
        {
            text.fontSize = (int)fontSize;
        }

        if (lineSpacing != null)
        {
            text.lineSpacing = lineSpacing.Value;
        }

        if (sizeToFit)
        {
            text.resizeTextForBestFit = true;
        }

        if (maxFontSize != null)
        {
            text.resizeTextMaxSize = maxFontSize.Value;
        }

        if (minFontSize != null)
        {
            text.resizeTextMinSize = minFontSize.Value;
        }

        if (vOverflow)
        {
            text.verticalOverflow = VerticalWrapMode.Overflow;
        }

        if (hOverflow)
        {
            text.horizontalOverflow = HorizontalWrapMode.Overflow;
        }

        if (fontStyle != null)
        {
            if (fontStyle == PlanetUnity2.FontStyle.bold)
            {
                text.fontStyle = FontStyle.Bold;
            }
            if (fontStyle == PlanetUnity2.FontStyle.italic)
            {
                text.fontStyle = FontStyle.Italic;
            }
            if (fontStyle == PlanetUnity2.FontStyle.normal)
            {
                text.fontStyle = FontStyle.Normal;
            }
            if (fontStyle == PlanetUnity2.FontStyle.boldAndItalic)
            {
                text.fontStyle = FontStyle.BoldAndItalic;
            }
        }

        if (alignment != null)
        {
            if (alignment == PlanetUnity2.TextAlignment.lowerCenter)
            {
                text.alignment = TextAnchor.LowerCenter;
            }
            if (alignment == PlanetUnity2.TextAlignment.lowerLeft)
            {
                text.alignment = TextAnchor.LowerLeft;
            }
            if (alignment == PlanetUnity2.TextAlignment.lowerRight)
            {
                text.alignment = TextAnchor.LowerRight;
            }
            if (alignment == PlanetUnity2.TextAlignment.middleCenter)
            {
                text.alignment = TextAnchor.MiddleCenter;
            }
            if (alignment == PlanetUnity2.TextAlignment.middleLeft)
            {
                text.alignment = TextAnchor.MiddleLeft;
            }
            if (alignment == PlanetUnity2.TextAlignment.middleRight)
            {
                text.alignment = TextAnchor.MiddleRight;
            }
            if (alignment == PlanetUnity2.TextAlignment.upperCenter)
            {
                text.alignment = TextAnchor.UpperCenter;
            }
            if (alignment == PlanetUnity2.TextAlignment.upperLeft)
            {
                text.alignment = TextAnchor.UpperLeft;
            }
            if (alignment == PlanetUnity2.TextAlignment.upperRight)
            {
                text.alignment = TextAnchor.UpperRight;
            }
        }

        if (value != null)
        {
            text.text = PlanetUnityStyle.ReplaceStyleTags(value);
        }

        text.material = new Material(Shader.Find("UI/Default Font"));
    }