Exemplo n.º 1
0
        internal void CheckAndUpdate()
        {
            if (newText.Length > 0)
            {
                if (guiText == null)
                {
                    GameObject anchorObject = new GameObject(anchor.ToString(), typeof(GUIText));
                    guiText = anchorObject.GetComponent <GUIText>();
                    if (guiText == null)
                    {
                        return;
                    }
                    if (anchor == LabelAnchor.UpperLeft)
                    {
                        anchorObject.transform.position = new Vector3(0f, 1f);
                        guiText.anchor    = TextAnchor.UpperLeft;
                        guiText.alignment = TextAlignment.Left;
                    }
                    else if (anchor == LabelAnchor.UpperRight)
                    {
                        anchorObject.transform.position = new Vector3(1f, 1f);
                        guiText.anchor    = TextAnchor.UpperRight;
                        guiText.alignment = TextAlignment.Right;
                    }
                    else if (anchor == LabelAnchor.LowerLeft)
                    {
                        anchorObject.transform.position = new Vector3(0.0f, 0.3f);
                        guiText.anchor    = TextAnchor.LowerLeft;
                        guiText.alignment = TextAlignment.Left;
                    }
                    else if (anchor == LabelAnchor.LowerRight)
                    {
                        anchorObject.transform.position = new Vector3(1f, 0f);
                        guiText.anchor    = TextAnchor.LowerRight;
                        guiText.alignment = TextAlignment.Right;
                    }

                    guiText.pixelOffset = pixelOffset;
                    guiText.font        = font;
                    guiText.fontSize    = fontSize;
                    guiText.lineSpacing = lineSpacing;

                    anchorObject.layer            = AFPSCounter.Instance.gameObject.layer;
                    anchorObject.tag              = AFPSCounter.Instance.gameObject.tag;
                    anchorObject.transform.parent = AFPSCounter.Instance.transform;
                }

                if (dirty)
                {
                    guiText.text = newText.ToString();
                    dirty        = false;
                }
                newText.Length = 0;
            }
            else if (guiText != null)
            {
                Object.DestroyImmediate(guiText.gameObject);
            }
        }
Exemplo n.º 2
0
        // ----------------------------------------------------------------------------
        // internal methods
        // ----------------------------------------------------------------------------

        internal void CheckAndUpdate()
        {
            if (newText.Length > 0)
            {
                if (uiText == null)
                {
                    /* create label game object and configure it */
                    labelGameObject = new GameObject(anchor.ToString(), typeof(RectTransform));
                    labelTransform  = labelGameObject.GetComponent <RectTransform>();
                    labelFitter     = labelGameObject.AddComponent <ContentSizeFitter>();

                    labelFitter.horizontalFit = ContentSizeFitter.FitMode.PreferredSize;
                    labelFitter.verticalFit   = ContentSizeFitter.FitMode.PreferredSize;

                    labelGroup = labelGameObject.AddComponent <HorizontalLayoutGroup>();

                    labelGameObject.layer = container.layer;
                    labelGameObject.tag   = container.tag;
                    labelGameObject.transform.SetParent(container.transform, false);

                    uiTextGameObject = new GameObject("Text", typeof(Text));
                    uiTextGameObject.transform.SetParent(labelGameObject.transform, false);

                    /* create UI Text component and apply settings */
                    uiText = uiTextGameObject.GetComponent <Text>();

                    uiText.horizontalOverflow = HorizontalWrapMode.Overflow;
                    uiText.verticalOverflow   = VerticalWrapMode.Overflow;

                    ApplyShadow();
                    ApplyOutline();
                    ApplyFont();
                    uiText.fontSize    = fontSize;
                    uiText.lineSpacing = lineSpacing;

                    UpdateTextPosition();
                    ApplyBackground();
                }

                if (dirty)
                {
                    uiText.text = newText.ToString();
                    ApplyBackground();
                    dirty = false;
                }
                newText.Length = 0;
            }
            else if (uiText != null)
            {
                Clear();
            }
        }
Exemplo n.º 3
0
        // ----------------------------------------------------------------------------
        // internal methods
        // ----------------------------------------------------------------------------

        internal void CheckAndUpdate()
        {
            if (newText.Length > 0)
            {
                if (uiText == null)
                {
                    /* create label game object and configure it */
                    labelGameObject = new GameObject(anchor.ToString(), typeof(RectTransform));
                    labelTransform  = labelGameObject.GetComponent <RectTransform>();

                    labelGameObject.layer = container.layer;
                    labelGameObject.tag   = container.tag;
                    labelGameObject.transform.SetParent(container.transform, false);

                    uiTextGameObject = new GameObject("Text", typeof(Text));
                    uiTextGameObject.transform.SetParent(labelGameObject.transform, false);

                    var textRectTransform = (RectTransform)uiTextGameObject.transform;
                    textRectTransform.anchorMin = Vector2.zero;
                    textRectTransform.anchorMax = Vector2.one;
                    textRectTransform.sizeDelta = Vector2.zero;

                    /* create UI Text component and apply settings */
                    uiText = uiTextGameObject.GetComponent <Text>();

                    uiText.horizontalOverflow = HorizontalWrapMode.Overflow;
                    uiText.verticalOverflow   = VerticalWrapMode.Overflow;

                    ApplyShadow();
                    ApplyOutline();
                    ApplyFont();
                    uiText.fontSize    = fontSize;
                    uiText.lineSpacing = lineSpacing;

                    UpdateTextPosition();
                    ApplyBackground();
                }

                if (dirty)
                {
                    uiText.text = newText.ToString();
                    ApplyBackground();
                    dirty = false;
                }
                newText.Length = 0;
            }
            else if (uiText != null)
            {
                Clear();
            }
        }
Exemplo n.º 4
0
        // ----------------------------------------------------------------------------
        // internal methods
        // ----------------------------------------------------------------------------

        internal void CheckAndUpdate()
        {
            if (newText.Length > 0)
            {
                if (uiText == null)
                {
                    /* create label game object and configure it */
                    labelGameObject = new GameObject(anchor.ToString());

                    labelGameObject.layer = container.layer;
                    labelGameObject.tag   = container.tag;
                    labelGameObject.transform.SetParent(container.transform, false);

                    /* create UI Text component and apply settings */
                    uiText          = labelGameObject.AddComponent <Text>();
                    uiTextTransform = uiText.rectTransform;

                    uiText.horizontalOverflow = HorizontalWrapMode.Overflow;
                    uiText.verticalOverflow   = VerticalWrapMode.Overflow;

                    ApplyShadow();
                    ApplyOutline();
                    ApplyFont();
                    uiText.fontSize    = fontSize;
                    uiText.lineSpacing = lineSpacing;

                    UpdateTextPosition();
                }

                if (dirty)
                {
                    uiText.text = newText.ToString();
                    dirty       = false;
                }
                newText.Length = 0;
            }
            else if (uiText != null)
            {
                Object.DestroyImmediate(uiText.gameObject);
            }
        }
Exemplo n.º 5
0
        internal void CheckAndUpdate()
        {
            if (newText.Length > 0)
            {
                if (guiText == null)
                {
                    GameObject anchorObject = new GameObject(anchor.ToString());
                    guiText = anchorObject.AddComponent <GUIText>();

                    if (anchor == LabelAnchor.UpperLeft)
                    {
                        anchorObject.transform.position = new Vector3(0f, 1f);
                        guiText.anchor    = TextAnchor.UpperLeft;
                        guiText.alignment = TextAlignment.Left;
                    }
                    else if (anchor == LabelAnchor.UpperRight)
                    {
                        anchorObject.transform.position = new Vector3(1f, 1f);
                        guiText.anchor    = TextAnchor.UpperRight;
                        guiText.alignment = TextAlignment.Right;
                    }
                    else if (anchor == LabelAnchor.LowerLeft)
                    {
                        anchorObject.transform.position = new Vector3(0f, 0f);
                        guiText.anchor    = TextAnchor.LowerLeft;
                        guiText.alignment = TextAlignment.Left;
                    }
                    else if (anchor == LabelAnchor.LowerRight)
                    {
                        anchorObject.transform.position = new Vector3(1f, 0f);
                        guiText.anchor    = TextAnchor.LowerRight;
                        guiText.alignment = TextAlignment.Right;
                    }
                    else if (anchor == LabelAnchor.UpperCenter)
                    {
                        anchorObject.transform.position = new Vector3(0.5f, 1f);
                        guiText.anchor    = TextAnchor.UpperCenter;
                        guiText.alignment = TextAlignment.Center;
                    }
                    else if (anchor == LabelAnchor.LowerCenter)
                    {
                        anchorObject.transform.position = new Vector3(0.5f, 0f);
                        guiText.anchor    = TextAnchor.LowerCenter;
                        guiText.alignment = TextAlignment.Center;
                    }
                    else
                    {
                        Debug.LogWarning("[AFPSCounter] Unknown label anchor for " + this);
                        anchor = LabelAnchor.UpperLeft;
                        anchorObject.transform.position = new Vector3(0f, 1f);
                        guiText.anchor    = TextAnchor.UpperLeft;
                        guiText.alignment = TextAlignment.Left;
                    }

                    guiText.pixelOffset = pixelOffset;
                    guiText.font        = font;
                    guiText.fontSize    = fontSize;
                    guiText.lineSpacing = lineSpacing;

                    anchorObject.layer            = AFPSCounter.Instance.gameObject.layer;
                    anchorObject.tag              = AFPSCounter.Instance.gameObject.tag;
                    anchorObject.transform.parent = AFPSCounter.Instance.transform;
                }

                if (dirty)
                {
                    guiText.text = newText.ToString();
                    dirty        = false;
                }
                newText.Length = 0;
            }
            else if (guiText != null)
            {
                Object.DestroyImmediate(guiText.gameObject);
            }
        }