protected void _Create(EleBaseRect parent, string text, bool wrap, Font font, Color color, int fontSize, Vector2 size, string name) { GameObject go = new GameObject("Text_" + name); go.transform.SetParent(parent.GetContentRect()); this.text = go.AddComponent <UnityEngine.UI.Text>(); this.text.color = color; this.text.font = font; this.text.fontSize = fontSize; this.text.alignment = TextAnchor.UpperLeft; this.text.text = text; this.text.verticalOverflow = VerticalWrapMode.Overflow; this.text.horizontalOverflow = wrap ? HorizontalWrapMode.Wrap : HorizontalWrapMode.Overflow; SetRTTopLeft(this.text.rectTransform); this.wrap = wrap; if (wrap == true) { this.text.horizontalOverflow = HorizontalWrapMode.Wrap; } else { this.text.horizontalOverflow = HorizontalWrapMode.Overflow; } this.text.rectTransform.RTQ().Identity(); }
protected void _Create(EleBaseRect parent, string text, Font font, Color fontColor, int fontPointSize, Sprite frame, PadRect padding, Vector2 size, string name) { GameObject goPlate = new GameObject("HeaderPlate_" + name); goPlate.transform.SetParent(parent.GetContentRect()); this.plate = goPlate.AddComponent <UnityEngine.UI.Image>(); this.plate.rectTransform.RTQ().Identity().TopLeftAnchorsPivot().ZeroOffsets(); this.plate.sprite = frame; this.plate.type = UnityEngine.UI.Image.Type.Sliced; this.border = padding; GameObject goText = new GameObject("HeaderText_" + name); goText.transform.SetParent(this.plate.rectTransform); this.text = goText.AddComponent <UnityEngine.UI.Text>(); this.text.rectTransform.RTQ().Identity().TopLeftAnchorsPivot().ZeroOffsets(); this.text.font = font; this.text.color = fontColor; this.text.fontSize = fontPointSize; this.text.text = text; }
protected void _Create(EleBaseRect parent, Font font, int fontSize, Color fontColor, string text, Sprite plateSprite, Vector2 size, string name) { GameObject go = new GameObject("Button_" + name); go.transform.SetParent(parent.GetContentRect(), false); this.plate = go.AddComponent <UnityEngine.UI.Image>(); this.button = go.AddComponent <BtnTy>(); this.plate.RTQ().TopLeftAnchorsPivot(); this.button.targetGraphic = this.plate; this.plate.sprite = plateSprite; this.plate.type = UnityEngine.UI.Image.Type.Sliced; if (string.IsNullOrEmpty(text) == false) { GameObject goChild = new GameObject("ButtonText_" + name); goChild.transform.SetParent(go.transform, false); this.text = goChild.AddComponent <UnityEngine.UI.Text>(); this.text.text = text; this.text.font = font; this.text.color = fontColor; this.text.fontSize = fontSize; this.text.horizontalOverflow = HorizontalWrapMode.Overflow; this.text.verticalOverflow = VerticalWrapMode.Overflow; this.text.alignment = TextAnchor.MiddleCenter; this.text.rectTransform.RTQ().ExpandParentFlush(); } }
protected void _Create(EleBaseRect parent, Texture t, Vector2 size, string name = "") { GameObject go = new GameObject("Texture_" + name); go.transform.SetParent(parent.GetContentRect(), false); this.rawImg = go.AddComponent <UnityEngine.UI.RawImage>(); this.rawImg.rectTransform.RTQ().TopLeftAnchorsPivot().ZeroOffsets(); this.rawImg.texture = t; }
protected void _Create(EleBaseRect parent, Sprite sprite, Vector2 size, string name) { GameObject go = new GameObject("Separator_" + name); go.transform.SetParent(parent.GetContentRect()); this.img = go.AddComponent <UnityEngine.UI.Image>(); this.img.rectTransform.RTQ().Identity().TopLeftAnchorsPivot().ZeroOffsets(); this.img.sprite = sprite; this.img.type = UnityEngine.UI.Image.Type.Sliced; }
protected void _Create(EleBaseRect parent, ScrollInfo scrollInfo, Vector2 size) { this.minSize = size; GameObject go = new GameObject("Slider_" + name); go.transform.SetParent(parent.GetContentRect(), false); // this.plate = go.AddComponent <UnityEngine.UI.Image>(); this.plate.type = UnityEngine.UI.Image.Type.Sliced; this.plate.sprite = scrollInfo.backplateSprite; // this.slider = go.AddComponent <SldTy>(); this.plate.RTQ().TopLeftAnchorsPivot(); GameObject slideRegion = new GameObject("Slidergn_" + name); slideRegion.transform.SetParent(go.transform, false); RectTransform rtSliderRegion = slideRegion.AddComponent <RectTransform>(); rtSliderRegion.RTQ().ExpandParentFlush(). OffsetMin(scrollInfo.scrollbarDim * 0.5f, 0.0f). OffsetMax(-scrollInfo.scrollbarDim * 0.5f, 0.0f); GameObject goThumb = new GameObject("Thumb_" + name); goThumb.transform.SetParent(slideRegion.transform, false); // this.thumb = goThumb.AddComponent <UnityEngine.UI.Image>(); this.thumb.type = UnityEngine.UI.Image.Type.Sliced; // this.thumb.RTQ().CenterPivot().SizeDelta(scrollInfo.scrollbarDim, 0.0f); this.slider.targetGraphic = this.thumb; this.slider.handleRect = this.thumb.rectTransform; scrollInfo.Apply(this.slider, this.thumb); }
public void Add(Ele child, float proportion, LFlag flags, string label) { PairedLayoutData pld = new PairedLayoutData(); pld.ele = child; pld.prop = proportion; pld.style = flags; pld.label = label; if (string.IsNullOrEmpty(label) == false) { RTQuick.CreateGameObjectWithText( parent.GetContentRect(), "Label_" + label, out pld.labelText).TopLeftAnchorsPivot(); this.labelText.Apply(pld.labelText); pld.labelText.text = label; pld.labelText.horizontalOverflow = HorizontalWrapMode.Overflow; pld.labelText.verticalOverflow = VerticalWrapMode.Overflow; } layoutData.Add(pld); }
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; } }
protected void _Create( EleBaseRect parent, TextAttrib textAttrib, string text, SelectableInfo plateStyle, float toggleWidth, Sprite toggleSprite, UnityEngine.UI.Image.Type icoType, PadRect togglePad, Vector2 size, float separation, string name) { this.minSize = size; this.separation = separation; this.toggleWidth = toggleWidth; this.padding = togglePad; GameObject go = new GameObject("Checkbox_" + name); go.transform.SetParent(parent.GetContentRect(), false); // this.plate = go.AddComponent <UnityEngine.UI.Image>(); this.plate.type = UnityEngine.UI.Image.Type.Sliced; this.plate.RTQ().TopLeftAnchorsPivot(); // this.toggle = go.AddComponent <ty>(); plateStyle.Apply(this.toggle, this.plate); GameObject goCheckmark = new GameObject("Checkmark_" + name); goCheckmark.transform.SetParent(go.transform, false); this.checkbox = goCheckmark.AddComponent <UnityEngine.UI.Image>(); this.checkbox.sprite = toggleSprite; this.checkbox.type = icoType; if (icoType != UnityEngine.UI.Image.Type.Simple) { this.checkbox. RTQ(). CenterPivot(). ExpandParentFlush(). OffsetMin(togglePad.left, togglePad.bot). OffsetMax(-togglePad.right, -togglePad.top); } else { this.checkbox.RTQ(). CenterPivot(). OffsetMin(0.5f, 0.5f). OffsetMax(0.5f, 0.5f). AnchPos( (togglePad.left - togglePad.right) * 0.5f, (togglePad.bot - togglePad.top) * 0.5f). SizeDelta(toggleSprite.rect.size); } if (textAttrib != null) { GameObject goText = new GameObject("Text_" + name); goText.transform.SetParent(go.transform, false); this.label = goText.AddComponent <UnityEngine.UI.Text>(); this.label.text = text; this.label.horizontalOverflow = HorizontalWrapMode.Overflow; this.label.verticalOverflow = VerticalWrapMode.Overflow; this.label.alignment = TextAnchor.LowerLeft; this.label.RTQ().Pivot(0.0f, 0.0f).BotLeftAnchors(); textAttrib.Apply(this.label); } this.toggle.targetGraphic = this.plate; this.toggle.graphic = this.checkbox; }
protected void _Create( EleBaseRect parent, ScrollInfo horiz, ScrollInfo vert, bool showBack, Vector2 size, float sensitivity, string name = "") { // SCROLL ITEMS //////////////////////////////////////////////////////////////////////////////// GameObject go = new GameObject("ScrollRgn_" + name); go.transform.SetParent(parent.GetContentRect(), false); RectTransform rt = go.AddComponent <RectTransform>(); rt.anchorMin = new Vector2(0.0f, 1.0f); rt.anchorMax = new Vector2(0.0f, 1.0f); rt.pivot = new Vector2(0.0f, 1.0f); GameObject goViewport = new GameObject("Viewport_" + name); goViewport.transform.SetParent(go.transform, false); UnityEngine.UI.Image imgViewport = goViewport.AddComponent <UnityEngine.UI.Image>(); RectTransform rtViewport = imgViewport.rectTransform; rtViewport.anchorMin = new Vector2(0.0f, 0.0f); rtViewport.anchorMax = new Vector2(1.0f, 1.0f); rtViewport.pivot = new Vector2(0.0f, 1.0f); rtViewport.offsetMin = new Vector2(0.0f, 0.0f); rtViewport.offsetMax = new Vector2(0.0f, 0.0f); UnityEngine.UI.Mask maskViewport = goViewport.AddComponent <UnityEngine.UI.Mask>(); maskViewport.showMaskGraphic = showBack; GameObject goContent = new GameObject("Content_" + name); goContent.transform.SetParent(goViewport.transform, false); RectTransform rtContent = goContent.AddComponent <RectTransform>(); // // VERTICAL SCROLLBAR //////////////////////////////////////////////////////////////////////////////// GameObject goScrollVert = new GameObject("ScrollVert_" + name); goScrollVert.transform.SetParent(go.transform, false); UnityEngine.UI.Image imgScrollVert = goScrollVert.AddComponent <UnityEngine.UI.Image>(); RectTransform rtScrollVert = imgScrollVert.rectTransform; rtScrollVert.pivot = new Vector2(0.0f, 1.0f); rtScrollVert.anchorMin = new Vector2(1.0f, 0.0f); rtScrollVert.anchorMax = new Vector2(1.0f, 1.0f); rtScrollVert.anchoredPosition = new Vector2(-vert.scrollbarDim, 0.0f); rtScrollVert.sizeDelta = new Vector2(vert.scrollbarDim, 0.0f); imgScrollVert.sprite = vert.backplateSprite; imgScrollVert.type = UnityEngine.UI.Image.Type.Sliced; GameObject goThumbVert = new GameObject("ThumbVert_" + name); goThumbVert.transform.SetParent(goScrollVert.transform, false); UnityEngine.UI.Image imgThumbVert = goThumbVert.AddComponent <UnityEngine.UI.Image>(); RectTransform rtThumbVert = imgThumbVert.rectTransform; rtThumbVert.pivot = new Vector2(1.0f, 1.0f); rtThumbVert.anchorMin = new Vector2(0.0f, 0.0f); rtThumbVert.anchorMax = new Vector2(1.0f, 1.0f); rtThumbVert.anchoredPosition = new Vector2(0.0f, 0.0f); rtThumbVert.sizeDelta = new Vector2(0.0f, 0.0f); ScrollTy sbVert = goScrollVert.AddComponent <ScrollTy>(); sbVert.direction = UnityEngine.UI.Scrollbar.Direction.BottomToTop; sbVert.targetGraphic = imgThumbVert; sbVert.handleRect = rtThumbVert; vert.Apply(sbVert, imgThumbVert); // // HORIZONTAL SCROLLBAR //////////////////////////////////////////////////////////////////////////////// GameObject goScrollHoriz = new GameObject("ScrollHoriz_" + name); goScrollHoriz.transform.SetParent(go.transform, false); UnityEngine.UI.Image imgScrollHoriz = goScrollHoriz.AddComponent <UnityEngine.UI.Image>(); RectTransform rtScrollHoriz = imgScrollHoriz.rectTransform; rtScrollHoriz.pivot = new Vector2(0.0f, 0.0f); rtScrollHoriz.anchorMin = new Vector2(0.0f, 0.0f); rtScrollHoriz.anchorMax = new Vector2(1.0f, 0.0f); rtScrollHoriz.sizeDelta = new Vector2(0.0f, horiz.scrollbarDim); imgScrollHoriz.sprite = horiz.backplateSprite; imgScrollHoriz.type = UnityEngine.UI.Image.Type.Sliced; GameObject goThumbHoriz = new GameObject("ThumbHoriz_" + name); goThumbHoriz.transform.SetParent(goScrollHoriz.transform, false); UnityEngine.UI.Image imgThumbHoriz = goThumbHoriz.AddComponent <UnityEngine.UI.Image>(); RectTransform rtThumbHoriz = imgThumbHoriz.rectTransform; rtThumbHoriz.pivot = new Vector2(0.0f, 1.0f); rtThumbHoriz.anchorMin = new Vector2(0.0f, 0.0f); rtThumbHoriz.anchorMax = new Vector2(1.0f, 1.0f); rtThumbHoriz.anchoredPosition = new Vector2(0.0f, 0.0f); rtThumbHoriz.sizeDelta = new Vector2(0.0f, 0.0f); ScrollTy sbHoriz = goScrollHoriz.AddComponent <ScrollTy>(); sbHoriz.direction = UnityEngine.UI.Scrollbar.Direction.LeftToRight; sbHoriz.targetGraphic = imgThumbHoriz; sbHoriz.handleRect = rtThumbHoriz; horiz.Apply(sbHoriz, imgThumbHoriz); // FINISH //////////////////////////////////////////////////////////////////////////////// RectTy scrollR = go.AddComponent <RectTy>(); scrollR.horizontalScrollbarVisibility = UnityEngine.UI.ScrollRect.ScrollbarVisibility.AutoHideAndExpandViewport; scrollR.verticalScrollbarVisibility = UnityEngine.UI.ScrollRect.ScrollbarVisibility.AutoHideAndExpandViewport; scrollR.viewport = rtViewport; scrollR.content = rtContent; scrollR.horizontalScrollbar = sbHoriz; scrollR.verticalScrollbar = sbVert; scrollR.scrollSensitivity = sensitivity; this.viewportMask = maskViewport; // this.horizScroll = sbHoriz; this.vertScroll = sbVert; // this.rt = rt; this.scrollRect = scrollR; }