From 6424a2c440b3500bc63238509bfbdc44fcff6272 Mon Sep 17 00:00:00 2001 From: monitor1394 Date: Tue, 6 Aug 2019 18:21:16 +0800 Subject: [PATCH] =?UTF-8?q?=E6=80=A7=E8=83=BD=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Scripts/UI/Component/Axis.cs | 3 +++ Scripts/UI/Utility/ChartHelper.cs | 20 ++++++++++++++++++-- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/Scripts/UI/Component/Axis.cs b/Scripts/UI/Component/Axis.cs index 7ede02a3..6d3b8c7f 100644 --- a/Scripts/UI/Component/Axis.cs +++ b/Scripts/UI/Component/Axis.cs @@ -217,6 +217,7 @@ namespace XCharts m_AxisName.Copy(other.axisName); m_AxisLabel.Copy(other.axisLabel); m_Data.Clear(); + m_Data.Capacity = m_Data.Count; foreach (var d in other.data) m_Data.Add(d); } @@ -643,6 +644,7 @@ namespace XCharts axis.axisName.Copy(axisName); axis.axisLabel.Copy(axisLabel); axis.data.Clear(); + axis.data.Capacity = data.Count; foreach (var d in data) axis.data.Add(d); return axis; } @@ -694,6 +696,7 @@ namespace XCharts axis.axisName.Copy(axisName); axis.axisLabel.Copy(axisLabel); axis.data.Clear(); + axis.data.Capacity = data.Count; foreach (var d in data) axis.data.Add(d); return axis; } diff --git a/Scripts/UI/Utility/ChartHelper.cs b/Scripts/UI/Utility/ChartHelper.cs index 056afd29..fabd6807 100644 --- a/Scripts/UI/Utility/ChartHelper.cs +++ b/Scripts/UI/Utility/ChartHelper.cs @@ -12,6 +12,19 @@ namespace XCharts public static float CRICLE_SMOOTHNESS = 2f; private static UIVertex[] vertex = new UIVertex[4]; + public static void SetActive(GameObject gameObject,bool active){ + SetActive(gameObject.transform,active); + } + + /// + /// 通过设置scale实现是否显示,优化性能,减少GC + /// + /// + /// + public static void SetActive(Transform transform,bool active){ + if(active) transform.localScale = Vector3.one; + else transform.localScale = Vector3.zero; + } public static void HideAllObject(GameObject obj, string match = null) { HideAllObject(obj.transform, match); @@ -22,13 +35,15 @@ namespace XCharts for (int i = 0; i < parent.childCount; i++) { if (match == null) - parent.GetChild(i).gameObject.SetActive(false); + SetActive(parent.GetChild(i),false); + //parent.GetChild(i).gameObject.SetActive(false); else { var go = parent.GetChild(i); if (go.name.StartsWith(match)) { - go.gameObject.SetActive(false); + SetActive(go,false); + //go.gameObject.SetActive(false); } } } @@ -79,6 +94,7 @@ namespace XCharts obj = parent.Find(name).gameObject; obj.SetActive(true); obj.transform.localPosition = Vector3.zero; + obj.transform.localScale = Vector3.one; } else {