diff --git a/Assets/XChart/Scripts/ChartUtils.cs b/Assets/XChart/Scripts/ChartUtils.cs new file mode 100644 index 00000000..71255460 --- /dev/null +++ b/Assets/XChart/Scripts/ChartUtils.cs @@ -0,0 +1,177 @@ +using System.Collections.Generic; +using UnityEngine; +using UnityEngine.UI; + +namespace xchart +{ + public static class ChartUtils + { + public static Text AddTextObject(string name, Transform parent, Font font, TextAnchor anchor, + Vector2 anchorMin, Vector2 anchorMax, Vector2 pivot, Vector2 sizeDelta) + { + GameObject txtObj; + if (parent.Find(name)) + { + txtObj = parent.Find(name).gameObject; + txtObj.SetActive(true); + } + else + { + txtObj = new GameObject(); + txtObj.name = name; + txtObj.transform.parent = parent; + txtObj.transform.localPosition = Vector3.zero; + txtObj.transform.localScale = Vector3.one; + Text txt = txtObj.AddComponent(); + txt.font = font; + txt.text = "Text"; + txt.alignment = anchor; + txt.horizontalOverflow = HorizontalWrapMode.Overflow; + txt.verticalOverflow = VerticalWrapMode.Overflow; + } + RectTransform rect = txtObj.GetComponent(); + rect.anchorMin = anchorMin; + rect.anchorMax = anchorMax; + rect.pivot = pivot; + rect.sizeDelta = sizeDelta; + return txtObj.GetComponent(); + } + + public static Button AddButtonObject(string name,Transform parent,Font font, + Vector2 anchorMin, Vector2 anchorMax, Vector2 pivot, Vector2 sizeDelta) + { + GameObject btnObj; + if (parent.Find(name)) + { + btnObj = parent.Find(name).gameObject; + btnObj.SetActive(true); + } + else + { + btnObj = new GameObject(); + btnObj.name = name; + btnObj.transform.parent = parent; + btnObj.transform.localPosition = Vector3.zero; + btnObj.transform.localScale = Vector3.one; + btnObj.AddComponent(); + btnObj.AddComponent