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 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 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 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_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; } }