修复Legend初始化异常的问题

This commit is contained in:
monitor1394
2020-04-09 07:26:40 +08:00
parent 6649059db1
commit 86403702e0
3 changed files with 14 additions and 17 deletions

View File

@@ -1,6 +1,7 @@
# 更新日志 # 更新日志
* (2020.04.09) 修复`Legend`初始化异常的问题
* (2020.04.08) 增加`PieChart`通过`ItemStyle`设置边框的支持 * (2020.04.08) 增加`PieChart`通过`ItemStyle`设置边框的支持
* (2020.03.29) 增加`Axis``ceilRate`设置最大最小值的取整倍率 * (2020.03.29) 增加`Axis``ceilRate`设置最大最小值的取整倍率
* (2020.03.29) 增加`BarChart`可通过`itemStyle``cornerRadius`设置`圆角柱图` * (2020.03.29) 增加`BarChart`可通过`itemStyle``cornerRadius`设置`圆角柱图`

View File

@@ -172,13 +172,13 @@ namespace XCharts
protected override void OnEnable() protected override void OnEnable()
{ {
base.OnEnable(); base.OnEnable();
Awake(); ChartHelper.ActiveAllObject(transform, true);
} }
protected override void OnDisable() protected override void OnDisable()
{ {
base.OnDisable(); base.OnDisable();
ChartHelper.HideAllObject(transform); ChartHelper.ActiveAllObject(transform, false);
} }
#if UNITY_EDITOR #if UNITY_EDITOR

View File

@@ -77,19 +77,22 @@ namespace XCharts
} }
public static void HideAllObject(Transform parent, string match = null) public static void HideAllObject(Transform parent, string match = null)
{
ActiveAllObject(parent, false, match);
}
public static void ActiveAllObject(Transform parent, bool active, string match = null)
{ {
for (int i = 0; i < parent.childCount; i++) for (int i = 0; i < parent.childCount; i++)
{ {
if (match == null) if (match == null)
SetActive(parent.GetChild(i), false); SetActive(parent.GetChild(i), active);
//parent.GetChild(i).gameObject.SetActive(false);
else else
{ {
var go = parent.GetChild(i); var go = parent.GetChild(i);
if (go.name.StartsWith(match)) if (go.name.StartsWith(match))
{ {
SetActive(go, false); SetActive(go, active);
//go.gameObject.SetActive(false);
} }
} }
} }
@@ -97,24 +100,17 @@ namespace XCharts
public static void DestroyAllChildren(Transform parent) public static void DestroyAllChildren(Transform parent)
{ {
#if UNITY_2019_1_OR_NEWER
#else
if (parent == null) return; if (parent == null) return;
#if UNITY_EDITOR && UNITY_2018_3_OR_NEWER var childCount = parent.childCount;
if (PrefabUtility.IsPartOfAnyPrefab(parent.gameObject)) for (int i = childCount - 1; i >= 0; i--)
{ {
return; var go = parent.GetChild(i);
}
#endif
while (parent.childCount > 0)
{
var go = parent.GetChild(0);
if (go != null) if (go != null)
{ {
GameObject.DestroyImmediate(go.gameObject); GameObject.DestroyImmediate(go.gameObject);
//GameObject.Destroy(go.gameObject);
} }
} }
#endif
} }
public static string GetFullName(Transform transform) public static string GetFullName(Transform transform)