public TextFieldBuilder(string name, Transform parent, Rect pos, TextAlignmentOptions textAlignment, RectTransformAnchoring anchor, Vector2 pivot, bool isDigitOnly = false) { this.name = name; this.parent = parent; this.rect = pos; this.textAlignment = textAlignment; this.anchor = anchor; this.pivot = pivot; this.isDigitOnly = isDigitOnly; }
private static GameObject CreateTextBackground(Rect rect, RectTransformAnchoring anchor, Transform parent, Vector2 pivot) { GameObject refSection = SingletonBehaviour <CanvasSpawner> .Instance.CanvasGO.transform.Find("Main Menu").Find("Title bg").gameObject; GameObject newTextBackground = Object.Instantiate(refSection, parent); RectTransform transform = newTextBackground.GetComponent <RectTransform>(); transform.ChangeAnchors(anchor); transform.ChangeRect(rect); transform.pivot = pivot; return(newTextBackground); }
public ButtonBuilder(string name, string label, Transform parent, TextAlignmentOptions textAlignment, GameObject btn = null, string tooltipEnabledText = "", string tooltipDisabledText = "", FontStyles fontStyle = FontStyles.UpperCase) { this.name = name; this.type = ButtonType.Text; this.icon = ""; this.label = label; this.parent = parent; this.btn = btn; this.rect = null; this.textAlignment = textAlignment; this.anchor = RectTransformAnchoring.NotSet; this.pivot = null; this.tooltipEnabledText = tooltipEnabledText; this.tooltipDisabledText = tooltipDisabledText; this.fontStyle = fontStyle; }
public ButtonBuilder(string name, string label, Transform parent, Rect pos, RectTransformAnchoring anchor, Vector2 pivot, TextAlignmentOptions textAlignment, string tooltipEnabledText = "", string tooltipDisabledText = "", FontStyles fontStyle = FontStyles.UpperCase) { this.name = name; this.type = ButtonType.Text; this.icon = ""; this.label = label; this.parent = parent; this.btn = null; this.rect = pos; this.textAlignment = textAlignment; this.anchor = anchor; this.pivot = pivot; this.tooltipEnabledText = tooltipEnabledText; this.tooltipDisabledText = tooltipDisabledText; this.fontStyle = fontStyle; }
private static GameObject CreateSection(Rect rect, RectTransformAnchoring anchor, Transform parent, Vector2?pivot = null) { GameObject refSection = SingletonBehaviour <CanvasSpawner> .Instance.CanvasGO.transform.Find("Main Menu").Find("Section").gameObject; GameObject newSection = Object.Instantiate(refSection, parent); RectTransform transform = newSection.GetComponent <RectTransform>(); transform.ChangeAnchors(anchor); if (pivot.HasValue) { transform.pivot = pivot.Value; } transform.ChangeRect(rect); return(newSection); }
public static void ChangeAnchors(this RectTransform rt, RectTransformAnchoring anchor) { switch (anchor) { case RectTransformAnchoring.TopLeft: rt.anchorMin = new Vector2(0, 1); rt.anchorMax = new Vector2(0, 1); break; case RectTransformAnchoring.TopCenter: rt.anchorMin = new Vector2(.5f, 1); rt.anchorMax = new Vector2(.5f, 1); break; case RectTransformAnchoring.TopRight: rt.anchorMin = new Vector2(1f, 1); rt.anchorMax = new Vector2(1f, 1); break; case RectTransformAnchoring.TopStretch: rt.anchorMin = new Vector2(0, 1); rt.anchorMax = new Vector2(1, 1); break; case (RectTransformAnchoring.MiddleLeft): rt.anchorMin = new Vector2(0, 0.5f); rt.anchorMax = new Vector2(0, 0.5f); break; case (RectTransformAnchoring.MiddleCenter): rt.anchorMin = new Vector2(0.5f, 0.5f); rt.anchorMax = new Vector2(0.5f, 0.5f); break; case (RectTransformAnchoring.MiddleRight): rt.anchorMin = new Vector2(1, 0.5f); rt.anchorMax = new Vector2(1, 0.5f); break; case RectTransformAnchoring.BottomCenter: rt.anchorMin = new Vector2(.5f, 0); rt.anchorMax = new Vector2(.5f, 0); break; } }
private static GameObject CreateLabel(string name, string labelText, Transform parent, Rect rect, FontStyles fontStyle, TextAlignmentOptions textAlignment, RectTransformAnchoring anchor, Vector2 pivot, Color?color = null, float?fontSize = null) { GameObject refLabel = SingletonBehaviour <CanvasSpawner> .Instance.CanvasGO.transform.Find("Main Menu").Find("title").gameObject; GameObject label = Object.Instantiate(refLabel, parent); label.name = $"Label {name}"; TextMeshProUGUI titleText = label.GetComponent <TextMeshProUGUI>(); titleText.text = labelText; titleText.alignment = textAlignment; titleText.fontStyle = fontStyle; if (color.HasValue) { titleText.color = color.Value; } if (fontSize.HasValue) { titleText.fontSize = fontSize.Value; } RectTransform transform = label.GetComponent <RectTransform>(); transform.pivot = pivot; transform.ChangeAnchors(anchor); transform.ChangeRect(rect); return(label); }