diff --git a/Editor/Charts/BaseChartEditor.cs b/Editor/Charts/BaseChartEditor.cs index e087159d..486205de 100644 --- a/Editor/Charts/BaseChartEditor.cs +++ b/Editor/Charts/BaseChartEditor.cs @@ -263,9 +263,9 @@ namespace XCharts.Editor if (GUILayout.Button("Covert XY Axis")) m_Chart.CovertXYAxis(0); } - if (GUILayout.Button("Reinit Component")) + if (GUILayout.Button("Rebuild Chart Object")) { - m_Chart.RemoveAndReinitChartObject(); + m_Chart.RebuildChartObject(); } if (m_CheckWarning) { diff --git a/Editor/ChildComponents/AnimationDrawer.cs b/Editor/ChildComponents/AnimationDrawer.cs index f5fb1efa..baf8c09d 100644 --- a/Editor/ChildComponents/AnimationDrawer.cs +++ b/Editor/ChildComponents/AnimationDrawer.cs @@ -12,7 +12,7 @@ namespace XCharts.Editor public override void OnGUI(Rect pos, SerializedProperty prop, GUIContent label) { base.OnGUI(pos, prop, label); - if (MakeComponentFoldout(prop, "m_Enable")) + if (MakeComponentFoldout(prop, "m_Enable", true)) { ++EditorGUI.indentLevel; PropertyField(prop, "m_Type"); diff --git a/Editor/ChildComponents/AreaStyleDrawer.cs b/Editor/ChildComponents/AreaStyleDrawer.cs index 4aaa81e8..b581f48d 100644 --- a/Editor/ChildComponents/AreaStyleDrawer.cs +++ b/Editor/ChildComponents/AreaStyleDrawer.cs @@ -12,7 +12,7 @@ namespace XCharts.Editor public override void OnGUI(Rect pos, SerializedProperty prop, GUIContent label) { base.OnGUI(pos, prop, label); - if (MakeComponentFoldout(prop, "m_Show")) + if (MakeComponentFoldout(prop, "m_Show", true)) { ++EditorGUI.indentLevel; PropertyField(prop, "m_Origin"); diff --git a/Editor/ChildComponents/BasePropertyDrawer.cs b/Editor/ChildComponents/BasePropertyDrawer.cs index 110fbfba..61cc5265 100644 --- a/Editor/ChildComponents/BasePropertyDrawer.cs +++ b/Editor/ChildComponents/BasePropertyDrawer.cs @@ -162,18 +162,19 @@ namespace XCharts.Editor m_DisplayName, relativeProp); } } - protected bool MakeComponentFoldout(SerializedProperty prop, string relativePropName, params HeaderMenuInfo[] menus) + protected bool MakeComponentFoldout(SerializedProperty prop, string relativePropName, bool relativePropEnable, + params HeaderMenuInfo[] menus) { if (string.IsNullOrEmpty(relativePropName)) { return ChartEditorHelper.MakeComponentFoldout(ref m_DrawRect, m_Heights, m_PropToggles, m_KeyName, - m_DisplayName, null, menus); + m_DisplayName, null, relativePropEnable, menus); } else - { + { var relativeProp = prop.FindPropertyRelative(relativePropName); return ChartEditorHelper.MakeComponentFoldout(ref m_DrawRect, m_Heights, m_PropToggles, m_KeyName, - m_DisplayName, relativeProp, menus); + m_DisplayName, relativeProp, relativePropEnable, menus); } } diff --git a/Editor/ChildComponents/ComponentThemeDrawer.cs b/Editor/ChildComponents/ComponentThemeDrawer.cs index ad61a375..2487692f 100644 --- a/Editor/ChildComponents/ComponentThemeDrawer.cs +++ b/Editor/ChildComponents/ComponentThemeDrawer.cs @@ -16,7 +16,7 @@ namespace XCharts.Editor public override void OnGUI(Rect pos, SerializedProperty prop, GUIContent label) { base.OnGUI(pos, prop, label); - if (MakeComponentFoldout(prop, "")) + if (MakeComponentFoldout(prop, "", true)) { ++EditorGUI.indentLevel; #if dUI_TextMeshPro @@ -141,7 +141,7 @@ namespace XCharts.Editor public override void OnGUI(Rect pos, SerializedProperty prop, GUIContent label) { base.OnGUI(pos, prop, label); - if (MakeComponentFoldout(prop, "")) + if (MakeComponentFoldout(prop, "", true)) { ++EditorGUI.indentLevel; PropertyField(prop, "m_LineWidth"); diff --git a/Editor/ChildComponents/DebugInfoDrawer.cs b/Editor/ChildComponents/DebugInfoDrawer.cs index b5a618a4..b3eb0fd3 100644 --- a/Editor/ChildComponents/DebugInfoDrawer.cs +++ b/Editor/ChildComponents/DebugInfoDrawer.cs @@ -12,7 +12,7 @@ namespace XCharts.Editor public override void OnGUI(Rect pos, SerializedProperty prop, GUIContent label) { base.OnGUI(pos, prop, label); - if (MakeComponentFoldout(prop, "")) + if (MakeComponentFoldout(prop, "m_Show", false)) { ++EditorGUI.indentLevel; PropertyField(prop, "m_FoldSeries"); diff --git a/Editor/ChildComponents/EmphasisStyleDrawer.cs b/Editor/ChildComponents/EmphasisStyleDrawer.cs index f1348e80..509f65c9 100644 --- a/Editor/ChildComponents/EmphasisStyleDrawer.cs +++ b/Editor/ChildComponents/EmphasisStyleDrawer.cs @@ -13,7 +13,7 @@ namespace XCharts.Editor public override void OnGUI(Rect pos, SerializedProperty prop, GUIContent label) { base.OnGUI(pos, prop, label); - if (MakeComponentFoldout(prop, "m_Show")) + if (MakeComponentFoldout(prop, "m_Show", true)) { ++EditorGUI.indentLevel; PropertyField(prop, "m_Label"); diff --git a/Editor/ChildComponents/IconStyleDrawer.cs b/Editor/ChildComponents/IconStyleDrawer.cs index ad4e6861..f63d9ee2 100644 --- a/Editor/ChildComponents/IconStyleDrawer.cs +++ b/Editor/ChildComponents/IconStyleDrawer.cs @@ -12,7 +12,7 @@ namespace XCharts.Editor public override void OnGUI(Rect pos, SerializedProperty prop, GUIContent label) { base.OnGUI(pos, prop, label); - if (MakeComponentFoldout(prop, "m_Show")) + if (MakeComponentFoldout(prop, "m_Show", true)) { ++EditorGUI.indentLevel; PropertyField(prop, "m_Layer"); diff --git a/Editor/ChildComponents/ItemStyleDrawer.cs b/Editor/ChildComponents/ItemStyleDrawer.cs index 34eebabf..87560daa 100644 --- a/Editor/ChildComponents/ItemStyleDrawer.cs +++ b/Editor/ChildComponents/ItemStyleDrawer.cs @@ -12,7 +12,7 @@ namespace XCharts.Editor public override void OnGUI(Rect pos, SerializedProperty prop, GUIContent label) { base.OnGUI(pos, prop, label); - if (MakeComponentFoldout(prop, "m_Show")) + if (MakeComponentFoldout(prop, "m_Show", false)) { ++EditorGUI.indentLevel; PropertyField(prop, "m_Color"); diff --git a/Editor/ChildComponents/LabelLineDrawer.cs b/Editor/ChildComponents/LabelLineDrawer.cs index f2a443f8..566fbdf4 100644 --- a/Editor/ChildComponents/LabelLineDrawer.cs +++ b/Editor/ChildComponents/LabelLineDrawer.cs @@ -12,7 +12,7 @@ namespace XCharts.Editor public override void OnGUI(Rect pos, SerializedProperty prop, GUIContent label) { base.OnGUI(pos, prop, label); - if (MakeComponentFoldout(prop, "m_Show")) + if (MakeComponentFoldout(prop, "m_Show", true)) { ++EditorGUI.indentLevel; PropertyField(prop, "m_LineType"); diff --git a/Editor/ChildComponents/LabelStyleDrawer.cs b/Editor/ChildComponents/LabelStyleDrawer.cs index 31cc070a..68cfc30b 100644 --- a/Editor/ChildComponents/LabelStyleDrawer.cs +++ b/Editor/ChildComponents/LabelStyleDrawer.cs @@ -12,7 +12,7 @@ namespace XCharts.Editor public override void OnGUI(Rect pos, SerializedProperty prop, GUIContent label) { base.OnGUI(pos, prop, label); - if (MakeComponentFoldout(prop, "m_Show")) + if (MakeComponentFoldout(prop, "m_Show", true)) { ++EditorGUI.indentLevel; PropertyField(prop, "m_Position"); diff --git a/Editor/ChildComponents/LevelStyleDrawer.cs b/Editor/ChildComponents/LevelStyleDrawer.cs index acca8caf..38fb60aa 100644 --- a/Editor/ChildComponents/LevelStyleDrawer.cs +++ b/Editor/ChildComponents/LevelStyleDrawer.cs @@ -12,7 +12,7 @@ namespace XCharts.Editor public override void OnGUI(Rect pos, SerializedProperty prop, GUIContent label) { base.OnGUI(pos, prop, label); - if (MakeComponentFoldout(prop, "m_Show")) + if (MakeComponentFoldout(prop, "m_Show", true)) { ++EditorGUI.indentLevel; PropertyListField(prop, "m_Levels"); diff --git a/Editor/ChildComponents/LineArrowDrawer.cs b/Editor/ChildComponents/LineArrowDrawer.cs index 5029f0ff..35929365 100644 --- a/Editor/ChildComponents/LineArrowDrawer.cs +++ b/Editor/ChildComponents/LineArrowDrawer.cs @@ -12,7 +12,7 @@ namespace XCharts.Editor public override void OnGUI(Rect pos, SerializedProperty prop, GUIContent label) { base.OnGUI(pos, prop, label); - if (MakeComponentFoldout(prop, "")) + if (MakeComponentFoldout(prop, "", true)) { ++EditorGUI.indentLevel; PropertyField(prop, "m_Width"); @@ -32,7 +32,7 @@ namespace XCharts.Editor public override void OnGUI(Rect pos, SerializedProperty prop, GUIContent label) { base.OnGUI(pos, prop, label); - if (MakeComponentFoldout(prop, "m_Show")) + if (MakeComponentFoldout(prop, "m_Show", true)) { ++EditorGUI.indentLevel; PropertyField(prop, "m_Position"); diff --git a/Editor/ChildComponents/LineDrawer.cs b/Editor/ChildComponents/LineDrawer.cs index ab412603..e88a8cd8 100644 --- a/Editor/ChildComponents/LineDrawer.cs +++ b/Editor/ChildComponents/LineDrawer.cs @@ -12,7 +12,7 @@ namespace XCharts.Editor public override void OnGUI(Rect pos, SerializedProperty prop, GUIContent label) { base.OnGUI(pos, prop, label); - if (MakeComponentFoldout(prop, "m_Show")) + if (MakeComponentFoldout(prop, "m_Show", true)) { ++EditorGUI.indentLevel; DrawExtendeds(prop); diff --git a/Editor/ChildComponents/LineStyleDrawer.cs b/Editor/ChildComponents/LineStyleDrawer.cs index b0c93942..623a5a18 100644 --- a/Editor/ChildComponents/LineStyleDrawer.cs +++ b/Editor/ChildComponents/LineStyleDrawer.cs @@ -12,7 +12,7 @@ namespace XCharts.Editor public override void OnGUI(Rect pos, SerializedProperty prop, GUIContent label) { base.OnGUI(pos, prop, label); - if (MakeComponentFoldout(prop, "m_Show")) + if (MakeComponentFoldout(prop, "m_Show", true)) { ++EditorGUI.indentLevel; PropertyField(prop, "m_Type"); diff --git a/Editor/ChildComponents/LocationDrawer.cs b/Editor/ChildComponents/LocationDrawer.cs index b895d4c3..dd279697 100644 --- a/Editor/ChildComponents/LocationDrawer.cs +++ b/Editor/ChildComponents/LocationDrawer.cs @@ -12,7 +12,7 @@ namespace XCharts.Editor public override void OnGUI(Rect pos, SerializedProperty prop, GUIContent label) { base.OnGUI(pos, prop, label); - if (MakeComponentFoldout(prop, "m_Align")) + if (MakeComponentFoldout(prop, "m_Align", true)) { ++EditorGUI.indentLevel; PropertyField(prop, "m_Top"); diff --git a/Editor/ChildComponents/SettingsDrawer.cs b/Editor/ChildComponents/SettingsDrawer.cs index 8a4b9db7..db2a1c70 100644 --- a/Editor/ChildComponents/SettingsDrawer.cs +++ b/Editor/ChildComponents/SettingsDrawer.cs @@ -12,7 +12,7 @@ namespace XCharts.Editor public override void OnGUI(Rect pos, SerializedProperty prop, GUIContent label) { base.OnGUI(pos, prop, label); - if (MakeComponentFoldout(prop, "m_Show", new HeaderMenuInfo("Reset", () => + if (MakeComponentFoldout(prop, "m_Show", false, new HeaderMenuInfo("Reset", () => { var chart = prop.serializedObject.targetObject as BaseChart; chart.settings.Reset(); diff --git a/Editor/ChildComponents/SymbolStyleDrawer.cs b/Editor/ChildComponents/SymbolStyleDrawer.cs index fe1c1cdc..ed4855d1 100644 --- a/Editor/ChildComponents/SymbolStyleDrawer.cs +++ b/Editor/ChildComponents/SymbolStyleDrawer.cs @@ -13,7 +13,7 @@ namespace XCharts.Editor public override void OnGUI(Rect pos, SerializedProperty prop, GUIContent label) { base.OnGUI(pos, prop, label); - if (MakeComponentFoldout(prop, "m_Show")) + if (MakeComponentFoldout(prop, "m_Show", true)) { ++EditorGUI.indentLevel; var type = (SymbolType)prop.FindPropertyRelative("m_Type").enumValueIndex; diff --git a/Editor/ChildComponents/TextLimitDrawer.cs b/Editor/ChildComponents/TextLimitDrawer.cs index 9ba85653..bcbdfdb4 100644 --- a/Editor/ChildComponents/TextLimitDrawer.cs +++ b/Editor/ChildComponents/TextLimitDrawer.cs @@ -12,7 +12,7 @@ namespace XCharts.Editor public override void OnGUI(Rect pos, SerializedProperty prop, GUIContent label) { base.OnGUI(pos, prop, label); - if (MakeComponentFoldout(prop, "m_Enable")) + if (MakeComponentFoldout(prop, "m_Enable", true)) { ++EditorGUI.indentLevel; PropertyField(prop, "m_MaxWidth"); diff --git a/Editor/ChildComponents/TextStyleDrawer.cs b/Editor/ChildComponents/TextStyleDrawer.cs index 7ec3f7bb..40cff88f 100644 --- a/Editor/ChildComponents/TextStyleDrawer.cs +++ b/Editor/ChildComponents/TextStyleDrawer.cs @@ -15,7 +15,7 @@ namespace XCharts.Editor public override void OnGUI(Rect pos, SerializedProperty prop, GUIContent label) { base.OnGUI(pos, prop, label); - if (MakeComponentFoldout(prop, "")) + if (MakeComponentFoldout(prop, "", true)) { ++EditorGUI.indentLevel; #if dUI_TextMeshPro diff --git a/Editor/ChildComponents/ThemeDrawer.cs b/Editor/ChildComponents/ThemeDrawer.cs index 04bc2d24..6c443f2a 100644 --- a/Editor/ChildComponents/ThemeDrawer.cs +++ b/Editor/ChildComponents/ThemeDrawer.cs @@ -19,7 +19,7 @@ namespace XCharts.Editor var defaultWidth = pos.width; var defaultX = pos.x; var chart = prop.serializedObject.targetObject as BaseChart; - if (MakeComponentFoldout(prop, "m_Show", new HeaderMenuInfo("Reset|Reset to theme default color", () => + if (MakeComponentFoldout(prop, "m_Show", false, new HeaderMenuInfo("Reset|Reset to theme default color", () => { chart.theme.sharedTheme.ResetTheme(); chart.RefreshAllComponent(); diff --git a/Editor/ChildComponents/TitleStyleDrawer.cs b/Editor/ChildComponents/TitleStyleDrawer.cs index 12b1adc0..3ee73441 100644 --- a/Editor/ChildComponents/TitleStyleDrawer.cs +++ b/Editor/ChildComponents/TitleStyleDrawer.cs @@ -11,7 +11,7 @@ namespace XCharts.Editor public override void OnGUI(Rect pos, SerializedProperty prop, GUIContent label) { base.OnGUI(pos, prop, label); - if (MakeComponentFoldout(prop, "m_Show")) + if (MakeComponentFoldout(prop, "m_Show", true)) { ++EditorGUI.indentLevel; PropertyField(prop, "m_OffsetCenter"); diff --git a/Editor/MainComponents/AxisEditor.cs b/Editor/MainComponents/AxisEditor.cs index 3cae7e6f..d1d0fb6b 100644 --- a/Editor/MainComponents/AxisEditor.cs +++ b/Editor/MainComponents/AxisEditor.cs @@ -148,7 +148,7 @@ namespace XCharts.Editor public override void OnGUI(Rect pos, SerializedProperty prop, GUIContent label) { base.OnGUI(pos, prop, label); - if (MakeComponentFoldout(prop, "m_Show")) + if (MakeComponentFoldout(prop, "m_Show", true)) { ++EditorGUI.indentLevel; PropertyField(prop, "m_Inside"); @@ -176,7 +176,7 @@ namespace XCharts.Editor public override void OnGUI(Rect pos, SerializedProperty prop, GUIContent label) { base.OnGUI(pos, prop, label); - if (MakeComponentFoldout(prop, "m_Show")) + if (MakeComponentFoldout(prop, "m_Show", true)) { ++EditorGUI.indentLevel; PropertyField(prop, "m_Name"); @@ -195,7 +195,7 @@ namespace XCharts.Editor public override void OnGUI(Rect pos, SerializedProperty prop, GUIContent label) { base.OnGUI(pos, prop, label); - if (MakeComponentFoldout(prop, "m_Show")) + if (MakeComponentFoldout(prop, "m_Show", true)) { ++EditorGUI.indentLevel; PropertyField(prop, "m_Color"); diff --git a/Editor/MainComponents/MarkAreaEditor.cs b/Editor/MainComponents/MarkAreaEditor.cs index b51b69a4..6ca86420 100644 --- a/Editor/MainComponents/MarkAreaEditor.cs +++ b/Editor/MainComponents/MarkAreaEditor.cs @@ -28,7 +28,7 @@ namespace XCharts.Editor public override void OnGUI(Rect pos, SerializedProperty prop, GUIContent label) { base.OnGUI(pos, prop, label); - if (MakeComponentFoldout(prop, "")) + if (MakeComponentFoldout(prop, "", true)) { ++EditorGUI.indentLevel; var type = (MarkAreaType)(prop.FindPropertyRelative("m_Type")).enumValueIndex; diff --git a/Editor/MainComponents/MarkLineEditor.cs b/Editor/MainComponents/MarkLineEditor.cs index dde0250a..053895d7 100644 --- a/Editor/MainComponents/MarkLineEditor.cs +++ b/Editor/MainComponents/MarkLineEditor.cs @@ -25,7 +25,7 @@ namespace XCharts.Editor public override void OnGUI(Rect pos, SerializedProperty prop, GUIContent label) { base.OnGUI(pos, prop, label); - if (MakeComponentFoldout(prop, "")) + if (MakeComponentFoldout(prop, "", true)) { ++EditorGUI.indentLevel; var type = (MarkLineType)(prop.FindPropertyRelative("m_Type")).enumValueIndex; diff --git a/Editor/MainComponents/RadarCoordEditor.cs b/Editor/MainComponents/RadarCoordEditor.cs index d49b45e3..8b3c076b 100644 --- a/Editor/MainComponents/RadarCoordEditor.cs +++ b/Editor/MainComponents/RadarCoordEditor.cs @@ -37,7 +37,7 @@ namespace XCharts.Editor public override void OnGUI(Rect pos, SerializedProperty prop, GUIContent label) { base.OnGUI(pos, prop, label); - if (MakeComponentFoldout(prop, "")) + if (MakeComponentFoldout(prop, "", true)) { ++EditorGUI.indentLevel; PropertyField(prop, "m_Name"); diff --git a/Editor/Utilities/ChartEditorHelper.cs b/Editor/Utilities/ChartEditorHelper.cs index 6df5d627..bbdee5da 100644 --- a/Editor/Utilities/ChartEditorHelper.cs +++ b/Editor/Utilities/ChartEditorHelper.cs @@ -166,7 +166,7 @@ namespace XCharts.Editor } public static bool MakeComponentFoldout(ref Rect drawRect, Dictionary heights, Dictionary moduleToggle, string key, string content, SerializedProperty prop, - params HeaderMenuInfo[] menus) + bool propEnable, params HeaderMenuInfo[] menus) { var sourRect = drawRect; float defaultWidth = drawRect.width; @@ -180,7 +180,11 @@ namespace XCharts.Editor { if (prop.propertyType == SerializedPropertyType.Boolean) { - MakeBool(drawRect, prop); + if (!propEnable) + using (new EditorGUI.DisabledScope(true)) + MakeBool(drawRect, prop); + else + MakeBool(drawRect, prop); } else { diff --git a/Editor/Widgets/XCProgressBarEditor.cs b/Editor/Widgets/ProgressBarEditor.cs similarity index 90% rename from Editor/Widgets/XCProgressBarEditor.cs rename to Editor/Widgets/ProgressBarEditor.cs index 9d4d7dc3..8d57260a 100644 --- a/Editor/Widgets/XCProgressBarEditor.cs +++ b/Editor/Widgets/ProgressBarEditor.cs @@ -4,15 +4,15 @@ using XCharts.Runtime; namespace XCharts.Editor { - [CustomEditor(typeof(XCProgressBar), false)] - public class XCProgressBarEditor : UnityEditor.Editor + [CustomEditor(typeof(ProgressBar), false)] + public class ProgressBarEditor : UnityEditor.Editor { [MenuItem("XCharts/ProgressBar", priority = 200)] [MenuItem("GameObject/XCharts/ProgressBar", priority = 200)] public static void AddPyramidChart() { - XChartsEditor.AddChart("ProgressBar"); + XChartsEditor.AddChart("ProgressBar"); } protected SerializedProperty m_Script; diff --git a/Editor/Widgets/XCProgressBarEditor.cs.meta b/Editor/Widgets/ProgressBarEditor.cs.meta similarity index 100% rename from Editor/Widgets/XCProgressBarEditor.cs.meta rename to Editor/Widgets/ProgressBarEditor.cs.meta diff --git a/README.md b/README.md index 9904ccba..d59fabde 100644 --- a/README.md +++ b/README.md @@ -9,6 +9,7 @@
一款基于UGUI的数据可视化图表插件。
+ English Doc

@@ -18,10 +19,10 @@ - + - - + + @@ -42,169 +43,4 @@

-A powerful, easy-to-use, configurable charting and data visualization library for Unity. Supporting line, bar, pie, radar, scatter, heatmap, gauge, ring, polar, liquid and other common chart. - -[XCharts Homepage](https://github.com/monitor1394/unity-ugui-XCharts) -[XCharts Q&A](https://github.com/monitor1394/unity-ugui-XCharts/blob/master/Assets/XCharts/Documentation/xcharts-questions-and-answers-EN.md) -[XCharts API](https://github.com/monitor1394/unity-ugui-XCharts/blob/master/Assets/XCharts/Documentation/xcharts-api-EN.md) -[XCharts Configuration](https://github.com/monitor1394/unity-ugui-XCharts/blob/master/Assets/XCharts/Documentation/xcharts-configuration-EN.md) -[XCharts Changelog](https://github.com/monitor1394/unity-ugui-XCharts/blob/master/Assets/XCharts/CHANGELOG-EN.md) -[Tutorial - Get start with XCharts in 5 minute](https://github.com/monitor1394/unity-ugui-XCharts/blob/master/Doc/tutorial--get-start-with-xcharts-in-5-minute-EN.md) - -## XCharts 2.0 - -* Underlevel reconstruction, layered rendering, optimized scalability, support more data. -* Support for multi-component patterns. -* Support for any combination of most charts. -* Support theme customization, import and export, and more theme configuration parameters. -* Support global adjustment of configuration parameters. -* Added support for `TextMeshPro`. -* Added `CandlestickChart`. -* __ Note:__ `2.0` has undergone a lot of refactoring and adjustments and is not fully compatible with version `1.0`, so `1.0` should not be directly upgraded to `2.0`. Some parameter Settings may be reset to default values after upgrading. - -## Features - -* Rich built-in examples and templates, parameter visualization configuration, effect real-time preview, pure code drawing. -* Support line, bar, pie, radar, scatter, heatmaps, gauge, ring, polar, liquid and other common chart. -* Support line graph, curve graph, area graph, step graph and other LineChart. -* Support parallel bar, stack bar, stack percentage bar, zebra bar and other BarChart. -* Support ring, rose and other PieChart. -* Support line-bar chart, scatter-line chart and other combination chart. -* Support solid line, curve, ladder line, dotted line, dash line, dot line, double dot line and other lines. -* Support custom theme, built-in theme switching. -* Support custom chart content drawing, drawing points, line, curve, triangle, quadrilateral, circle, ring, sector, border, arrow and other drawing API. -* Support interactive operations such as data filtering, view zooming and detail display on PC and mobile terminals. -* Support 10,000-level big data rendering. - -## Screenshot - -![linechart](https://github.com/monitor1394/unity-ugui-XCharts/blob/master/Doc/screenshot/xcharts-line.png) -![barchart](https://github.com/monitor1394/unity-ugui-XCharts/blob/master/Doc/screenshot/xcharts-bar.png) -![piechart](https://github.com/monitor1394/unity-ugui-XCharts/blob/master/Doc/screenshot/xcharts-pie.png) -![radarchart](https://github.com/monitor1394/unity-ugui-XCharts/blob/master/Doc/screenshot/xcharts-radar.png) -![scatterchart](https://github.com/monitor1394/unity-ugui-XCharts/blob/master/Doc/screenshot/xcharts-scatter.png) -![heatmapchart](https://github.com/monitor1394/unity-ugui-XCharts/blob/master/Doc/screenshot/xcharts-heatmap.png) -![gaugechart](https://github.com/monitor1394/unity-ugui-XCharts/blob/master/Doc/screenshot/xcharts-gauge.png) -![ringchart](https://github.com/monitor1394/unity-ugui-XCharts/blob/master/Doc/screenshot/xcharts-ring.png) -![polarchart](https://github.com/monitor1394/unity-ugui-XCharts/blob/master/Doc/screenshot/xcharts-polar.png) -![liquidchart](https://github.com/monitor1394/unity-ugui-XCharts/blob/master/Doc/screenshot/xcharts-liquid.png) -![combinations](https://github.com/monitor1394/unity-ugui-XCharts/blob/master/Doc/screenshot/xcharts-combinations.png) - -## Cheat Sheet - -![cheatsheet](https://github.com/monitor1394/unity-ugui-XCharts/blob/master/Doc/screenshot/xcharts-cheatsheet.gif) - -`XCharts` consist of components and data. Different components and data can be combined into different types of charts. The component is divided into main component and sub component. The main component contains the sub components. - -`XCharts` main components: - -* `Theme` theme component, which can configure the default colors, fonts and so on. -* `Title` title component, which contains the main title and subtitle. -* `Legend` legend component, which represent different sets of symbols, colors, and names. You can control which series are not displayed by clicking on the legend. -* `Grid` grid component, drawing grid in rectangular coordinate system. Up to two X axes and two Y axes can be placed within a grid component. You can draw line, bar and scatter chart on the grid. -* `Axis` axis component, the axis of a rectangular coordinate system. Supports the upper and lower X axes and the left and right Y axes. -* `Series` series component, a list of serie. A chart can contain many different series, and each series determines its own chart type by type. -* `Tooltip` tooltip component, feedback more details of the data indicated by the mouse at the time. -* `DataZoom` data zoom component, used for area zooming so you can focus on detailed data information, or overview the data as a whole, or remove the impact of outliers. -* `VisualMap` visual mapping component, you can map data in different colors. -* `Radar` radar component, suitable for radar chart only. -* `Settings` global Settings component, Some global parameters can be adjusted. Use the default values in general and adjust them as needed. - -`XCharts` support chart: - -* `LineChart` -* `BarChart` -* `PieChart` -* `RadarChart` -* `ScatterChart` -* `HeatmapChart` -* `GuageChart` -* `RingChart` -* `PolarChart` -* `LiquidChart` - -The following is the relationship structure of LineChart: - -``` js -. -├── LineChart -. ├── ThemeInfo - ├── Title - │ └── Location - ├── Legend - │ └── Location - ├── Tooltip - ├── DataZoom - ├── VisualMap - ├── Grid - ├── Axis - │ ├── AxisLine - │ ├── AxisName - │ ├── AxisLabel - │ ├── AxisTick - │ └── AxisSplitArea - ├── Series - │ ├── ItemStyle - │ ├── AreaStyle - │ ├── SerieSymbol - │ ├── LineStyle - │ ├── LineArrow - │ ├── SerieLabel - │ ├── Emphasis - │ ├── Animation - │ └── SerieData - └── Settings -``` - -## Environment - -* Unity2017.4.27f1 -* .Net 3.5 -* macOS 10.15.4 - -## Usage - -* This project was developed under `Unity 2017.4.27f1` and `.net 3.5`, tested normally on `Unity 5`, `Unity 2018` and `Unity 2019`. It can theoretically run on any version that supports `UGUI`. -* Download the source code or `unitypackage` to import into your project. If `Unity` version are `2018.3` or above, it is recommended to import packages through `Package Manager`: - 1. Open the `manifest.json` file under `Packages` directory and add under `dependencies`: - ``` json - "com.monitor1394.xcharts": "https://github.com/monitor1394/unity-ugui-XCharts.git#2.0-upm", - ``` - 2. Going back to `Unity`, it may take 3 to 5 minutes to download. - 3. If you want to delete `XCharts`, just delete the content added in step 1. - 4. If you want to update `XCharts`, open `manifest.json` file , delete the content about `com.monitor1394.xcharts` under `lock`, it will download anagain. Also can check For update in `components-> XCharts -> Check For Update`. - -* Add a chart in Editor quickly: - 1. In `Hierarchy`, right-click menu `XChart->LineChart`. - 2. In unity menu bar, `Component->XCharts->LineChart`. - 3. In `Inspector`,`Add Component->LineChart`. - 4. Then a simple line chart is done. - 5. In `Inspector` you can adjust the parameters of components, and in `Game` will feedback the adjustment effect in realtime 。the detail of parameters go to see: [XCharts Configuration](https://github.com/monitor1394/unity-ugui-XCharts/blob/master/Assets/XCharts/Documentation/xcharts-configuration-EN.md). - -* See more examples of code dynamic control: [Tutorial - Get start with XCharts in 5 minute](https://github.com/monitor1394/unity-ugui-XCharts/blob/master/Doc/tutorial--get-start-with-xcharts-in-5-minute-EN.md). - -* Enable TextMeshPro: - 1. `XCharts -> TextMeshPro Enable` or `Project Setting -> XCharts -> Enable TextMeshPro` - 2. `Project Setting -> XCharts -> Settings -> TMP Font` set the TextMeshPro font. - 3. If the chart does not initialize properly, you can use the `Remove All Chart Object` button to clean up the chart and reinitialize it. - -## Documents - -* [XCharts Homepage](https://github.com/monitor1394/unity-ugui-XCharts) -* [XCharts Q&A](https://github.com/monitor1394/unity-ugui-XCharts/blob/master/Assets/XCharts/Documentation/xcharts-questions-and-answers-EN.md) -* [XCharts API](https://github.com/monitor1394/unity-ugui-XCharts/blob/master/Assets/XCharts/Documentation/xcharts-api-EN.md) -* [XCharts Configuration](https://github.com/monitor1394/unity-ugui-XCharts/blob/master/Assets/XCharts/Documentation/xcharts-configuration-EN.md) -* [XCharts Changelog](https://github.com/monitor1394/unity-ugui-XCharts/blob/master/Assets/XCharts/CHANGELOG-EN.md) -* [XCharts Tutorial: Get start with XCharts in 5 minute](https://github.com/monitor1394/unity-ugui-XCharts/blob/master/Doc/tutorial--get-start-with-xcharts-in-5-minute-EN.md) - -## Changelog - -[XCharts Changelog](https://github.com/monitor1394/unity-ugui-XCharts/blob/master/Assets/XCharts/CHANGELOG.md) - -## Licenses - -[MIT License](https://github.com/monitor1394/unity-ugui-XCharts/blob/master/Assets/XCharts/LICENSE.md) - -## Contact - -gmail: monitor1394@gmail.com +一款基于`UGUI`的功能强大、易用、参数可配置的数据可视化图表插件。支持折线图、柱状图、饼图、雷达图、散点图、热力图、环形图、K线图、极坐标、平行坐标等常见图表。 \ No newline at end of file diff --git a/Runtime/Component/Debug/DebugInfo.cs b/Runtime/Component/Debug/DebugInfo.cs index a822415f..7914e42b 100644 --- a/Runtime/Component/Debug/DebugInfo.cs +++ b/Runtime/Component/Debug/DebugInfo.cs @@ -9,6 +9,9 @@ namespace XCharts.Runtime [Serializable] public class DebugInfo { + #pragma warning disable 0414 + [SerializeField] private bool m_Show = true; + #pragma warning restore 0414 [SerializeField] private bool m_ShowDebugInfo = false; [SerializeField] protected bool m_ShowAllChartObject = false; [SerializeField] protected bool m_FoldSeries = false; diff --git a/Runtime/Helper/SerieLabelHelper.cs b/Runtime/Helper/SerieLabelHelper.cs index 156bbba9..f9993d05 100644 --- a/Runtime/Helper/SerieLabelHelper.cs +++ b/Runtime/Helper/SerieLabelHelper.cs @@ -76,64 +76,6 @@ namespace XCharts.Runtime } } - public static void SetRingLabelText(Serie serie, ThemeStyle theme) - { - for (int i = 0; i < serie.dataCount; i++) - { - var serieData = serie.data[i]; - var serieLabel = SerieHelper.GetSerieLabel(serie, serieData, serieData.context.highlight); - if (serieLabel != null && serieLabel.show && serieData.labelObject != null) - { - if (!serie.show || !serieData.show) - { - serieData.SetLabelActive(false); - continue; - } - var value = serieData.GetData(0); - var total = serieData.GetData(1); - var content = SerieLabelHelper.GetFormatterContent(serie, serieData, value, total, null, Color.clear); - serieData.SetLabelActive(true); - serieData.labelObject.SetText(content); - serieData.labelObject.SetTextColor(GetLabelColor(serie, theme, i)); - - if (serieLabel.position == LabelStyle.Position.Bottom) - { - var labelWidth = serieData.GetLabelWidth(); - if (serie.clockwise) - serieData.labelObject.SetLabelPosition(serieData.context.labelPosition - new Vector3(labelWidth / 2, 0)); - else - serieData.labelObject.SetLabelPosition(serieData.context.labelPosition + new Vector3(labelWidth / 2, 0)); - } - else - { - serieData.labelObject.SetLabelPosition(serieData.context.labelPosition); - } - } - } - } - - public static void SetLiquidLabelText(Serie serie, ThemeStyle theme, int colorIndex) - { - var serieData = serie.GetSerieData(0); - if (serieData == null) return; - var serieLabel = SerieHelper.GetSerieLabel(serie, serieData, serieData.context.highlight); - if (serieLabel.show && serieData.labelObject != null) - { - if (!serie.show || !serieData.show) - { - serieData.SetLabelActive(false); - return; - } - var value = serieData.GetData(0); - var total = serie.max - serie.min; - var content = SerieLabelHelper.GetFormatterContent(serie, serieData, value, total, null, Color.clear); - serieData.SetLabelActive(true); - serieData.labelObject.SetText(content); - serieData.labelObject.SetTextColor(GetLabelColor(serie, theme, colorIndex)); - serieData.labelObject.SetLabelPosition(serieData.context.labelPosition + serieLabel.offset); - } - } - public static void UpdatePieLabelPosition(Serie serie, SerieData serieData) { if (serieData.labelObject == null) return; diff --git a/Runtime/Internal/BaseChart.Serie.cs b/Runtime/Internal/BaseChart.Serie.cs index 1e4a7245..a3f66e52 100644 --- a/Runtime/Internal/BaseChart.Serie.cs +++ b/Runtime/Internal/BaseChart.Serie.cs @@ -146,6 +146,7 @@ namespace XCharts.Runtime public void RemoveSerie(Serie serie) { serie.OnRemove(); + m_SerieHandlers.Remove(serie.handler); m_Series.Remove(serie); RefreshChart(); } diff --git a/Runtime/Internal/BaseGraph.API.cs b/Runtime/Internal/BaseGraph.API.cs index 48c23458..83f97407 100644 --- a/Runtime/Internal/BaseGraph.API.cs +++ b/Runtime/Internal/BaseGraph.API.cs @@ -143,9 +143,9 @@ namespace XCharts.Runtime } /// - /// 移除并重新初始化所有组件。 + /// 移除并重新创建所有图表的Object。 /// - public void RemoveAndReinitChartObject() + public void RebuildChartObject() { ChartHelper.DestroyAllChildren(transform); SetAllComponentDirty(); diff --git a/Runtime/Internal/BaseGraph.cs b/Runtime/Internal/BaseGraph.cs index e4910dfc..118b3e5f 100644 --- a/Runtime/Internal/BaseGraph.cs +++ b/Runtime/Internal/BaseGraph.cs @@ -125,7 +125,7 @@ namespace XCharts.Runtime if (m_EnableTextMeshPro != enableTextMeshPro) { m_EnableTextMeshPro = enableTextMeshPro; - RemoveAndReinitChartObject(); + RebuildChartObject(); } } diff --git a/Runtime/Internal/Utilities/ChartHelper.cs b/Runtime/Internal/Utilities/ChartHelper.cs index 64923765..8f1bd414 100644 --- a/Runtime/Internal/Utilities/ChartHelper.cs +++ b/Runtime/Internal/Utilities/ChartHelper.cs @@ -903,9 +903,9 @@ namespace XCharts.Runtime return !ChartHelper.IsClearColor(color) && color.a == 0; } - public static float GetActualValue(float valueOrRate, float total) + public static float GetActualValue(float valueOrRate, float total, float maxRate = 1.5f) { - if (valueOrRate >= -1.5f && valueOrRate <= 1.5f) return valueOrRate * total; + if (valueOrRate >= -maxRate && valueOrRate <= maxRate) return valueOrRate * total; else return valueOrRate; } } diff --git a/Runtime/Internal/Utilities/ComponentHelper.cs b/Runtime/Internal/Utilities/ComponentHelper.cs index 50981adf..f273734b 100644 --- a/Runtime/Internal/Utilities/ComponentHelper.cs +++ b/Runtime/Internal/Utilities/ComponentHelper.cs @@ -1,7 +1,6 @@ using System.Collections.Generic; -using UnityEngine; namespace XCharts.Runtime { diff --git a/Runtime/Internal/XChartsMgr.cs b/Runtime/Internal/XChartsMgr.cs index 8742be9a..4879a9ea 100644 --- a/Runtime/Internal/XChartsMgr.cs +++ b/Runtime/Internal/XChartsMgr.cs @@ -122,7 +122,7 @@ namespace XCharts.Runtime foreach (var chart in chartList) { if (chart != null) - chart.RemoveAndReinitChartObject(); + chart.RebuildChartObject(); } } diff --git a/Runtime/Serie/Heatmap/Heatmap.cs b/Runtime/Serie/Heatmap/Heatmap.cs index dfd1f8ea..84c51394 100644 --- a/Runtime/Serie/Heatmap/Heatmap.cs +++ b/Runtime/Serie/Heatmap/Heatmap.cs @@ -6,6 +6,7 @@ namespace XCharts.Runtime [System.Serializable] [SerieHandler(typeof(HeatmapHandler), true)] [DefaultAnimation(AnimationType.LeftToRight)] + [RequireChartComponent(typeof(VisualMap))] [SerieExtraComponent(typeof(LabelStyle), typeof(Emphasis))] public class Heatmap : Serie, INeedSerieContainer { diff --git a/Runtime/Widgets/XCProgressBar.cs b/Runtime/Widgets/ProgressBar.cs similarity index 98% rename from Runtime/Widgets/XCProgressBar.cs rename to Runtime/Widgets/ProgressBar.cs index 1677180f..734debbf 100644 --- a/Runtime/Widgets/XCProgressBar.cs +++ b/Runtime/Widgets/ProgressBar.cs @@ -8,7 +8,7 @@ namespace XCharts.Runtime [ExecuteInEditMode] [RequireComponent(typeof(RectTransform))] [DisallowMultipleComponent] - public class XCProgressBar : BaseChart + public class ProgressBar : BaseChart { [SerializeField] [Range(0f, 1f)] private float m_Value = 0.5f; [SerializeField] private Color m_BackgroundColor = new Color32(255, 233, 233, 255); diff --git a/Runtime/Widgets/XCProgressBar.cs.meta b/Runtime/Widgets/ProgressBar.cs.meta similarity index 100% rename from Runtime/Widgets/XCProgressBar.cs.meta rename to Runtime/Widgets/ProgressBar.cs.meta diff --git a/Runtime/Widgets/SVGImage.cs b/Runtime/Widgets/SVGImage.cs new file mode 100644 index 00000000..8bf7ac00 --- /dev/null +++ b/Runtime/Widgets/SVGImage.cs @@ -0,0 +1,33 @@ +using UnityEngine; +using UnityEngine.UI; +using XUGL; + +namespace XCharts.Runtime +{ + [ExecuteInEditMode] + public class SVGImage : MaskableGraphic + { + [SerializeField] private bool m_MirrorY; + [SerializeField] private string m_SVGPath; + + private SVGPath m_Path; + + public string svgPath { get { return m_SVGPath; } } + public bool mirrorY { get { return m_MirrorY; } } + + protected override void Awake() + { + base.Awake(); + m_Path = SVGPath.Parse(m_SVGPath); + m_Path.mirrorY = m_MirrorY; + } + + protected override void OnPopulateMesh(VertexHelper vh) + { + vh.Clear(); + if (m_Path != null) + m_Path.Draw(vh); + } + + } +} \ No newline at end of file diff --git a/Runtime/Widgets/SVGImage.cs.meta b/Runtime/Widgets/SVGImage.cs.meta new file mode 100644 index 00000000..cf55b08e --- /dev/null +++ b/Runtime/Widgets/SVGImage.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: fe10ee35a038646b6aedfffb30f84024 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/XUGL/SVG.meta b/Runtime/XUGL/SVG.meta new file mode 100644 index 00000000..bd6001d9 --- /dev/null +++ b/Runtime/XUGL/SVG.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 6e78d1d27fb8f42948af1c6050eb6a46 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/XUGL/SVG/SVG.cs b/Runtime/XUGL/SVG/SVG.cs new file mode 100644 index 00000000..791620d2 --- /dev/null +++ b/Runtime/XUGL/SVG/SVG.cs @@ -0,0 +1,39 @@ +using System.Collections.Generic; +using UnityEngine; +using UnityEngine.UI; + +namespace XUGL +{ + public static class SVG + { + public static bool yMirror = false; + public static void Test(VertexHelper vh) + { + //UGL.DrawSvgPath(vh, "path://M600,800 C625,700 725,700 750,800 S875,900 900,800"); + //UGL.DrawSvgPath(vh, "path://M67.335,33.596L67.335,33.596c-0.002-1.39-1.153-3.183-3.328-4.218h-9.096v-2.07h5.371 c-4.939-2.07-11.199-4.141-14.89-4.141H19.72v12.421v5.176h38.373c4.033,0,8.457-1.035,9.142-5.176h-0.027 c0.076-0.367,0.129-0.751,0.129-1.165L67.335,33.596L67.335,33.596z M27.999,30.413h-3.105v-4.141h3.105V30.413z M35.245,30.413 h-3.104v-4.141h3.104V30.413z M42.491,30.413h-3.104v-4.141h3.104V30.413z M49.736,30.413h-3.104v-4.141h3.104V30.413z M14.544,40.764c1.143,0,2.07-0.927,2.07-2.07V35.59V25.237c0-1.145-0.928-2.07-2.07-2.07H-9.265c-1.143,0-2.068,0.926-2.068,2.07 v10.351v3.105c0,1.144,0.926,2.07,2.068,2.07H14.544L14.544,40.764z M8.333,26.272h3.105v4.141H8.333V26.272z M1.087,26.272h3.105 v4.141H1.087V26.272z M-6.159,26.272h3.105v4.141h-3.105V26.272z M-9.265,41.798h69.352v1.035H-9.265V41.798z"); + //UGL.DrawSvgPath(vh, "path://M30.9,53.2C16.8,53.2,5.3,41.7,5.3,27.6S16.8,2,30.9,2C45,2,56.4,13.5,56.4,27.6S45,53.2,30.9,53.2z M30.9,3.5C17.6,3.5,6.8,14.4,6.8,27.6c0,13.3,10.8,24.1,24.101,24.1C44.2,51.7,55,40.9,55,27.6C54.9,14.4,44.1,3.5,30.9,3.5z M36.9,35.8c0,0.601-0.4,1-0.9,1h-1.3c-0.5,0-0.9-0.399-0.9-1V19.5c0-0.6,0.4-1,0.9-1H36c0.5,0,0.9,0.4,0.9,1V35.8z M27.8,35.8 c0,0.601-0.4,1-0.9,1h-1.3c-0.5,0-0.9-0.399-0.9-1V19.5c0-0.6,0.4-1,0.9-1H27c0.5,0,0.9,0.4,0.9,1L27.8,35.8L27.8,35.8z"); + + //人体 + UGL.DrawSvgPath(vh, "path://M36.7,102.84c-1.17,2.54-2.99,4.98-3.39,7.63c-1.51,9.89-3.31,19.58-1.93,29.95 c0.95,7.15-2.91,14.82-3.57,22.35c-0.64,7.36-0.2,14.86,0.35,22.25c0.12,1.68,2.66,3.17,4.67,5.4c-0.6,0.82-1.5,2.22-2.58,3.48 c-0.96,1.12-1.96,2.35-3.21,3.04c-1.71,0.95-3.71,2.03-5.51,1.9c-1.18-0.08-3.04-2.13-3.16-3.43c-0.44-4.72,0-9.52-0.41-14.25 c-0.94-10.88-2.32-21.72-3.24-32.61c-0.49-5.84-1.63-12.01-0.35-17.54c3.39-14.56,2.8-28.84,0.36-43.4 c-2.71-16.16-1.06-32.4,0.54-48.59c0.91-9.22,4.62-17.36,8.53-25.57c1.32-2.77,1.88-6.84,0.87-9.62C21.89-3.77,18.09-11,14.7-18.38 c-0.56,0.1-1.13,0.21-1.69,0.31C10.17-11.52,6.29-5.2,4.71,1.65C2.05,13.21-4.42,22.3-11.43,31.28c-1.32,1.69-2.51,3.5-3.98,5.04 c-4.85,5.08-3.25,10.98-2.32,16.82c0.25,1.53,0.52,3.06,0.77,4.59c-0.53,0.22-1.07,0.43-1.6,0.65c-1.07-2.09-2.14-4.19-3.28-6.44 c-6.39,2.91-2.67,9.6-5.23,15.16c-1.61-3.31-2.77-5.68-3.93-8.06c0-0.33,0-0.67,0-1c6.96-16.08,14.63-31.9,20.68-48.31 C-5.24-4.07-2.03-18.55,2-32.73c0.36-1.27,0.75-2.53,0.98-3.82c1.36-7.75,4.19-10.23,11.88-10.38c1.76-0.04,3.52-0.21,5.76-0.35 c-0.55-3.95-1.21-7.3-1.45-10.68c-0.61-8.67,0.77-16.69,7.39-23.19c2.18-2.14,4.27-4.82,5.25-7.65c2.39-6.88,11.66-9,16.94-8.12 c5.92,0.99,12.15,7.93,12.16,14.12c0.01,9.89-5.19,17.26-12.24,23.68c-2.17,1.97-5.35,4.77-5.17,6.94c0.31,3.78,4.15,5.66,8.08,6.04 c1.82,0.18,3.7,0.37,5.49,0.1c5.62-0.85,8.8,2.17,10.85,6.73C73.38-27.19,78.46-14.9,84.2-2.91c1.52,3.17,4.52,5.91,7.41,8.09 c7.64,5.77,15.57,11.16,23.45,16.61c2.28,1.58,4.64,3.23,7.21,4.14c5.18,1.84,8.09,5.63,9.82,10.46c0.45,1.24,0.19,3.71-0.6,4.18 c-1.06,0.63-3.15,0.27-4.44-0.38c-7.05-3.54-12.84-8.88-19.14-13.5c-3.5-2.57-7.9-4-12.03-5.6c-9.44-3.66-17.73-8.42-22.5-18.09 c-2.43-4.94-6.09-9.27-9.69-14.61c-1.2,10.98-4.46,20.65,1.14,31.19c6.62,12.47,5.89,26.25,1.21,39.49 c-2.52,7.11-6.5,13.74-8.67,20.94c-1.91,6.33-2.2,13.15-3.23,19.75c-0.72,4.63-0.84,9.48-2.36,13.84 c-2.49,7.16-6.67,13.83-5.84,21.82c0.42,4.02,1.29,7.99,2.1,12.8c-3.74-0.49-7.47-0.4-10.67-1.66c-1.33-0.53-2.43-4.11-2.07-6.01 c1.86-9.94,3.89-19.69,0.07-29.74C34.55,108.63,36.19,105.52,36.7,102.84c1.25-8.45,2.51-16.89,3.71-24.9 c-0.83-0.58-0.85-0.59-0.87-0.61c-0.03,0.16-0.07,0.32-0.09,0.48C38.53,86.15,37.62,94.5,36.7,102.84z"); + + //UGL.DrawSvgPath(vh, "path://M29.902,23.275c1.86,0,3.368-1.506,3.368-3.365c0-1.859-1.508-3.365-3.368-3.365 c-1.857,0-3.365,1.506-3.365,3.365C26.537,21.769,28.045,23.275,29.902,23.275z M36.867,30.74c-1.666-0.467-3.799-1.6-4.732-4.199 c-0.932-2.6-3.131-2.998-4.797-2.998s-7.098,3.894-7.098,3.894c-1.133,1.001-2.1,6.502-0.967,6.769 c1.133,0.269,1.266-1.533,1.934-3.599c0.666-2.065,3.797-3.466,3.797-3.466s0.201,2.467-0.398,3.866 c-0.599,1.399-1.133,2.866-1.467,6.198s-1.6,3.665-3.799,6.266c-2.199,2.598-0.6,3.797,0.398,3.664 c1.002-0.133,5.865-5.598,6.398-6.998c0.533-1.397,0.668-3.732,0.668-3.732s0,0,2.199,1.867c2.199,1.865,2.332,4.6,2.998,7.73 s2.332,0.934,2.332-0.467c0-1.401,0.269-5.465-1-7.064c-1.265-1.6-3.73-3.465-3.73-5.265s1.199-3.732,1.199-3.732 c0.332,1.667,3.335,3.065,5.599,3.399C38.668,33.206,38.533,31.207,36.867,30.74z"); + + //钟表指针 + //UGL.DrawSvgPath(vh, "path://M2090.36389,615.30999 L2090.36389,615.30999 C2091.48372,615.30999 2092.40383,616.194028 2092.44859,617.312956 L2096.90698,728.755929 C2097.05155,732.369577 2094.2393,735.416212 2090.62566,735.56078 C2090.53845,735.564269 2090.45117,735.566014 2090.36389,735.566014 L2090.36389,735.566014 C2086.74736,735.566014 2083.81557,732.63423 2083.81557,729.017692 C2083.81557,728.930412 2083.81732,728.84314 2083.82081,728.755929 L2088.2792,617.312956 C2088.32396,616.194028 2089.24407,615.30999 2090.36389,615.30999 Z"); + + //钟表指针 + //UGL.DrawSvgPath(vh, "path://M2.9,0.7L2.9,0.7c1.4,0,2.6,1.2,2.6,2.6v115c0,1.4-1.2,2.6-2.6,2.6l0,0c-1.4,0-2.6-1.2-2.6-2.6V3.3C0.3,1.9,1.4,0.7,2.9,0.7z"); + } + + public static void DrawPath(VertexHelper vh, string path) + { + var svgPath = SVGPath.Parse(path); + DrawPath(vh, svgPath); + } + + public static void DrawPath(VertexHelper vh, SVGPath path) + { + path.Draw(vh); + } + } +} \ No newline at end of file diff --git a/Runtime/XUGL/SVG/SVG.cs.meta b/Runtime/XUGL/SVG/SVG.cs.meta new file mode 100644 index 00000000..133f0d25 --- /dev/null +++ b/Runtime/XUGL/SVG/SVG.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: cbe2b3aa282ad4cd9b469792fde7e092 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/XUGL/SVG/SVGPath.cs b/Runtime/XUGL/SVG/SVGPath.cs new file mode 100644 index 00000000..07426cd2 --- /dev/null +++ b/Runtime/XUGL/SVG/SVGPath.cs @@ -0,0 +1,203 @@ +using System.Collections.Generic; +using System.Text.RegularExpressions; +using UnityEngine; +using UnityEngine.UI; + +namespace XUGL +{ + public class SVGPath + { + private static Regex s_PathRegex = new Regex(@"(([a-z]|[A-Z])(\d|\.|,|-)*)"); + // private static Regex s_PathValueRegex = new Regex(@"(^[a-z]|[A-Z])\s*(-?\d+\.*\d*)*[\s|,|-]*(\d+\.*\d*)*"); + private static Regex s_PathValueRegex = new Regex(@"(^[a-z]|[A-Z])\s*(-?\d+\.*\d*)*[\s|,|-]*(\d+\.*\d*)*"); + private static Regex s_PathValueRegex2 = new Regex(@"(-?\d+\.?\d*)"); + public bool mirrorY = true; + public List segs = new List(); + + public void AddSegment(SVGPathSeg seg) + { + segs.Add(seg); + } + + public static SVGPath Parse(string path) + { + if (string.IsNullOrEmpty(path)) + return new SVGPath(); + if (path.StartsWith("path://")) + { + path = path.Substring(7); + } + path = path.Replace(' ', ','); + var mc = s_PathRegex.Matches(path); + var svgPath = new SVGPath(); + + foreach (var m in mc) + { + var key = m.ToString(); + if (key.Equals("Z") || key.Equals("z")) + { + var seg = new SVGPathSeg(SVGPathSegType.Z); + seg.raw = key; + seg.relative = key.Equals("z"); + svgPath.AddSegment(seg); + } + else + { + var type = s_PathValueRegex.Match(key).Groups[1].ToString().ToCharArray()[0]; + var mc3 = s_PathValueRegex2.Matches(key); + SVGPathSeg seg = null; + switch (type) + { + case 'M': + case 'm': + seg = new SVGPathSeg(SVGPathSegType.M); + seg.relative = type == 'm'; + break; + case 'L': + case 'l': + seg = new SVGPathSeg(SVGPathSegType.L); + seg.relative = type == 'l'; + break; + case 'H': + case 'h': + seg = new SVGPathSeg(SVGPathSegType.H); + seg.relative = type == 'h'; + break; + case 'V': + case 'v': + seg = new SVGPathSeg(SVGPathSegType.V); + seg.relative = type == 'v'; + break; + case 'C': + case 'c': + seg = new SVGPathSeg(SVGPathSegType.C); + seg.relative = type == 'c'; + break; + case 'S': + case 's': + seg = new SVGPathSeg(SVGPathSegType.S); + seg.relative = type == 's'; + break; + case 'Q': + case 'q': + seg = new SVGPathSeg(SVGPathSegType.Q); + seg.relative = type == 'q'; + break; + case 'T': + case 't': + seg = new SVGPathSeg(SVGPathSegType.T); + seg.relative = type == 't'; + break; + case 'A': + case 'a': + seg = new SVGPathSeg(SVGPathSegType.A); + seg.relative = type == 'a'; + break; + } + if (seg != null) + { + seg.raw = key; + foreach (var m3 in mc3) + { + // if (type == 'c' || type == 'C') + //Debug.LogError("\tmc3:" + type + "," + m3.ToString()); + float p; + if (float.TryParse(m3.ToString(), out p)) + seg.parameters.Add(p); + } + svgPath.AddSegment(seg); + } + } + } + // Debug.LogError(path); + // foreach (var cmd in svgPath.commands) + // { + // Debug.LogError(cmd.raw); + // } + return svgPath; + } + + public void Draw(VertexHelper vh) + { + var sp = Vector2.zero; + var np = Vector2.zero; + var posList = new List(); + var bezierList = new List(); + var cp2 = Vector2.zero; + foreach (var seg in segs) + { + switch (seg.type) + { + case SVGPathSegType.M: + sp = np = seg.relative ? np + seg.p1 : seg.p1; + if (posList.Count > 0) + { + DrawPosList(vh, posList); + } + posList.Add(np); + break; + case SVGPathSegType.L: + np = seg.relative ? np + seg.p1 : seg.p1; + posList.Add(np); + break; + case SVGPathSegType.H: + np = seg.relative ? np + new Vector2(seg.value, 0) : new Vector2(seg.value, np.y); + posList.Add(np); + break; + case SVGPathSegType.V: + np = seg.relative ? np + new Vector2(0, seg.value) : new Vector2(np.x, seg.value); + posList.Add(np); + break; + case SVGPathSegType.C: + var cp1 = seg.relative ? np + seg.p1 : seg.p1; + cp2 = seg.relative ? np + seg.p2 : seg.p2; + var ep = seg.relative ? np + seg.p3 : seg.p3; + var dist = (int)Vector2.Distance(np, ep) * 2; + if (dist < 2) dist = 2; + UGLHelper.GetBezierList2(ref bezierList, np, ep, dist, cp1, cp2); + for (int n = 1; n < bezierList.Count; n++) + posList.Add(bezierList[n]); + np = ep; + break; + case SVGPathSegType.S: + cp1 = np + (np - cp2).normalized * Vector2.Distance(np, cp2); + var scp2 = seg.relative ? np + seg.p1 : seg.p1; + ep = seg.relative ? np + seg.p2 : seg.p2; + dist = (int)Vector2.Distance(np, ep) * 2; + if (dist < 2) dist = 2; + UGLHelper.GetBezierList2(ref bezierList, np, ep, dist, cp1, scp2); + for (int n = 1; n < bezierList.Count; n++) + posList.Add(bezierList[n]); + break; + case SVGPathSegType.Z: + posList.Add(sp); + DrawPosList(vh, posList); + break; + case SVGPathSegType.Q: + case SVGPathSegType.T: + case SVGPathSegType.A: + default: + Debug.LogError("unknow seg:" + seg.type); + break; + } + } + if (posList.Count > 0) + DrawPosList(vh, posList); + //UGL.DrawCricle(vh, sp, 1, Color.black); + } + + private void DrawPosList(VertexHelper vh, List posList) + { + if (mirrorY) + { + for (int i = posList.Count - 1; i >= 0; i--) + { + var pos = posList[i]; + posList[i] = new Vector3(pos.x, -pos.y); + } + } + UGL.DrawLine(vh, posList, 1f, Color.red, false); + posList.Clear(); + } + } +} \ No newline at end of file diff --git a/Runtime/XUGL/SVG/SVGPath.cs.meta b/Runtime/XUGL/SVG/SVGPath.cs.meta new file mode 100644 index 00000000..20f5c8d7 --- /dev/null +++ b/Runtime/XUGL/SVG/SVGPath.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: c4119dc5490ec4f8bbcc67aa6eee024a +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/XUGL/SVG/SVGPathSeg.cs b/Runtime/XUGL/SVG/SVGPathSeg.cs new file mode 100644 index 00000000..acce3614 --- /dev/null +++ b/Runtime/XUGL/SVG/SVGPathSeg.cs @@ -0,0 +1,36 @@ +using System.Collections.Generic; +using System.Text.RegularExpressions; +using UnityEngine; +using UnityEngine.UI; + +namespace XUGL +{ + public class SVGPathSeg + { + public SVGPathSegType type; + public bool relative; + public List parameters = new List(); + public string raw; + + public SVGPathSeg(SVGPathSegType type) + { + this.type = type; + } + + public float value + { + get + { + if (type == SVGPathSegType.H) + return SVG.yMirror ? -parameters[0] : parameters[0]; + else + return parameters[0]; + } + } + public float x { get { return parameters[0]; } } + public float y { get { return SVG.yMirror ? -parameters[1] : parameters[1]; } } + public Vector2 p1 { get { return new Vector2(parameters[0], (SVG.yMirror ? -parameters[1] : parameters[1])); } } + public Vector2 p2 { get { return new Vector2(parameters[2], (SVG.yMirror ? -parameters[3] : parameters[3])); } } + public Vector2 p3 { get { return new Vector2(parameters[4], (SVG.yMirror ? -parameters[5] : parameters[5])); } } + } +} \ No newline at end of file diff --git a/Runtime/XUGL/SVG/SVGPathSeg.cs.meta b/Runtime/XUGL/SVG/SVGPathSeg.cs.meta new file mode 100644 index 00000000..81275598 --- /dev/null +++ b/Runtime/XUGL/SVG/SVGPathSeg.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 2c97d44ceb28a471aa3d657f3984e6b1 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/XUGL/SVG/SVGPathSegType.cs b/Runtime/XUGL/SVG/SVGPathSegType.cs new file mode 100644 index 00000000..174dc1c8 --- /dev/null +++ b/Runtime/XUGL/SVG/SVGPathSegType.cs @@ -0,0 +1,51 @@ +using System.Collections.Generic; +using System.Text.RegularExpressions; +using UnityEngine; +using UnityEngine.UI; + +namespace XUGL +{ + public enum SVGPathSegType + { + /// + /// move to + /// + M, + /// + /// line to + /// + L, + /// + /// horizontal line to + /// + H, + /// + /// vertial line to + /// + V, + /// + /// curve to + /// + C, + /// + /// smooth curve to + /// + S, + /// + /// quadratic bezier curve + /// + Q, + /// + /// smooth quadratic bezier curve to + /// + T, + /// + /// elliptical Arc + /// + A, + /// + /// close path + /// + Z + } +} \ No newline at end of file diff --git a/Runtime/XUGL/SVG/SVGPathSegType.cs.meta b/Runtime/XUGL/SVG/SVGPathSegType.cs.meta new file mode 100644 index 00000000..217d4b68 --- /dev/null +++ b/Runtime/XUGL/SVG/SVGPathSegType.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: ebd7fe1a38c81433697bbe21c2e962ba +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/XUGL/UGL.cs b/Runtime/XUGL/UGL.cs index feaebda5..bac8fef2 100644 --- a/Runtime/XUGL/UGL.cs +++ b/Runtime/XUGL/UGL.cs @@ -122,6 +122,11 @@ namespace XUGL public static void DrawLine(VertexHelper vh, List points, float width, Color32 color, bool smooth) { + for (int i = points.Count - 1; i >= 1; i--) + { + if (UGLHelper.IsValueEqualsVector3(points[i], points[i - 1])) + points.RemoveAt(i); + } if (points.Count < 2) return; else if (points.Count <= 2) { @@ -1796,5 +1801,10 @@ namespace XUGL AddVertToVertexHelper(vh, toUp, toDn, lineColor); } } + + public static void DrawSvgPath(VertexHelper vh, string path) + { + SVG.DrawPath(vh, path); + } } } diff --git a/Runtime/XUGL/UGLExample.cs b/Runtime/XUGL/UGLExample.cs index 834a9d34..a245ec7a 100644 --- a/Runtime/XUGL/UGLExample.cs +++ b/Runtime/XUGL/UGLExample.cs @@ -1,3 +1,4 @@ +using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; @@ -33,7 +34,7 @@ namespace XUGL //背景边框 UGL.DrawSquare(vh, m_Center, m_Width / 2, m_BackgroundColor); - UGL.DrawBorder(vh, m_Center, m_Width, m_Height, 40, Color.green, Color.red, 0, m_BorderRadius,false,1); + UGL.DrawBorder(vh, m_Center, m_Width, m_Height, 40, Color.green, Color.red, 0, m_BorderRadius, false, 1); //点 UGL.DrawCricle(vh, m_LeftTopPos + new Vector3(20, -20), 10, m_DrawColor); diff --git a/Runtime/XUGL/UGLHelper.cs b/Runtime/XUGL/UGLHelper.cs index 64c9efbc..f88d8f0e 100644 --- a/Runtime/XUGL/UGLHelper.cs +++ b/Runtime/XUGL/UGLHelper.cs @@ -43,6 +43,12 @@ namespace XUGL && v1.z == v2.z; } + public static bool IsValueEqualsVector3(Vector3 v1, Vector2 v2) + { + return v1.x == v2.x + && v1.y == v2.y; + } + public static bool IsValueEqualsList(List list1, List list2) { if (list1 == null || list2 == null)