diff --git a/Assets/XCharts/CHANGELOG-EN.md b/Assets/XCharts/CHANGELOG-EN.md index 673f0ebc..afb59f7b 100644 --- a/Assets/XCharts/CHANGELOG-EN.md +++ b/Assets/XCharts/CHANGELOG-EN.md @@ -42,6 +42,7 @@ ## branch-2.0 +* (2022.02.21) Fixed chart name repeat check error #183 * (2022.02.17) Fixed bug where axis split line might be displayed outside the coordinate system #181 * (2022.02.08) Fixed {d} formatter error when value is 0 * (2022.02.08) Fixed `YAxis` `AxisLabel`'s `onZero` does not work diff --git a/Assets/XCharts/CHANGELOG.md b/Assets/XCharts/CHANGELOG.md index bdea7376..dc006104 100644 --- a/Assets/XCharts/CHANGELOG.md +++ b/Assets/XCharts/CHANGELOG.md @@ -42,6 +42,7 @@ ## branch-2.0 +* (2022.02.21) 修复`Chart`的`chartName`重复检测问题 #183 * (2022.02.17) 修复`Axis`的`SplitLine`可能会显示在坐标系外的问题 #181 * (2022.02.08) 修复数据全0时`{d}`显示不正确的问题 * (2022.02.08) 修复`YAxis`的`AxisLabel`的`onZero`参数不生效的问题 diff --git a/Assets/XCharts/Editor/BaseChartEditor.cs b/Assets/XCharts/Editor/BaseChartEditor.cs index 775e9c8e..a52b4db1 100644 --- a/Assets/XCharts/Editor/BaseChartEditor.cs +++ b/Assets/XCharts/Editor/BaseChartEditor.cs @@ -137,6 +137,12 @@ protected virtual void OnStartInspectorGUI() EditorGUILayout.PropertyField(serializedObject.FindProperty(filed)); } } + if (XChartsMgr.Instance.IsRepeatChartName(m_Chart, m_ChartName.stringValue)) + { + EditorGUILayout.BeginHorizontal(); + EditorGUILayout.HelpBox("chart name is repeated:" + m_ChartName.stringValue, MessageType.Error); + EditorGUILayout.EndHorizontal(); + } } BlockEnd(); diff --git a/Assets/XCharts/Runtime/Helper/CheckHelper.cs b/Assets/XCharts/Runtime/Helper/CheckHelper.cs index f9cb20dd..2e7f0024 100644 --- a/Assets/XCharts/Runtime/Helper/CheckHelper.cs +++ b/Assets/XCharts/Runtime/Helper/CheckHelper.cs @@ -18,7 +18,7 @@ private static bool IsColorAlphaZero(Color color) public static string CheckChart(BaseGraph chart) { - if(chart == null) + if (chart == null) return string.Empty; if (chart is BaseChart) return CheckChart((BaseChart)chart); @@ -28,7 +28,7 @@ public static string CheckChart(BaseGraph chart) public static string CheckChart(BaseChart chart) { - if(chart == null) + if (chart == null) return string.Empty; var sb = ChartHelper.sb; sb.Length = 0; @@ -45,10 +45,10 @@ public static string CheckChart(BaseChart chart) private static void CheckName(BaseChart chart, StringBuilder sb) { if (string.IsNullOrEmpty(chart.chartName)) return; - var list = XChartsMgr.Instance.GetCharts(chart.chartName); - if (list.Count > 1) + if (XChartsMgr.Instance.IsRepeatChartName(chart)) { - sb.AppendFormat("warning:chart name is repeated: {0}\n", chart.chartName); + var info = XChartsMgr.Instance.GetRepeatChartNameInfo(chart, chart.chartName); + sb.AppendFormat("warning:chart name is repeated: {0}\n{1}", chart.chartName, info); } } diff --git a/Assets/XCharts/Runtime/XChartsMgr.cs b/Assets/XCharts/Runtime/XChartsMgr.cs index 77623eba..6008c32f 100644 --- a/Assets/XCharts/Runtime/XChartsMgr.cs +++ b/Assets/XCharts/Runtime/XChartsMgr.cs @@ -279,7 +279,7 @@ public BaseChart GetChart(string chartName) public List GetCharts(string chartName) { if (string.IsNullOrEmpty(chartName)) return null; - return m_ChartList.FindAll(chart => chartName.Equals(chartName)); + return m_ChartList.FindAll(chart => chartName.Equals(chart.chartName)); } public void RemoveChart(string chartName) @@ -299,6 +299,33 @@ public bool ContainsChart(BaseChart chart) return m_ChartList.Contains(chart); } + public bool IsRepeatChartName(BaseChart chart, string chartName = null) + { + if(chartName == null) + chartName = chart.chartName; + if (string.IsNullOrEmpty(chartName)) + return false; + foreach (var temp in m_ChartList) + { + if (temp != chart && chartName.Equals(temp.chartName)) + return true; + } + return false; + } + + public string GetRepeatChartNameInfo(BaseChart chart, string chartName) + { + if (string.IsNullOrEmpty(chartName)) + return string.Empty; + string result = ""; + foreach (var temp in m_ChartList) + { + if (temp != chart && chartName.Equals(temp.chartName)) + result += ChartHelper.GetFullName(temp.transform) + "\n"; + } + return result; + } + public static void RemoveAllChartObject() { if (Instance.m_ChartList.Count == 0)