优化切换主题显示效果

This commit is contained in:
monitor1394
2018-10-02 08:57:47 +08:00
parent a62e856c43
commit f7bfc9c73b
5 changed files with 72 additions and 61 deletions

View File

@@ -4,9 +4,12 @@ using xcharts;
public class Demo : MonoBehaviour
{
public Theme theme = Theme.Dark;
private LineChart lineChart;
private float time;
private int count;
private Theme checkTheme = Theme.Dark;
void Awake()
{
@@ -34,5 +37,19 @@ public class Demo : MonoBehaviour
//lineChart.AddData("line1", "key"+count, Random.Range(24.0f, 60.0f));
//lineChart.AddData("line2", "key"+count, Random.Range(24.0f, 60.0f));
}
if(checkTheme != theme)
{
checkTheme = theme;
UpdateTheme(theme);
}
}
void UpdateTheme(Theme theme)
{
var charts = transform.Find("xchart").GetComponentsInChildren<BaseChart>();
foreach(var chart in charts)
{
chart.UpdateTheme(theme);
}
}
}

View File

@@ -196,6 +196,13 @@ namespace xcharts
RefreshChart();
}
public void UpdateTheme(Theme theme)
{
this.theme = theme;
OnThemeChanged();
SetAllDirty();
}
protected void HideChild(string match = null)
{
for (int i = 0; i < transform.childCount; i++)

View File

@@ -3,13 +3,6 @@ using UnityEngine.UI;
namespace xcharts
{
[System.Serializable]
public enum PointType
{
square,
cicle
}
[System.Serializable]
public class LineInfo
{
@@ -17,9 +10,7 @@ namespace xcharts
[Header("Point")]
public bool showPoint = true;
public PointType pointType = PointType.square;
public float pointWid = 1.0f;
public Color pointColor = Color.white;
public float pointWid = 2.5f;
[Header("Smooth")]
public bool smooth = false;
@@ -107,15 +98,15 @@ namespace xcharts
SeriesData data = series.dataList[i];
Vector3 p = new Vector3(startX + i * scaleWid, zeroY + data.value * coordinateHig / max);
switch (lineInfo.pointType)
if(theme == Theme.Dark)
{
case PointType.square:
ChartUtils.DrawPolygon(vh, p, lineInfo.pointWid, lineInfo.pointColor);
break;
case PointType.cicle:
ChartUtils.DrawCricle(vh, p, lineInfo.pointWid, lineInfo.pointColor,
(int)lineInfo.pointWid * 5);
break;
ChartUtils.DrawCricle(vh, p, lineInfo.pointWid, color, (int)lineInfo.pointWid * 5);
}
else
{
ChartUtils.DrawCricle(vh, p, lineInfo.pointWid, Color.white);
ChartUtils.DrawDoughnut(vh, p, lineInfo.pointWid - lineInfo.tickness,
lineInfo.pointWid, 0, 360, color);
}
}
}

View File

@@ -174,6 +174,7 @@ namespace xcharts
radarInfo.backgroundColorList.Add(ThemeInfo.GetColor("#e7e7e7"));
break;
}
InitIndicator();
}
private void DrawData(VertexHelper vh)

View File

@@ -253,7 +253,7 @@ MonoBehaviour:
m_HorizontalOverflow: 1
m_VerticalOverflow: 1
m_LineSpacing: 1
m_Text: 56
m_Text: 70
--- !u!222 &12948879
CanvasRenderer:
m_ObjectHideFlags: 0
@@ -455,7 +455,7 @@ MonoBehaviour:
m_Name:
m_EditorClassIdentifier:
m_Material: {fileID: 0}
m_Color: {r: 1, g: 1, b: 1, a: 1}
m_Color: {r: 0.93333334, g: 0.93333334, b: 0.93333334, a: 1}
m_RaycastTarget: 1
m_OnCullStateChanged:
m_PersistentCalls:
@@ -1215,7 +1215,7 @@ MonoBehaviour:
m_HorizontalOverflow: 1
m_VerticalOverflow: 1
m_LineSpacing: 1
m_Text: 14
m_Text: 17
--- !u!222 &67122460
CanvasRenderer:
m_ObjectHideFlags: 0
@@ -1269,7 +1269,7 @@ MonoBehaviour:
m_Name:
m_EditorClassIdentifier:
m_Material: {fileID: 0}
m_Color: {r: 1, g: 1, b: 1, a: 1}
m_Color: {r: 0.93333334, g: 0.93333334, b: 0.93333334, a: 1}
m_RaycastTarget: 1
m_OnCullStateChanged:
m_PersistentCalls:
@@ -1639,7 +1639,7 @@ MonoBehaviour:
m_Name:
m_EditorClassIdentifier:
m_Material: {fileID: 0}
m_Color: {r: 1, g: 1, b: 1, a: 1}
m_Color: {r: 0.93333334, g: 0.93333334, b: 0.93333334, a: 1}
m_RaycastTarget: 1
m_OnCullStateChanged:
m_PersistentCalls:
@@ -1935,7 +1935,7 @@ MonoBehaviour:
m_Name:
m_EditorClassIdentifier:
m_Material: {fileID: 0}
m_Color: {r: 1, g: 1, b: 1, a: 1}
m_Color: {r: 0.93333334, g: 0.93333334, b: 0.93333334, a: 1}
m_RaycastTarget: 1
m_OnCullStateChanged:
m_PersistentCalls:
@@ -2029,7 +2029,7 @@ MonoBehaviour:
m_HorizontalOverflow: 1
m_VerticalOverflow: 1
m_LineSpacing: 1
m_Text: 42
m_Text: 52
--- !u!222 &224354018
CanvasRenderer:
m_ObjectHideFlags: 0
@@ -2103,7 +2103,7 @@ MonoBehaviour:
m_HorizontalOverflow: 1
m_VerticalOverflow: 1
m_LineSpacing: 1
m_Text: 96
m_Text: 120
--- !u!222 &235400235
CanvasRenderer:
m_ObjectHideFlags: 0
@@ -2416,7 +2416,7 @@ MonoBehaviour:
m_Name:
m_EditorClassIdentifier:
m_Material: {fileID: 0}
m_Color: {r: 1, g: 1, b: 1, a: 1}
m_Color: {r: 0.93333334, g: 0.93333334, b: 0.93333334, a: 1}
m_RaycastTarget: 1
m_OnCullStateChanged:
m_PersistentCalls:
@@ -3060,7 +3060,7 @@ MonoBehaviour:
m_HorizontalOverflow: 1
m_VerticalOverflow: 1
m_LineSpacing: 1
m_Text: 30
m_Text: 37
--- !u!222 &348603706
CanvasRenderer:
m_ObjectHideFlags: 0
@@ -4053,7 +4053,7 @@ MonoBehaviour:
m_Name:
m_EditorClassIdentifier:
m_Material: {fileID: 0}
m_Color: {r: 1, g: 1, b: 1, a: 1}
m_Color: {r: 0.93333334, g: 0.93333334, b: 0.93333334, a: 1}
m_RaycastTarget: 1
m_OnCullStateChanged:
m_PersistentCalls:
@@ -4588,7 +4588,7 @@ MonoBehaviour:
m_HorizontalOverflow: 1
m_VerticalOverflow: 1
m_LineSpacing: 1
m_Text: 42
m_Text: 52
--- !u!222 &471071886
CanvasRenderer:
m_ObjectHideFlags: 0
@@ -4736,7 +4736,7 @@ MonoBehaviour:
m_HorizontalOverflow: 1
m_VerticalOverflow: 1
m_LineSpacing: 1
m_Text: 28
m_Text: 35
--- !u!222 &492961304
CanvasRenderer:
m_ObjectHideFlags: 0
@@ -5713,7 +5713,7 @@ MonoBehaviour:
m_HorizontalOverflow: 1
m_VerticalOverflow: 1
m_LineSpacing: 1
m_Text: 120
m_Text: 150
--- !u!222 &566565926
CanvasRenderer:
m_ObjectHideFlags: 0
@@ -5841,7 +5841,7 @@ MonoBehaviour:
m_Name:
m_EditorClassIdentifier:
m_Material: {fileID: 0}
m_Color: {r: 1, g: 1, b: 1, a: 1}
m_Color: {r: 0.93333334, g: 0.93333334, b: 0.93333334, a: 1}
m_RaycastTarget: 1
m_OnCullStateChanged:
m_PersistentCalls:
@@ -6083,7 +6083,7 @@ MonoBehaviour:
m_HorizontalOverflow: 1
m_VerticalOverflow: 1
m_LineSpacing: 1
m_Text: 90
m_Text: 112
--- !u!222 &635640133
CanvasRenderer:
m_ObjectHideFlags: 0
@@ -6606,7 +6606,7 @@ MonoBehaviour:
m_Name:
m_EditorClassIdentifier:
m_Material: {fileID: 0}
m_Color: {r: 1, g: 1, b: 1, a: 1}
m_Color: {r: 0.93333334, g: 0.93333334, b: 0.93333334, a: 1}
m_RaycastTarget: 1
m_OnCullStateChanged:
m_PersistentCalls:
@@ -7453,7 +7453,7 @@ MonoBehaviour:
m_Name:
m_EditorClassIdentifier:
m_Material: {fileID: 0}
m_Color: {r: 1, g: 1, b: 1, a: 1}
m_Color: {r: 0.93333334, g: 0.93333334, b: 0.93333334, a: 1}
m_RaycastTarget: 1
m_OnCullStateChanged:
m_PersistentCalls:
@@ -7747,9 +7747,7 @@ MonoBehaviour:
lineInfo:
tickness: 0.8
showPoint: 1
pointType: 0
pointWid: 1
pointColor: {r: 1, g: 1, b: 1, a: 1}
pointWid: 2.5
smooth: 0
smoothStyle: 2
area: 1
@@ -7827,7 +7825,7 @@ MonoBehaviour:
m_HorizontalOverflow: 1
m_VerticalOverflow: 1
m_LineSpacing: 1
m_Text: 32
m_Text: 40
--- !u!222 &841332740
CanvasRenderer:
m_ObjectHideFlags: 0
@@ -8104,7 +8102,7 @@ GameObject:
- component: {fileID: 872320148}
- component: {fileID: 872320147}
m_Layer: 5
m_Name: radar_chart_cricle (1)
m_Name: test_chart
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
@@ -8481,7 +8479,7 @@ MonoBehaviour:
m_Name:
m_EditorClassIdentifier:
m_Material: {fileID: 0}
m_Color: {r: 1, g: 1, b: 1, a: 1}
m_Color: {r: 0.93333334, g: 0.93333334, b: 0.93333334, a: 1}
m_RaycastTarget: 1
m_OnCullStateChanged:
m_PersistentCalls:
@@ -8575,7 +8573,7 @@ MonoBehaviour:
m_HorizontalOverflow: 1
m_VerticalOverflow: 1
m_LineSpacing: 1
m_Text: 28
m_Text: 35
--- !u!222 &949530643
CanvasRenderer:
m_ObjectHideFlags: 0
@@ -9680,7 +9678,7 @@ MonoBehaviour:
m_HorizontalOverflow: 1
m_VerticalOverflow: 1
m_LineSpacing: 1
m_Text: 64
m_Text: 80
--- !u!222 &1096778763
CanvasRenderer:
m_ObjectHideFlags: 0
@@ -10180,7 +10178,7 @@ MonoBehaviour:
m_Name:
m_EditorClassIdentifier:
m_Material: {fileID: 0}
m_Color: {r: 1, g: 1, b: 1, a: 1}
m_Color: {r: 0.93333334, g: 0.93333334, b: 0.93333334, a: 1}
m_RaycastTarget: 1
m_OnCullStateChanged:
m_PersistentCalls:
@@ -11417,9 +11415,7 @@ MonoBehaviour:
lineInfo:
tickness: 0.8
showPoint: 1
pointType: 0
pointWid: 1
pointColor: {r: 1, g: 1, b: 1, a: 1}
pointWid: 2.5
smooth: 0
smoothStyle: 2
area: 0
@@ -11497,7 +11493,7 @@ MonoBehaviour:
m_HorizontalOverflow: 1
m_VerticalOverflow: 1
m_LineSpacing: 1
m_Text: 14
m_Text: 17
--- !u!222 &1322231539
CanvasRenderer:
m_ObjectHideFlags: 0
@@ -11847,7 +11843,7 @@ MonoBehaviour:
m_Name:
m_EditorClassIdentifier:
m_Material: {fileID: 0}
m_Color: {r: 1, g: 1, b: 1, a: 1}
m_Color: {r: 0.93333334, g: 0.93333334, b: 0.93333334, a: 1}
m_RaycastTarget: 1
m_OnCullStateChanged:
m_PersistentCalls:
@@ -12459,7 +12455,7 @@ MonoBehaviour:
m_HorizontalOverflow: 1
m_VerticalOverflow: 1
m_LineSpacing: 1
m_Text: 56
m_Text: 70
--- !u!222 &1423602108
CanvasRenderer:
m_ObjectHideFlags: 0
@@ -12735,7 +12731,7 @@ MonoBehaviour:
m_Name:
m_EditorClassIdentifier:
m_Material: {fileID: 0}
m_Color: {r: 1, g: 1, b: 1, a: 1}
m_Color: {r: 0.93333334, g: 0.93333334, b: 0.93333334, a: 1}
m_RaycastTarget: 1
m_OnCullStateChanged:
m_PersistentCalls:
@@ -13142,7 +13138,7 @@ MonoBehaviour:
m_Name:
m_EditorClassIdentifier:
m_Material: {fileID: 0}
m_Color: {r: 1, g: 1, b: 1, a: 1}
m_Color: {r: 0.93333334, g: 0.93333334, b: 0.93333334, a: 1}
m_RaycastTarget: 1
m_OnCullStateChanged:
m_PersistentCalls:
@@ -13325,9 +13321,7 @@ MonoBehaviour:
lineInfo:
tickness: 0.8
showPoint: 1
pointType: 0
pointWid: 1
pointColor: {r: 1, g: 1, b: 1, a: 1}
pointWid: 2.5
smooth: 1
smoothStyle: 2
area: 0
@@ -13405,7 +13399,7 @@ MonoBehaviour:
m_HorizontalOverflow: 1
m_VerticalOverflow: 1
m_LineSpacing: 1
m_Text: 128
m_Text: 160
--- !u!222 &1507933106
CanvasRenderer:
m_ObjectHideFlags: 0
@@ -13792,7 +13786,7 @@ MonoBehaviour:
m_Name:
m_EditorClassIdentifier:
m_Material: {fileID: 0}
m_Color: {r: 1, g: 1, b: 1, a: 1}
m_Color: {r: 0.93333334, g: 0.93333334, b: 0.93333334, a: 1}
m_RaycastTarget: 1
m_OnCullStateChanged:
m_PersistentCalls:
@@ -14162,7 +14156,7 @@ MonoBehaviour:
m_Name:
m_EditorClassIdentifier:
m_Material: {fileID: 0}
m_Color: {r: 1, g: 1, b: 1, a: 1}
m_Color: {r: 0.93333334, g: 0.93333334, b: 0.93333334, a: 1}
m_RaycastTarget: 1
m_OnCullStateChanged:
m_PersistentCalls:
@@ -14844,7 +14838,7 @@ MonoBehaviour:
m_HorizontalOverflow: 1
m_VerticalOverflow: 1
m_LineSpacing: 1
m_Text: 60
m_Text: 75
--- !u!222 &1675486929
CanvasRenderer:
m_ObjectHideFlags: 0
@@ -17007,7 +17001,7 @@ MonoBehaviour:
m_Name:
m_EditorClassIdentifier:
m_Material: {fileID: 0}
m_Color: {r: 1, g: 1, b: 1, a: 1}
m_Color: {r: 0.93333334, g: 0.93333334, b: 0.93333334, a: 1}
m_RaycastTarget: 1
m_OnCullStateChanged:
m_PersistentCalls:
@@ -17083,6 +17077,7 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: e6bd57e81d68cac47a78ccb7a452c8d7, type: 3}
m_Name:
m_EditorClassIdentifier:
theme: 2
--- !u!222 &2051892029
CanvasRenderer:
m_ObjectHideFlags: 0