public virtual PUTMPro AddTextWithOptions(PUGameObject container, string content, string fontPath, Color color, float fontScale, string style, TMPro.TextAlignmentOptions alignment) { if (currentY != 0) { currentY -= paragraphSpacing (); } float maxWidth = container.size.Value.x - (padding.left + padding.right); PUTMPro text = new PUTMPro (); text.SetFrame (padding.left, currentY - padding.top, maxWidth, 0, 0, 1, "top,left"); text.font = fontPath; text.fontColor = color; text.fontStyle = style; text.fontSize = (int)(DefaultFontSize()*fontScale); text.sizeToFit = true; text.alignment = alignment; text.value = content; if (urlLinks.Count > 0) { string[] linkURLs = urlLinks.ToArray(); text.OnLinkClickAction = (linkText,linkIdx) => { OpenLink(linkURLs[linkIdx]); }; urlLinks.Clear(); } text.LoadIntoPUGameObject (container); Vector2 size = text.CalculateTextSize (content, maxWidth); text.rectTransform.sizeDelta = size; currentY -= text.rectTransform.sizeDelta.y + padding.bottom; return text; }
public override void Create_OL_LI(PUGameObject container, string content) { if (listCounts.Peek() != 0) { currentY += DefaultFontSize() * 0.5f; } float oldY = currentY; padding.left += DefaultFontSize() * 2.0f; Create_P(container, content); padding.left -= DefaultFontSize() * 2.0f; PUTMPro text = new PUTMPro(); text.SetFrame(padding.left, currentY - padding.top, DefaultFontSize() * 1.5f, (oldY - currentY) - DefaultFontSize(), 0, 0, "top,left"); text.font = DefaultFont(); text.value = string.Format("{0}.", listCounts.Peek() + 1); text.fontColor = textColor(); text.fontStyle = "Bold"; text.fontSize = (int)(DefaultFontSize()); text.sizeToFit = true; text.alignment = TMPro.TextAlignmentOptions.TopRight; text.enableWordWrapping = false; text.LoadIntoPUGameObject(container); text.textGUI.overflowMode = TMPro.TextOverflowModes.Overflow; listCounts.Push(listCounts.Pop() + 1); }
public override void Create_CodeBlock(PUGameObject container, string content) { float margin = 10; padding.left += DefaultFontSize() * 2.0f; padding.right += DefaultFontSize() * 2.0f; PUTMPro text = AddTextWithOptions(container, content, DefaultFont(), textColor(), 0.8f, "Normal", TMPro.TextAlignmentOptions.Left); PutTextInBox(container, text, margin, new Color32(204, 204, 204, 255), new Color32(248, 248, 248, 255)); padding.left -= DefaultFontSize() * 2.0f; padding.right -= DefaultFontSize() * 2.0f; currentY -= margin; }
public virtual PUTMPro AddTextWithOptions(PUGameObject container, string content, string fontPath, Color color, float fontScale, string style, TMPro.TextAlignmentOptions alignment) { if (currentY != 0) { currentY -= paragraphSpacing(); } float maxWidth = container.size.Value.x - (padding.left + padding.right); PUTMPro text = new PUTMPro(); text.SetFrame(padding.left, currentY - padding.top, maxWidth, 0, 0, 1, "top,left"); text.font = fontPath; text.fontColor = color; text.fontStyle = style; text.fontSize = (int)(DefaultFontSize() * fontScale); text.sizeToFit = true; text.alignment = alignment; text.value = content; if (urlLinks.Count > 0) { string[] linkURLs = urlLinks.ToArray(); text.OnLinkClickAction = (linkText, linkIdx) => { OpenLink(linkURLs[linkIdx]); }; urlLinks.Clear(); } text.LoadIntoPUGameObject(container); Vector2 size = text.CalculateTextSize(content, maxWidth); text.rectTransform.sizeDelta = size; currentY -= text.rectTransform.sizeDelta.y + padding.bottom; return(text); }
public void PutTextInBox(PUGameObject container, PUTMPro text, float margin, Color outlineColor, Color backgroundColor) { PUColor outlineColorGO = new PUColor(); outlineColorGO.color = outlineColor; outlineColorGO.SetFrame(text.rectTransform.anchoredPosition.x, text.rectTransform.anchoredPosition.y, text.rectTransform.sizeDelta.x + margin * 2.0f, text.rectTransform.sizeDelta.y + margin * 2.0f, 0, 1, "top,left"); outlineColorGO.LoadIntoPUGameObject(container); PUColor backgroundColorGO = new PUColor(); backgroundColorGO.color = backgroundColor; backgroundColorGO.SetFrame(0, 0, 0, 0, 0, 0, "stretch,stretch"); backgroundColorGO.LoadIntoPUGameObject(outlineColorGO); backgroundColorGO.SetStretchStretch(1, 1, 1, 1); text.rectTransform.SetParent(outlineColorGO.rectTransform, false); text.rectTransform.pivot = Vector2.zero; text.rectTransform.anchorMax = Vector2.one; text.rectTransform.anchorMin = Vector2.zero; text.SetStretchStretch(margin, margin, margin, margin); }
public override void gaxb_complete() { base.gaxb_complete(); // At this point, our gameObject is our "text" game object. We want to maneuver things around // until its like: // --> TMPro - Input Field // --> Text Area // --> Placeholder // --> Text // 0) first, swap out our TMPro text and replace our gameObject with one with the text field GameObject textGameObject = gameObject; // Next, we create a new gameObject, and put the Text-created gameObject inside me gameObject = new GameObject("<TMP_InputField/>", typeof(RectTransform)); gameObject.transform.SetParent(textGameObject.transform.parent, false); UpdateRectTransform(); // 0.5) Create a game object for the field inputField = new PUGameObject(); inputField.title = "TMP_InputField"; inputField.SetFrame(0, 0, 0, 0, 0, 0, "stretch,stretch"); inputField.LoadIntoPUGameObject(this); // 1) create the hierarchy of stuff under me textArea = new PUGameObject(); textArea.title = "Text Area"; textArea.SetFrame(0, 0, 0, 0, 0, 0, "stretch,stretch"); textArea.LoadIntoPUGameObject(inputField); // 2) placeholder if (placeholder != null) { placeholderText = new PUTMPro(); placeholderText.title = "Placeholder"; placeholderText.value = this.placeholder; placeholderText.LoadIntoPUGameObject(textArea); placeholderText.textGUI.overflowMode = this.textGUI.overflowMode; placeholderText.textGUI.alignment = this.textGUI.alignment; placeholderText.textGUI.font = this.textGUI.font; placeholderText.textGUI.fontSize = this.textGUI.fontSize; placeholderText.textGUI.fontStyle = this.textGUI.fontStyle; placeholderText.textGUI.color = this.textGUI.color - new Color(0, 0, 0, 0.5f); placeholderText.textGUI.lineSpacing = this.textGUI.lineSpacing; placeholderText.gameObject.FillParentUI(); } // 3) text text = new PUGameObject(); text.SetFrame(0, 0, 0, 0, 0, 0, "stretch,stretch"); text.LoadIntoPUGameObject(textArea); GameObject.Destroy(text.gameObject); text.gameObject = textGameObject; // Move the text to be the child of the input field textGameObject.name = "Text"; textGameObject.transform.SetParent(textArea.rectTransform, false); textGameObject.FillParentUI(); (textGameObject.transform as RectTransform).pivot = Vector2.zero; // now that we have the hierarchy, fille out the input field field = inputField.gameObject.AddComponent <TMP_InputField> (); field.transition = Selectable.Transition.None; field.targetGraphic = inputField.gameObject.AddComponent <InvisibleHitGraphic> (); field.textViewport = textArea.rectTransform; field.textComponent = textGUI; if (asteriskChar != null) { field.asteriskChar = asteriskChar.Value; } if (contentType == PlanetUnity2.InputFieldContentType.standard) { field.contentType = TMP_InputField.ContentType.Standard; } else if (contentType == PlanetUnity2.InputFieldContentType.autocorrected) { field.contentType = TMP_InputField.ContentType.Autocorrected; } else if (contentType == PlanetUnity2.InputFieldContentType.integer) { field.contentType = TMP_InputField.ContentType.IntegerNumber; } else if (contentType == PlanetUnity2.InputFieldContentType.number) { field.contentType = TMP_InputField.ContentType.DecimalNumber; } else if (contentType == PlanetUnity2.InputFieldContentType.alphanumeric) { field.contentType = TMP_InputField.ContentType.Alphanumeric; } else if (contentType == PlanetUnity2.InputFieldContentType.name) { field.contentType = TMP_InputField.ContentType.Name; } else if (contentType == PlanetUnity2.InputFieldContentType.email) { field.contentType = TMP_InputField.ContentType.EmailAddress; } else if (contentType == PlanetUnity2.InputFieldContentType.password) { field.contentType = TMP_InputField.ContentType.Password; field.inputType = TMP_InputField.InputType.Password; } else if (contentType == PlanetUnity2.InputFieldContentType.pin) { field.contentType = TMP_InputField.ContentType.Pin; } else if (contentType == PlanetUnity2.InputFieldContentType.custom) { field.contentType = TMP_InputField.ContentType.Custom; field.onValidateInput += ValidateInput; } if (lineType == PlanetUnity2.InputFieldLineType.single) { field.lineType = TMP_InputField.LineType.SingleLine; } else if (lineType == PlanetUnity2.InputFieldLineType.multiSubmit) { field.lineType = TMP_InputField.LineType.MultiLineSubmit; } else if (lineType == PlanetUnity2.InputFieldLineType.multiNewline) { field.lineType = TMP_InputField.LineType.MultiLineNewline; } if (characterLimit != null) { field.characterLimit = (int)characterLimit; } if (selectionColor != null) { field.selectionColor = selectionColor.Value; } // This is probably not the best way to do this, but 4.60.f1 removed the onSubmit event field.onEndEdit.AddListener((value) => { if (onValueChanged != null) { NotificationCenter.postNotification(Scope(), this.onValueChanged, NotificationCenter.Args("sender", this)); } }); foreach (Object obj in gameObject.GetComponentsInChildren <DetectTextClickTMPro>()) { GameObject.Destroy(obj); } if (this.value == null) { this.value = ""; } field.text = this.value; if (placeholder != null) { field.placeholder = placeholderText.textGUI; } }
public override void Create_Table(PUGameObject container, TableSpec spec) { float margin = DefaultFontSize(); currentY -= paragraphSpacing(); float savedY = currentY; PUGridLayoutGroup tableGroup = new PUGridLayoutGroup(); tableGroup.SetFrame(padding.left + 2, currentY, container.size.Value.x, 100, 0, 1, "top,left"); tableGroup.LoadIntoPUGameObject(container); // Fill out the group, then figure out the height / widths needed based upon the content float maxCellWidth = 0; float maxCellHeight = 0; int numberOfCols = 0; int numberOfRows = 0; if (spec.Headers != null) { for (int i = 0; i < spec.Headers.Count; i++) { string header = spec.Headers [i]; ColumnAlignment alignment = spec.Columns [i]; TMPro.TextAlignmentOptions tmAlignment = TMPro.TextAlignmentOptions.Left; if (alignment == ColumnAlignment.Right) { tmAlignment = TMPro.TextAlignmentOptions.Right; } if (alignment == ColumnAlignment.Center) { tmAlignment = TMPro.TextAlignmentOptions.Center; } PUTMPro text = AddTextWithOptions(tableGroup, header, DefaultFont(), textColor(), 1.0f, "Bold", tmAlignment); Vector2 size = text.rectTransform.sizeDelta + new Vector2(margin * 2.0f, margin); text.rectTransform.pivot = Vector2.zero; text.rectTransform.anchorMax = Vector2.one; text.rectTransform.anchorMin = Vector2.zero; PutTextInBox(tableGroup, text, 2, new Color32(204, 204, 204, 255), new Color32(255, 255, 255, 255)); text.SetStretchStretch(margin * 0.5f, margin, margin * 0.5f, margin); if (size.x > maxCellWidth) { maxCellWidth = size.x; } if (size.y > maxCellHeight) { maxCellHeight = size.y; } } } numberOfCols = spec.Rows[0].Count; numberOfRows = spec.Rows.Count; if (spec.Headers != null && spec.Headers.Count > 0) { numberOfRows++; } for (int i = 0; i < spec.Rows.Count; i++) { List <string> rows = spec.Rows[i]; for (int j = 0; j < rows.Count; j++) { string row = rows[j]; ColumnAlignment alignment = spec.Columns[j]; TMPro.TextAlignmentOptions tmAlignment = TMPro.TextAlignmentOptions.Left; if (alignment == ColumnAlignment.Right) { tmAlignment = TMPro.TextAlignmentOptions.Right; } if (alignment == ColumnAlignment.Center) { tmAlignment = TMPro.TextAlignmentOptions.Center; } PUTMPro text = AddTextWithOptions(tableGroup, row, DefaultFont(), textColor(), 1.0f, "Normal", tmAlignment); Vector2 size = text.rectTransform.sizeDelta + new Vector2(margin * 2.0f, margin); text.rectTransform.pivot = Vector2.zero; text.rectTransform.anchorMax = Vector2.one; text.rectTransform.anchorMin = Vector2.zero; if (i % 2 != 0) { PutTextInBox(tableGroup, text, 2, new Color32(204, 204, 204, 255), new Color32(248, 248, 248, 255)); } else { PutTextInBox(tableGroup, text, 2, new Color32(204, 204, 204, 255), new Color32(255, 255, 255, 255)); } text.SetStretchStretch(margin * 0.5f, margin, margin * 0.5f, margin); if (size.x > maxCellWidth) { maxCellWidth = size.x; } if (size.y > maxCellHeight) { maxCellHeight = size.y; } } } tableGroup.layout.cellSize = new Vector2(maxCellWidth, maxCellHeight); tableGroup.rectTransform.sizeDelta = new Vector2(maxCellWidth * numberOfCols, maxCellHeight * numberOfRows); currentY = savedY - tableGroup.rectTransform.sizeDelta.y; }
public void PutTextInBox(PUGameObject container, PUTMPro text, float margin, Color outlineColor, Color backgroundColor) { PUColor outlineColorGO = new PUColor (); outlineColorGO.color = outlineColor; outlineColorGO.SetFrame (text.rectTransform.anchoredPosition.x,text.rectTransform.anchoredPosition.y,text.rectTransform.sizeDelta.x + margin * 2.0f,text.rectTransform.sizeDelta.y + margin * 2.0f,0,1,"top,left"); outlineColorGO.LoadIntoPUGameObject (container); PUColor backgroundColorGO = new PUColor (); backgroundColorGO.color = backgroundColor; backgroundColorGO.SetFrame (0, 0, 0, 0, 0, 0, "stretch,stretch"); backgroundColorGO.LoadIntoPUGameObject (outlineColorGO); backgroundColorGO.SetStretchStretch (1, 1, 1, 1); text.rectTransform.SetParent (outlineColorGO.rectTransform, false); text.rectTransform.pivot = Vector2.zero; text.rectTransform.anchorMax = Vector2.one; text.rectTransform.anchorMin = Vector2.zero; text.SetStretchStretch (margin, margin, margin, margin); }
public override void Create_UL_LI(PUGameObject container, string content) { if (listCounts.Peek() != 0) { currentY += DefaultFontSize() * 0.5f; } float oldY = currentY; padding.left += DefaultFontSize() * 2.0f; Create_P(container, content); padding.left -= DefaultFontSize() * 2.0f; PUTMPro text = new PUTMPro (); text.SetFrame (padding.left, currentY - padding.top, DefaultFontSize() * 1.5f, (oldY - currentY) - DefaultFontSize(), 0, 0, "top,left"); text.font = DefaultFont(); text.value = "•"; text.fontColor = textColor(); text.fontStyle = "Bold"; text.fontSize = (int)(DefaultFontSize()); text.sizeToFit = true; text.alignment = TMPro.TextAlignmentOptions.TopRight; text.enableWordWrapping = false; text.LoadIntoPUGameObject (container); text.textGUI.OverflowMode = TMPro.TextOverflowModes.Overflow; listCounts.Push(listCounts.Pop() + 1); }
public override void gaxb_complete() { base.gaxb_complete (); // At this point, our gameObject is our "text" game object. We want to maneuver things around // until its like: // --> TMPro - Input Field // --> Text Area // --> Placeholder // --> Text // 0) first, swap out our TMPro text and replace our gameObject with one with the text field GameObject textGameObject = gameObject; // Next, we create a new gameObject, and put the Text-created gameObject inside me gameObject = new GameObject ("<TMP_InputField/>", typeof(RectTransform)); gameObject.transform.SetParent (textGameObject.transform.parent, false); UpdateRectTransform (); // 0.5) Create a game object for the field inputField = new PUGameObject(); inputField.title = "TMP_InputField"; inputField.SetFrame (0, 0, 0, 0, 0, 0, "stretch,stretch"); inputField.LoadIntoPUGameObject (this); // 1) create the hierarchy of stuff under me textArea = new PUGameObject(); textArea.title = "Text Area"; textArea.SetFrame (0, 0, 0, 0, 0, 0, "stretch,stretch"); textArea.LoadIntoPUGameObject (inputField); // 2) placeholder if (placeholder != null) { placeholderText = new PUTMPro (); placeholderText.title = "Placeholder"; placeholderText.value = this.placeholder; placeholderText.LoadIntoPUGameObject (textArea); placeholderText.textGUI.OverflowMode = this.textGUI.OverflowMode; placeholderText.textGUI.alignment = this.textGUI.alignment; placeholderText.textGUI.font = this.textGUI.font; placeholderText.textGUI.fontSize = this.textGUI.fontSize; placeholderText.textGUI.fontStyle = this.textGUI.fontStyle; placeholderText.textGUI.color = this.textGUI.color - new Color(0,0,0,0.5f); placeholderText.textGUI.lineSpacing = this.textGUI.lineSpacing; placeholderText.gameObject.FillParentUI (); } // 3) text text = new PUGameObject(); text.SetFrame (0, 0, 0, 0, 0, 0, "stretch,stretch"); text.LoadIntoPUGameObject (textArea); GameObject.Destroy (text.gameObject); text.gameObject = textGameObject; // Move the text to be the child of the input field textGameObject.name = "Text"; textGameObject.transform.SetParent (textArea.rectTransform, false); textGameObject.FillParentUI (); (textGameObject.transform as RectTransform).pivot = Vector2.zero; // now that we have the hierarchy, fille out the input field field = inputField.gameObject.AddComponent<TMP_InputField> (); field.transition = Selectable.Transition.None; field.targetGraphic = inputField.gameObject.AddComponent<InvisibleHitGraphic> (); field.textViewport = textArea.rectTransform; field.textComponent = textGUI; if (asteriskChar != null) { field.asteriskChar = asteriskChar.Value; } if (contentType == PlanetUnity2.InputFieldContentType.standard) { field.contentType = TMP_InputField.ContentType.Standard; } else if (contentType == PlanetUnity2.InputFieldContentType.autocorrected) { field.contentType = TMP_InputField.ContentType.Autocorrected; } else if (contentType == PlanetUnity2.InputFieldContentType.integer) { field.contentType = TMP_InputField.ContentType.IntegerNumber; } else if (contentType == PlanetUnity2.InputFieldContentType.number) { field.contentType = TMP_InputField.ContentType.DecimalNumber; } else if (contentType == PlanetUnity2.InputFieldContentType.alphanumeric) { field.contentType = TMP_InputField.ContentType.Alphanumeric; } else if (contentType == PlanetUnity2.InputFieldContentType.name) { field.contentType = TMP_InputField.ContentType.Name; } else if (contentType == PlanetUnity2.InputFieldContentType.email) { field.contentType = TMP_InputField.ContentType.EmailAddress; } else if (contentType == PlanetUnity2.InputFieldContentType.password) { field.contentType = TMP_InputField.ContentType.Password; field.inputType = TMP_InputField.InputType.Password; } else if (contentType == PlanetUnity2.InputFieldContentType.pin) { field.contentType = TMP_InputField.ContentType.Pin; } else if (contentType == PlanetUnity2.InputFieldContentType.custom) { field.contentType = TMP_InputField.ContentType.Custom; field.onValidateInput += ValidateInput; } if (lineType == PlanetUnity2.InputFieldLineType.single) { field.lineType = TMP_InputField.LineType.SingleLine; } else if (lineType == PlanetUnity2.InputFieldLineType.multiSubmit) { field.lineType = TMP_InputField.LineType.MultiLineSubmit; } else if (lineType == PlanetUnity2.InputFieldLineType.multiNewline) { field.lineType = TMP_InputField.LineType.MultiLineNewline; } if (characterLimit != null) { field.characterLimit = (int)characterLimit; } if (selectionColor != null) { field.selectionColor = selectionColor.Value; } // This is probably not the best way to do this, but 4.60.f1 removed the onSubmit event field.onEndEdit.AddListener ((value) => { if(onValueChanged != null){ NotificationCenter.postNotification (Scope (), this.onValueChanged, NotificationCenter.Args("sender", this)); } }); foreach (Object obj in gameObject.GetComponentsInChildren<DetectTextClickTMPro>()) { GameObject.Destroy (obj); } if (this.value == null) { this.value = ""; } field.text = this.value; if (placeholder != null) { field.placeholder = placeholderText.textGUI; } }