From 0282dae582860d5cbd1d897dffd5a14d2a4c9031 Mon Sep 17 00:00:00 2001 From: monitor1394 Date: Fri, 7 Jan 2022 09:48:59 +0800 Subject: [PATCH] compatibility --- Editor/Windows/XCSettingsEditor.cs | 2 +- Runtime/Helper/SerieHelper.cs | 2 +- Runtime/Internal/BaseChart.Draw.cs | 4 ++-- Runtime/Internal/BaseChart.cs | 5 +++-- Runtime/Serie/Bar/BarHandler.cs | 4 ++-- Runtime/Serie/Serie.cs | 2 +- Runtime/Utilities/ReflectionUtil.cs | 4 ++-- Runtime/Utilities/RuntimeUtil.cs | 23 ++++++++++++++++++++--- Runtime/XUGL/UGL.cs | 20 ++++++++++++++++++-- 9 files changed, 50 insertions(+), 16 deletions(-) diff --git a/Editor/Windows/XCSettingsEditor.cs b/Editor/Windows/XCSettingsEditor.cs index fa7d0b2f..4b9654dd 100644 --- a/Editor/Windows/XCSettingsEditor.cs +++ b/Editor/Windows/XCSettingsEditor.cs @@ -46,7 +46,7 @@ namespace XCharts.Editor [SettingsProviderGroup] static SettingsProvider[] CreateXCSettingsProvider() { - var providers = new List { new XCResourceImporterProvider() }; + var providers = new System.Collections.Generic.List { new XCResourceImporterProvider() }; if (GetSettings() != null) { diff --git a/Runtime/Helper/SerieHelper.cs b/Runtime/Helper/SerieHelper.cs index c4a4d80b..67cc6414 100644 --- a/Runtime/Helper/SerieHelper.cs +++ b/Runtime/Helper/SerieHelper.cs @@ -766,7 +766,7 @@ namespace XCharts var fields = typeof(Serie).GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance); foreach (var field in fields) { - if (field.IsDefined(typeof(SerializeField))) + if (field.IsDefined(typeof(SerializeField), false)) { field.SetValue(newSerie, field.GetValue(oldSerie)); } diff --git a/Runtime/Internal/BaseChart.Draw.cs b/Runtime/Internal/BaseChart.Draw.cs index 6cfa7cf8..b7cb5dc6 100644 --- a/Runtime/Internal/BaseChart.Draw.cs +++ b/Runtime/Internal/BaseChart.Draw.cs @@ -92,11 +92,11 @@ namespace XCharts } public void DrawClipZebraLine(VertexHelper vh, Vector3 p1, Vector3 p2, float size, float zebraWidth, - float zebraGap, Color32 color, Color32 toColor, bool clip, GridCoord grid) + float zebraGap, Color32 color, Color32 toColor, bool clip, GridCoord grid, float maxDistance) { ClampInChart(ref p1); ClampInChart(ref p2); - UGL.DrawZebraLine(vh, p1, p2, size, zebraWidth, zebraGap, color, toColor); + UGL.DrawZebraLine(vh, p1, p2, size, zebraWidth, zebraGap, color, toColor, maxDistance); } public void DrawSymbol(VertexHelper vh, SymbolType type, float symbolSize, diff --git a/Runtime/Internal/BaseChart.cs b/Runtime/Internal/BaseChart.cs index 0399abd9..d8f53352 100644 --- a/Runtime/Internal/BaseChart.cs +++ b/Runtime/Internal/BaseChart.cs @@ -611,10 +611,11 @@ namespace XCharts list.AddRange(fileds2); foreach (var field in list) { - var attribute1 = field.GetCustomAttribute(); + var attribute1 = field.GetAttribute(false); if (attribute1 != null) m_TypeListForSerie.Add(attribute1.type, field); - var attribute2 = field.GetCustomAttribute(); + + var attribute2 = field.GetAttribute(false); if (attribute2 != null) m_TypeListForComponent.Add(attribute2.type, field); } diff --git a/Runtime/Serie/Bar/BarHandler.cs b/Runtime/Serie/Bar/BarHandler.cs index 78cf4a23..6697d4b7 100644 --- a/Runtime/Serie/Bar/BarHandler.cs +++ b/Runtime/Serie/Bar/BarHandler.cs @@ -418,14 +418,14 @@ namespace XCharts plt = (plb + plt) / 2; prt = (prt + prb) / 2; chart.DrawClipZebraLine(vh, plt, prt, barWidth / 2, serie.barZebraWidth, serie.barZebraGap, - barColor, barToColor, serie.clip, grid); + barColor, barToColor, serie.clip, grid, grid.context.width); } else { plb = (prb + plb) / 2; plt = (plt + prt) / 2; chart.DrawClipZebraLine(vh, plb, plt, barWidth / 2, serie.barZebraWidth, serie.barZebraGap, - barColor, barToColor, serie.clip, grid); + barColor, barToColor, serie.clip, grid, grid.context.height); } } diff --git a/Runtime/Serie/Serie.cs b/Runtime/Serie/Serie.cs index c2ddcd8e..8a6271f7 100644 --- a/Runtime/Serie/Serie.cs +++ b/Runtime/Serie/Serie.cs @@ -897,7 +897,7 @@ namespace XCharts if (emphasis != null) emphasis.ClearVerticesDirty(); if (lineArrow != null) - lineArrow?.ClearVerticesDirty(); + lineArrow.ClearVerticesDirty(); } public override void ClearComponentDirty() diff --git a/Runtime/Utilities/ReflectionUtil.cs b/Runtime/Utilities/ReflectionUtil.cs index 0be701e5..f71319ab 100644 --- a/Runtime/Utilities/ReflectionUtil.cs +++ b/Runtime/Utilities/ReflectionUtil.cs @@ -15,7 +15,7 @@ namespace XCharts public static int InvokeListCount(object obj, FieldInfo field) { var list = field.GetValue(obj); - return (int)list.GetType().GetProperty("Count").GetValue(list); + return (int)list.GetType().GetProperty("Count").GetValue(list, null); } public static void InvokeListAdd(object obj, FieldInfo field, object item) @@ -37,7 +37,7 @@ namespace XCharts { var list = field.GetValue(obj); var listType = list.GetType(); - var count = Convert.ToInt32(listType.GetProperty("Count").GetValue(list)); + var count = Convert.ToInt32(listType.GetProperty("Count").GetValue(list, null)); for (int i = 0; i < count; i++) { var item = listType.GetProperty("Item").GetValue(list, new object[] { i }); diff --git a/Runtime/Utilities/RuntimeUtil.cs b/Runtime/Utilities/RuntimeUtil.cs index 993b20eb..a87d70ef 100644 --- a/Runtime/Utilities/RuntimeUtil.cs +++ b/Runtime/Utilities/RuntimeUtil.cs @@ -59,10 +59,27 @@ namespace XCharts return m_AssemblyTypes; } - public static T GetAttribute(this Type type) where T : Attribute + public static T GetAttribute(this Type type, bool check = true) where T : Attribute { - Assert.IsTrue(type.IsDefined(typeof(T), false), "Attribute not found:" + type.Name); - return (T)type.GetCustomAttributes(typeof(T), false)[0]; + if (type.IsDefined(typeof(T), false)) + return (T)type.GetCustomAttributes(typeof(T), false)[0]; + else + { + if (check) + Assert.IsTrue(false, "Attribute not found:" + type.Name); + return null; + } + } + public static T GetAttribute(this MemberInfo type, bool check = true) where T : Attribute + { + if (type.IsDefined(typeof(T), false)) + return (T)type.GetCustomAttributes(typeof(T), false)[0]; + else + { + if (check) + Assert.IsTrue(false, "Attribute not found:" + type.Name); + return null; + } } public static bool CopyFolder(string sourPath, string destPath) diff --git a/Runtime/XUGL/UGL.cs b/Runtime/XUGL/UGL.cs index 1cba640e..68b65b9b 100644 --- a/Runtime/XUGL/UGL.cs +++ b/Runtime/XUGL/UGL.cs @@ -373,9 +373,25 @@ namespace XUGL /// 起始颜色 /// 结束颜色 public static void DrawZebraLine(VertexHelper vh, Vector3 startPoint, Vector3 endPoint, float width, - float zebraWidth, float zebraGap, Color32 color, Color32 toColor) + float zebraWidth, float zebraGap, Color32 color, Color32 toColor, float maxDistance) { - DrawDotLine(vh, startPoint, endPoint, width, color, toColor, zebraWidth, zebraGap); + var dist = Vector3.Distance(startPoint, endPoint); + if (dist < 0.1f) return; + if (zebraWidth == 0) zebraWidth = 3 * width; + if (zebraGap == 0) zebraGap = 3 * width; + var allSegment = Mathf.CeilToInt(maxDistance / (zebraWidth + zebraGap)); + var segment = Mathf.CeilToInt(dist / maxDistance * allSegment); + var dir = (endPoint - startPoint).normalized; + var sp = startPoint; + var np = Vector3.zero; + var isGradient = !color.Equals(toColor); + zebraWidth = (maxDistance - zebraGap * (allSegment - 1)) / allSegment; + for (int i = 1; i <= segment; i++) + { + np = sp + dir * zebraWidth; + DrawLine(vh, sp, np, width, isGradient ? Color32.Lerp(color, toColor, i * 1.0f / allSegment) : color); + sp = np + dir * zebraGap; + } } ///