From 16c8d26e2a9ef730e2c48227a9e122420632b524 Mon Sep 17 00:00:00 2001 From: Jacob Rapoport Date: Sun, 27 Oct 2019 09:05:50 -0700 Subject: [PATCH] fix destroying a gameobject inside a prefab --- Demo/Runtime/Demo.cs | 2 +- Runtime/Internal/BaseChart.cs | 4 ++-- Runtime/Utility/ChartHelper.cs | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Demo/Runtime/Demo.cs b/Demo/Runtime/Demo.cs index 270650d9..57ffdc46 100644 --- a/Demo/Runtime/Demo.cs +++ b/Demo/Runtime/Demo.cs @@ -96,7 +96,7 @@ namespace XCharts var btnPanel = transform.Find("chart_list"); m_BtnClone = transform.Find("btn_clone").gameObject; m_BtnClone.SetActive(false); - ChartHelper.DestoryAllChilds(btnPanel); + //ChartHelper.DestroyAllChildren(btnPanel); foreach (var module in m_ChartModule) { var btnName = "btn_" + module.name; diff --git a/Runtime/Internal/BaseChart.cs b/Runtime/Internal/BaseChart.cs index 104811b4..1f5ab2c5 100644 --- a/Runtime/Internal/BaseChart.cs +++ b/Runtime/Internal/BaseChart.cs @@ -213,7 +213,7 @@ namespace XCharts totalLegend++; } m_Legend.RemoveButton(); - ChartHelper.DestoryAllChilds(legendObject.transform); + ChartHelper.DestroyAllChildren(legendObject.transform); if (!m_Legend.show) return; for (int i = 0; i < datas.Count; i++) { @@ -289,7 +289,7 @@ namespace XCharts { var labelObject = ChartHelper.AddObject(s_SerieLabelObjectName, transform, chartAnchorMin, chartAnchorMax, chartPivot, new Vector2(chartWidth, chartHeight)); - ChartHelper.DestoryAllChilds(labelObject.transform); + // ChartHelper.DestroyAllChildren(labelObject.transform); int count = 0; for (int i = 0; i < m_Series.Count; i++) { diff --git a/Runtime/Utility/ChartHelper.cs b/Runtime/Utility/ChartHelper.cs index b23f1595..f7a30862 100644 --- a/Runtime/Utility/ChartHelper.cs +++ b/Runtime/Utility/ChartHelper.cs @@ -72,12 +72,12 @@ namespace XCharts } } - public static void DestoryAllChilds(Transform parent) + public static void DestroyAllChildren(Transform parent) { while (parent.childCount > 0) { var go = parent.GetChild(0); - if (go.childCount > 0) DestoryAllChilds(go); + if (go.childCount > 0) DestroyAllChildren(go); else GameObject.DestroyImmediate(go.gameObject); } }