UIMessageElement BuildNewElement()
        {
            UIMessageElement newElement = Instantiate(UIManager.instance.messagePrefab);

            newElement.transform.SetParent(transform);
            newElement.transform.localRotation = Quaternion.identity;
            newElement.transform.localScale    = Vector3.one;
            newElement.DisableMessage();
            return(newElement);
        }
        public void ShowMessage(string message)
        {
            transform.localScale = Vector3.one * scale;

            UIMessageElement newMessage = GetAvailableElement();

            shownElements.Add(newMessage);
            newMessage.ShowMessage(duration, fadeIn, fadeOut);

            newMessage.transform.localPosition = new Vector3(startXOffset, (shownElements.Count - 1) * lineHeight, 0);

            newMessage.text.SetAnchor(textAnchor);
            newMessage.text.SetText(message);
            newMessage.text.transform.localScale = Vector3.one * textScale;
            // newMessage._UpdateElement();
            // newMessage.rectTransform.sizeDelta = new Vector2(width, Mathf.Abs(lineHeight));
            newMessage.SetSizeDelta(new Vector2(width, Mathf.Abs(lineHeight)));

            UIText textC = newMessage.text;
            // textC.SetAnchor( textAlignment );

            RectTransform textRect = textC.rectTransform;

            if (textAnchor == TextAnchor.MiddleCenter || textAnchor == TextAnchor.LowerCenter || textAnchor == TextAnchor.UpperCenter)
            {
                textRect.anchorMin = new Vector2(.5f, .5f);
                textRect.anchorMax = new Vector2(.5f, .5f);
                textRect.pivot     = new Vector2(0.5f, 0.5f);
            }
            else if (textAnchor == TextAnchor.MiddleRight || textAnchor == TextAnchor.LowerRight || textAnchor == TextAnchor.UpperRight)
            {
                textRect.anchorMin = new Vector2(1.0f - textMargin, 0.5f);
                textRect.anchorMax = new Vector2(1.0f - textMargin, 0.5f);
                textRect.pivot     = new Vector2(1.0f - textMargin, 0.5f);
            }
            else if (textAnchor == TextAnchor.MiddleLeft || textAnchor == TextAnchor.LowerLeft || textAnchor == TextAnchor.UpperLeft)
            {
                textRect.anchorMin = new Vector2(textMargin, 0.5f);
                textRect.anchorMax = new Vector2(textMargin, 0.5f);
                textRect.pivot     = new Vector2(textMargin, 0.5f);
            }
        }
        void UpdateShownElements(float deltaTime)
        {
            float speed = deltaTime * elementMoveSpeed;

            for (int i = 0; i < shownElements.Count; i++)
            {
                UIMessageElement element = shownElements[i];
                element.transform.localPosition = Vector3.Lerp(element.transform.localPosition, new Vector3(0, i * lineHeight, 0), speed);
                element.UpdateElement(deltaTime);
            }

            for (int i = shownElements.Count - 1; i >= 0; i--)
            {
                UIMessageElement element = shownElements[i];
                if (element.isAvailable)
                {
                    shownElements.Remove(element);
                    elementPool.Enqueue(element);
                }
            }
        }