Ejemplo n.º 1
0
        protected void _Create(EleBaseRect parent, string text, Font font, Color fontColor, int pointSize, bool multiline, Sprite plate, PadRect padding, Vector2 size, string name)
        {
            this.border = padding;

            GameObject go = new GameObject("InputPlate_" + name);

            go.transform.SetParent(parent.GetContentRect(), false);
            go.transform.localRotation = Quaternion.identity;
            go.transform.localScale    = Vector3.one;
            UnityEngine.UI.Image img = go.AddComponent <UnityEngine.UI.Image>();
            img.RTQ().TopLeftAnchorsPivot();
            img.sprite = plate;
            img.type   = UnityEngine.UI.Image.Type.Sliced;

            GameObject goInput = new GameObject("Input_" + name);

            goInput.transform.SetParent(go.transform, false);
            this.rtInput           = goInput.AddComponent <RectTransform>();
            this.rtInput.pivot     = new Vector2(0.0f, 1.0f);
            this.rtInput.anchorMin = Vector2.zero;
            this.rtInput.anchorMax = Vector2.one;
            this.rtInput.offsetMin = new Vector2(padding.left, padding.bot);
            this.rtInput.offsetMax = new Vector2(-padding.right, -padding.top);


            GameObject goText = new GameObject("InputText_" + name);

            goText.transform.SetParent(this.rtInput, false);
            goText.transform.localRotation = Quaternion.identity;
            goText.transform.localPosition = Vector3.zero;
            UnityEngine.UI.Text txt = goText.AddComponent <UnityEngine.UI.Text>();
            txt.RTQ().TopLeftAnchorsPivot().ExpandParentFlush();

            GameObject goPlaceholder = new GameObject("InputPlaceholder_" + name);

            goPlaceholder.transform.SetParent(this.rtInput, false);
            goPlaceholder.transform.localRotation = Quaternion.identity;
            goPlaceholder.transform.localPosition = Vector3.zero;
            UnityEngine.UI.Text txtPlace = goPlaceholder.AddComponent <UnityEngine.UI.Text>();
            txtPlace.RTQ().TopLeftAnchorsPivot().ExpandParentFlush();

            this.input = goInput.AddComponent <UnityEngine.UI.InputField>();
            this.input.textComponent = txt;
            this.input.targetGraphic = img;
            this.input.placeholder   = txtPlace;
            this.rt                           = go.GetComponent <RectTransform>();
            this.placeholder                  = txtPlace;
            this.text                         = txt;
            this.text.color                   = fontColor;
            this.text.font                    = font;
            this.text.fontSize                = pointSize;
            this.text.verticalOverflow        = VerticalWrapMode.Overflow;
            this.placeholder.color            = new Color(fontColor.r, fontColor.g, fontColor.b, fontColor.a * 0.5f);
            this.placeholder.font             = font;
            this.placeholder.fontSize         = pointSize;
            this.placeholder.verticalOverflow = VerticalWrapMode.Overflow;

            this.input.lineType =
                multiline ?
                UnityEngine.UI.InputField.LineType.MultiLineNewline :
                UnityEngine.UI.InputField.LineType.SingleLine;

            if (multiline == false)
            {
                this.text.alignment        = TextAnchor.MiddleLeft;
                this.placeholder.alignment = TextAnchor.MiddleLeft;
            }
        }