public GameObject Build() { var textField = PUIElements.CreateUI(null, Name); var style = TextStyle ?? PUITuning.Fonts.TextLightStyle; // Background var border = textField.AddComponent <Image>(); border.sprite = PUITuning.Images.BoxBorderWhite; border.type = Image.Type.Sliced; border.color = style.textColor; // Text box with rectangular clipping area; put pivot in upper left var textArea = PUIElements.CreateUI(textField, "Text Area", false); textArea.AddComponent <Image>().color = BackColor; var mask = textArea.AddComponent <RectMask2D>(); // Scrollable text var textBox = PUIElements.CreateUI(textArea, "Text"); // Text to display var textDisplay = PTextField.ConfigureField(textBox.AddComponent <TextMeshProUGUI>(), style, TextAlignment); textDisplay.enableWordWrapping = true; textDisplay.raycastTarget = true; // Text field itself textField.SetActive(false); var textEntry = textField.AddComponent <TMP_InputField>(); textEntry.textComponent = textDisplay; textEntry.textViewport = textArea.rectTransform(); textEntry.text = Text ?? ""; textDisplay.text = Text ?? ""; // Events! ConfigureTextEntry(textEntry); var events = textField.AddComponent <PTextFieldEvents>(); events.OnTextChanged = OnTextChanged; events.OnValidate = OnValidate; events.TextObject = textBox; // Add tooltip PUIElements.SetToolTip(textField, ToolTip); mask.enabled = true; PUIElements.SetAnchorOffsets(textBox, new RectOffset()); textField.SetActive(true); // Lay out var layout = PUIUtils.InsetChild(textField, textArea, Vector2.one, new Vector2( MinWidth, Math.Max(LineCount, 1) * PUIUtils.GetLineHeight(style))). AddOrGet <LayoutElement>(); layout.flexibleWidth = FlexSize.x; layout.flexibleHeight = FlexSize.y; OnRealize?.Invoke(textField); return(textField); }