From 5ed1c18af6a0fe3b22e0162725510003b6402b79 Mon Sep 17 00:00:00 2001 From: monitor1394 Date: Wed, 12 Sep 2018 07:27:22 +0800 Subject: [PATCH] =?UTF-8?q?=E6=95=B4=E7=90=86=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Assets/XChart/Demo.cs | 25 + Assets/XChart/Demo.cs.meta | 13 + Assets/XChart/Scripts/LineChart.cs | 129 +++-- Assets/XChart/demo.unity | 752 ++++++++++++++++++++++++++++- 4 files changed, 838 insertions(+), 81 deletions(-) create mode 100644 Assets/XChart/Demo.cs create mode 100644 Assets/XChart/Demo.cs.meta diff --git a/Assets/XChart/Demo.cs b/Assets/XChart/Demo.cs new file mode 100644 index 00000000..434db073 --- /dev/null +++ b/Assets/XChart/Demo.cs @@ -0,0 +1,25 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; +using xchart; + +public class Demo : MonoBehaviour +{ + private LineChart lineChart; + private float time; + + void Awake () { + lineChart = transform.Find("line_chart").GetComponent(); + } + + void Update () { + time += Time.deltaTime; + if (time >= 1) + { + time = 0; + lineChart.AddPoint("fps", Random.Range(24.0f, 60.0f)); + lineChart.AddPoint("rtt", Random.Range(15, 30)); + lineChart.AddPoint("ping", Random.Range(0, 100)); + } + } +} diff --git a/Assets/XChart/Demo.cs.meta b/Assets/XChart/Demo.cs.meta new file mode 100644 index 00000000..21f9e4f4 --- /dev/null +++ b/Assets/XChart/Demo.cs.meta @@ -0,0 +1,13 @@ +fileFormatVersion: 2 +guid: e6bd57e81d68cac47a78ccb7a452c8d7 +timeCreated: 1536708123 +licenseType: Free +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/XChart/Scripts/LineChart.cs b/Assets/XChart/Scripts/LineChart.cs index b4a23727..8f3d2117 100644 --- a/Assets/XChart/Scripts/LineChart.cs +++ b/Assets/XChart/Scripts/LineChart.cs @@ -196,30 +196,30 @@ namespace xchart } else { - GameObject g1; + GameObject txtObj; if (transform.Find("graduation" + i)) { - g1 = transform.Find("graduation" + i).gameObject; - g1.SetActive(true); + txtObj = transform.Find("graduation" + i).gameObject; + txtObj.SetActive(true); } else { - g1 = new GameObject(); - g1.name = "graduation" + i; - g1.transform.parent = transform; - g1.transform.localPosition = Vector3.zero; - g1.transform.localScale = Vector3.one; - Text txtg1 = g1.AddComponent(); - txtg1.font = font; - txtg1.text = (i * 100).ToString(); - txtg1.alignment = TextAnchor.MiddleRight; + txtObj = new GameObject(); + txtObj.name = "graduation" + i; + txtObj.transform.parent = transform; + txtObj.transform.localPosition = Vector3.zero; + txtObj.transform.localScale = Vector3.one; + Text txt = txtObj.AddComponent(); + txt.font = font; + txt.text = (i * 100).ToString(); + txt.alignment = TextAnchor.MiddleRight; } - RectTransform rect = g1.GetComponent(); + RectTransform rect = txtObj.GetComponent(); rect.anchorMax = Vector2.zero; rect.anchorMin = Vector2.zero; rect.sizeDelta = new Vector2(50, 20); rect.localPosition = new Vector3(-33, i * graduationHig, 0); - graduationList.Add(g1.GetComponent()); + graduationList.Add(txtObj.GetComponent()); } } } @@ -231,43 +231,43 @@ namespace xchart { if (lineList[i].button) continue; - GameObject goBtn; + GameObject btnObj; if (transform.Find("button" + i)) { - goBtn = transform.Find("button" + i).gameObject; + btnObj = transform.Find("button" + i).gameObject; } else { - goBtn = new GameObject(); - goBtn.name = "button" + i; - goBtn.transform.parent = transform; - goBtn.transform.localPosition = Vector3.zero; - goBtn.transform.localScale = Vector3.one; - goBtn.AddComponent(); - goBtn.AddComponent