From 8400285bd9d72a86fce3bf272ccbfabfad24a5b6 Mon Sep 17 00:00:00 2001 From: monitor1394 Date: Thu, 13 Sep 2018 07:20:11 +0800 Subject: [PATCH] =?UTF-8?q?=E9=87=8D=E6=9E=84=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Assets/XChart/Scripts/ChartUtils.cs | 177 ++++ Assets/XChart/Scripts/ChartUtils.cs.meta | 13 + Assets/XChart/Scripts/LineChart.cs | 244 +---- Assets/XChart/demo.unity | 1208 +--------------------- 4 files changed, 227 insertions(+), 1415 deletions(-) create mode 100644 Assets/XChart/Scripts/ChartUtils.cs create mode 100644 Assets/XChart/Scripts/ChartUtils.cs.meta 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