public override void Create_IMG(PUGameObject container, string url, string title) { Vector2 size = new Vector2(100, 100); if (title.Contains(",")) { size = Vector2.zero.PUParse(title); } currentY -= paragraphSpacing(); PUGameObject img = new PUGameObject(); img.SetFrame(padding.left, currentY - padding.top, size.x, size.y, 0, 1, "top,left"); img.LoadIntoPUGameObject(container); MarkdownRemoteImageLoader loader = img.gameObject.AddComponent <MarkdownRemoteImageLoader> (); loader.path = url; loader.onComplete = (imgSize) => { img.rectTransform.sizeDelta = imgSize; }; currentY -= size.y; }
public virtual void LoadIntoPUGameObject(PUScrollRect parent, object data) { scrollRect = parent; cellData = data; string xmlPath = XmlPath(); if (xmlPath != null) { puGameObject = (PUGameObject)PlanetUnity2.loadXML(PlanetUnityResourceCache.GetAsset <TextAsset>(xmlPath).bytes, parent.contentObject, null); // Attach all of the PlanetUnity objects try { FieldInfo field = this.GetType().GetField("scene"); if (field != null) { field.SetValue(this, puGameObject); } puGameObject.PerformOnChildren(val => { PUGameObject oo = val as PUGameObject; if (oo != null && oo.title != null) { field = this.GetType().GetField(oo.title); if (field != null) { field.SetValue(this, oo); } } return(true); }); } catch (Exception e) { UnityEngine.Debug.Log("TableCell error: " + e); } try { // Attach all of the named GameObjects FieldInfo[] fields = this.GetType().GetFields(); foreach (FieldInfo field in fields) { if (field.FieldType == typeof(GameObject)) { GameObject[] pAllObjects = (GameObject[])Resources.FindObjectsOfTypeAll(typeof(GameObject)); foreach (GameObject pObject in pAllObjects) { if (pObject.name.Equals(field.Name)) { field.SetValue(this, pObject); } } } } } catch (Exception e) { UnityEngine.Debug.Log("TableCell error: " + e); } } else { puGameObject = new PUGameObject(); puGameObject.SetFrame(0, 0, 0, 60, 0, 0, "bottom,left"); puGameObject.LoadIntoPUGameObject(parent); puGameObject.gameObject.transform.SetParent(parent.contentObject.transform, false); } puGameObject.parent = table; // We want to bridge all notifications to my scope; this allows developers to handle notifications // at the table cell level, or at the scene controller level, with ease NotificationCenter.addObserver(this, "*", puGameObject, (args, name) => { NotificationCenter.postNotification(scrollRect.Scope(), name, args); }); cellGameObject = puGameObject.gameObject; cellTransform = cellGameObject.transform as RectTransform; tableTransform = scrollRect.rectTransform; tableContentTransform = scrollRect.contentObject.transform as RectTransform; UpdateContents(); }
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 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 virtual void LoadIntoPUGameObject(PUScrollRect parent, object data) { scrollRect = parent; cellData = data; string xmlPath = XmlPath (); if (xmlPath != null) { puGameObject = (PUGameObject)PlanetUnity2.loadXML (PlanetUnityOverride.xmlFromPath (xmlPath), parent.contentObject, null); // Attach all of the PlanetUnity objects try { FieldInfo field = this.GetType ().GetField ("scene"); if (field != null) { field.SetValue (this, puGameObject); } puGameObject.PerformOnChildren (val => { PUGameObject oo = val as PUGameObject; if (oo != null && oo.title != null) { field = this.GetType ().GetField (oo.title); if (field != null) { field.SetValue (this, oo); } } return true; }); } catch (Exception e) { UnityEngine.Debug.Log ("TableCell error: " + e); } try { // Attach all of the named GameObjects FieldInfo[] fields = this.GetType ().GetFields (); foreach (FieldInfo field in fields) { if (field.FieldType == typeof(GameObject)) { GameObject[] pAllObjects = (GameObject[])Resources.FindObjectsOfTypeAll (typeof(GameObject)); foreach (GameObject pObject in pAllObjects) { if (pObject.name.Equals (field.Name)) { field.SetValue (this, pObject); } } } } } catch (Exception e) { UnityEngine.Debug.Log ("TableCell error: " + e); } } else { puGameObject = new PUGameObject (); puGameObject.SetFrame (0, 0, 0, 60, 0, 0, "bottom,stretch"); puGameObject.LoadIntoPUGameObject (parent); puGameObject.gameObject.transform.SetParent(parent.contentObject.transform, false); } if (IsHeader () && this is PUSimpleTableCell == false) { PUTableHeaderScript script = (PUTableHeaderScript)puGameObject.gameObject.AddComponent (typeof(PUTableHeaderScript)); script.table = table; script.tableCell = this; } puGameObject.parent = table; // We want to bridge all notifications to my scope; this allows developers to handle notifications // at the table cell level, or at the scene controller level, with ease NotificationCenter.addObserver (this, "*", puGameObject, (args,name) => { NotificationCenter.postNotification(scrollRect.Scope(), name, args); }); cellGameObject = puGameObject.gameObject; cellTransform = cellGameObject.transform as RectTransform; tableTransform = scrollRect.rectTransform; tableContentTransform = scrollRect.contentObject.transform as RectTransform; UpdateContents (); }