mirror of
https://github.com/XCharts-Team/XCharts.git
synced 2026-05-18 14:30:10 +00:00
重构代码,增加柱形图
This commit is contained in:
@@ -7,33 +7,38 @@ namespace xcharts
|
||||
public static class ChartUtils
|
||||
{
|
||||
public static Text AddTextObject(string name, Transform parent, Font font, TextAnchor anchor,
|
||||
Vector2 anchorMin, Vector2 anchorMax, Vector2 pivot, Vector2 sizeDelta)
|
||||
Vector2 anchorMin, Vector2 anchorMax, Vector2 pivot, Vector2 sizeDelta,int fontSize = 14)
|
||||
{
|
||||
GameObject txtObj;
|
||||
if (parent.Find(name))
|
||||
{
|
||||
|
||||
txtObj = parent.Find(name).gameObject;
|
||||
txtObj.SetActive(true);
|
||||
txtObj.transform.localPosition = Vector3.zero;
|
||||
}
|
||||
else
|
||||
{
|
||||
txtObj = new GameObject();
|
||||
txtObj.name = name;
|
||||
txtObj.transform.parent = parent;
|
||||
txtObj.transform.localPosition = Vector3.zero;
|
||||
txtObj.transform.localScale = Vector3.one;
|
||||
txtObj.transform.localPosition = Vector3.zero;
|
||||
Text txt = txtObj.AddComponent<Text>();
|
||||
txt.font = font;
|
||||
txt.fontSize = fontSize;
|
||||
txt.text = "Text";
|
||||
txt.alignment = anchor;
|
||||
txt.horizontalOverflow = HorizontalWrapMode.Overflow;
|
||||
txt.verticalOverflow = VerticalWrapMode.Overflow;
|
||||
}
|
||||
txtObj.GetComponent<Text>().alignment = anchor;
|
||||
RectTransform rect = txtObj.GetComponent<RectTransform>();
|
||||
rect.sizeDelta = sizeDelta;
|
||||
rect.anchorMin = anchorMin;
|
||||
rect.anchorMax = anchorMax;
|
||||
rect.pivot = pivot;
|
||||
rect.sizeDelta = sizeDelta;
|
||||
rect.localPosition = Vector3.zero;
|
||||
return txtObj.GetComponent<Text>();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user