using System.Collections.Generic; using System.Text.RegularExpressions; using UnityEngine; using UnityEngine.EventSystems; using UnityEngine.UI; namespace XCharts { public static class ChartHelper { private static float CRICLE_SMOOTHNESS = 1f; private static UIVertex[] vertex = new UIVertex[4]; public static void HideAllObject(GameObject obj, string match) { HideAllObject(obj.transform, match); } public static void HideAllObject(Transform parent, string match) { for (int i = 0; i < parent.childCount; i++) { if (match == null) parent.GetChild(i).gameObject.SetActive(false); else { var go = parent.GetChild(i); if (go.name.StartsWith(match)) { go.gameObject.SetActive(false); } } } } public static void DestoryAllChilds(Transform parent) { while (parent.childCount > 0) { var go = parent.GetChild(0); if (go.childCount > 0) DestoryAllChilds(go); else GameObject.DestroyImmediate(go.gameObject); } } public static string GetFullName(Transform transform) { string name = transform.name; Transform obj = transform; while (obj.transform.parent) { name += "/" + obj.transform.parent.name; obj = obj.transform.parent; } return name; } public static T GetOrAddComponent(Transform transform) where T : Component { return GetOrAddComponent(transform.gameObject); } public static T GetOrAddComponent(GameObject gameObject) where T : Component { if (gameObject.GetComponent() == null) { gameObject.AddComponent(); } return gameObject.GetComponent(); } public static GameObject AddObject(string name, Transform parent, Vector2 anchorMin, Vector2 anchorMax, Vector2 pivot, Vector2 sizeDelta) { GameObject obj; if (parent.Find(name)) { obj = parent.Find(name).gameObject; obj.SetActive(true); obj.transform.localPosition = Vector3.zero; } else { obj = new GameObject(); obj.name = name; obj.transform.parent = parent; obj.transform.localScale = Vector3.one; obj.transform.localPosition = Vector3.zero; } RectTransform rect = GetOrAddComponent(obj); rect.localPosition = Vector3.zero; rect.sizeDelta = sizeDelta; rect.anchorMin = anchorMin; rect.anchorMax = anchorMax; rect.pivot = pivot; return obj; } public static Text AddTextObject(string name, Transform parent, Font font, Color color, TextAnchor anchor, Vector2 anchorMin, Vector2 anchorMax, Vector2 pivot, Vector2 sizeDelta, int fontSize = 14, float textRotation = 0) { GameObject txtObj = AddObject(name, parent, anchorMin, anchorMax, pivot, sizeDelta); Text txt = GetOrAddComponent(txtObj); txt.font = font; txt.fontSize = fontSize; txt.text = "Text"; txt.alignment = anchor; txt.horizontalOverflow = HorizontalWrapMode.Overflow; txt.verticalOverflow = VerticalWrapMode.Overflow; txt.color = color; if (textRotation > 0) { txtObj.transform.localEulerAngles = new Vector3(0, 0, textRotation); } RectTransform rect = GetOrAddComponent(txtObj); rect.localPosition = Vector3.zero; rect.sizeDelta = sizeDelta; rect.anchorMin = anchorMin; rect.anchorMax = anchorMax; rect.pivot = pivot; return txtObj.GetComponent(); } public static Button AddButtonObject(string name, Transform parent, Font font, int fontSize, Color color, TextAnchor anchor, Vector2 anchorMin, Vector2 anchorMax, Vector2 pivot, Vector2 sizeDelta) { GameObject btnObj = AddObject(name, parent, anchorMin, anchorMax, pivot, sizeDelta); GetOrAddComponent(btnObj); GetOrAddComponent