重构代码,增加柱形图

This commit is contained in:
monitor1394
2018-09-18 06:56:41 +08:00
parent c45e81d2e9
commit c81496aa95
5 changed files with 3056 additions and 110 deletions

View File

@@ -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>();
}