public static Text DrawTextUIWithAnchoredPos(string textString, Transform parent, Vector2 anchoredPosition, int fontSize, Font font) { GameObject textGo = new GameObject("Text", typeof(RectTransform), typeof(Text)); textGo.transform.SetParent(parent, false); Transform textGoTrans = textGo.transform; textGoTrans.SetParent(parent, false); textGoTrans.localPosition = Vector3.zero; textGoTrans.localScale = Vector3.one; RectTransform textGoRectTransform = textGo.GetComponent <RectTransform>(); textGoRectTransform.sizeDelta = new Vector2(0, 0); textGoRectTransform.anchoredPosition = anchoredPosition; Text text = textGo.GetComponent <Text>(); text.text = textString; text.verticalOverflow = VerticalWrapMode.Overflow; text.horizontalOverflow = HorizontalWrapMode.Overflow; text.alignment = TextAnchor.MiddleLeft; if (font == null) { font = LC_Utils.GetDefaultFont(); } text.font = font; text.fontSize = fontSize; return(text); }
// Create Text Updater in UI public static FunctionUpdater CreateUITextUpdater(Func <string> GetTextFunc, Vector2 anchoredPosition) { Text text = DrawTextUIAnchoredPos(GetTextFunc(), anchoredPosition, 20, LC_Utils.GetDefaultFont()); return(FunctionUpdater.Create(() => { text.text = GetTextFunc(); return false; }, "UITextUpdater")); }