性能优化,减少Color隐式转化

This commit is contained in:
monitor1394
2019-03-26 08:03:28 +08:00
parent a7eb565766
commit 49dfd59ff3
3 changed files with 31 additions and 29 deletions

View File

@@ -15,22 +15,22 @@ namespace xcharts
public class ThemeInfo public class ThemeInfo
{ {
public Font font; public Font font;
public Color backgroundColor; public Color32 backgroundColor;
public Color contrastColor; public Color32 contrastColor;
public Color textColor; public Color32 textColor;
public Color subTextColor; public Color32 subTextColor;
public Color unableColor; public Color32 unableColor;
public Color axisLineColor; public Color32 axisLineColor;
public Color axisSplitLineColor; public Color32 axisSplitLineColor;
public Color tooltipBackgroundColor; public Color32 tooltipBackgroundColor;
public Color tooltipFlagAreaColor; public Color32 tooltipFlagAreaColor;
public Color tooltipTextColor; public Color32 tooltipTextColor;
public Color[] colorPalette; public Color32[] colorPalette;
public Color GetColor(int index) public Color32 GetColor(int index)
{ {
if(index < 0) if(index < 0)
{ {
@@ -52,7 +52,7 @@ namespace xcharts
axisSplitLineColor = theme.axisSplitLineColor; axisSplitLineColor = theme.axisSplitLineColor;
tooltipBackgroundColor = theme.tooltipBackgroundColor; tooltipBackgroundColor = theme.tooltipBackgroundColor;
tooltipTextColor = theme.tooltipTextColor; tooltipTextColor = theme.tooltipTextColor;
colorPalette = new Color[theme.colorPalette.Length]; colorPalette = new Color32[theme.colorPalette.Length];
for(int i = 0; i < theme.colorPalette.Length; i++) for(int i = 0; i < theme.colorPalette.Length; i++)
{ {
colorPalette[i] = theme.colorPalette[i]; colorPalette[i] = theme.colorPalette[i];
@@ -76,7 +76,7 @@ namespace xcharts
tooltipBackgroundColor = GetColor("#515151B5"), tooltipBackgroundColor = GetColor("#515151B5"),
tooltipTextColor = GetColor("#FFFFFFFF"), tooltipTextColor = GetColor("#FFFFFFFF"),
tooltipFlagAreaColor = GetColor("#51515120"), tooltipFlagAreaColor = GetColor("#51515120"),
colorPalette = new Color[] colorPalette = new Color32[]
{ {
new Color32(194, 53, 49, 255), new Color32(194, 53, 49, 255),
new Color32(47, 69, 84, 255), new Color32(47, 69, 84, 255),
@@ -111,7 +111,7 @@ namespace xcharts
tooltipBackgroundColor = GetColor("#515151B5"), tooltipBackgroundColor = GetColor("#515151B5"),
tooltipTextColor = GetColor("#FFFFFFFF"), tooltipTextColor = GetColor("#FFFFFFFF"),
tooltipFlagAreaColor = GetColor("#51515120"), tooltipFlagAreaColor = GetColor("#51515120"),
colorPalette = new Color[] colorPalette = new Color32[]
{ {
new Color32(55, 162, 218, 255), new Color32(55, 162, 218, 255),
new Color32(255, 159, 127, 255), new Color32(255, 159, 127, 255),
@@ -148,7 +148,7 @@ namespace xcharts
tooltipBackgroundColor = GetColor("#515151B5"), tooltipBackgroundColor = GetColor("#515151B5"),
tooltipTextColor = GetColor("#FFFFFFFF"), tooltipTextColor = GetColor("#FFFFFFFF"),
tooltipFlagAreaColor = GetColor("#51515120"), tooltipFlagAreaColor = GetColor("#51515120"),
colorPalette = new Color[] colorPalette = new Color32[]
{ {
new Color32(221, 107, 102, 255), new Color32(221, 107, 102, 255),
new Color32(117, 154, 160, 255), new Color32(117, 154, 160, 255),
@@ -166,11 +166,11 @@ namespace xcharts
} }
} }
public static Color GetColor(string hexColorStr) public static Color32 GetColor(string hexColorStr)
{ {
Color color; Color color;
ColorUtility.TryParseHtmlString(hexColorStr,out color); ColorUtility.TryParseHtmlString(hexColorStr,out color);
return color; return (Color32)color;
} }
} }
} }

View File

@@ -118,7 +118,7 @@ namespace xcharts
return tooltipObj; return tooltipObj;
} }
public static void DrawLine(VertexHelper vh, Vector3 p1, Vector3 p2, float size, Color color) public static void DrawLine(VertexHelper vh, Vector3 p1, Vector3 p2, float size, Color32 color)
{ {
Vector3 v = Vector3.Cross(p2 - p1, Vector3.forward).normalized * size; Vector3 v = Vector3.Cross(p2 - p1, Vector3.forward).normalized * size;
vertex[0].position = p1 + v; vertex[0].position = p1 + v;
@@ -133,7 +133,7 @@ namespace xcharts
vh.AddUIVertexQuad(vertex); vh.AddUIVertexQuad(vertex);
} }
public static void DrawPolygon(VertexHelper vh, Vector3 p, float size, Color color) public static void DrawPolygon(VertexHelper vh, Vector3 p, float size, Color32 color)
{ {
Vector3 p1 = new Vector3(p.x - size, p.y - size); Vector3 p1 = new Vector3(p.x - size, p.y - size);
Vector3 p2 = new Vector3(p.x + size, p.y - size); Vector3 p2 = new Vector3(p.x + size, p.y - size);
@@ -143,14 +143,14 @@ namespace xcharts
} }
public static void DrawPolygon(VertexHelper vh, Vector3 p1, Vector3 p2, Vector3 p3, Vector3 p4, public static void DrawPolygon(VertexHelper vh, Vector3 p1, Vector3 p2, Vector3 p3, Vector3 p4,
Color color) Color32 color)
{ {
DrawPolygon(vh, p1, p2, p3, p4, color, color); DrawPolygon(vh, p1, p2, p3, p4, color, color);
} }
public static void DrawPolygon(VertexHelper vh, Vector3 p1, Vector3 p2, Vector3 p3, Vector3 p4, public static void DrawPolygon(VertexHelper vh, Vector3 p1, Vector3 p2, Vector3 p3, Vector3 p4,
Color startColor, Color toColor) Color32 startColor, Color32 toColor)
{ {
vertex[0].position = p1; vertex[0].position = p1;
vertex[1].position = p2; vertex[1].position = p2;
@@ -165,7 +165,7 @@ namespace xcharts
} }
public static void DrawTriangle(VertexHelper vh, Vector3 p1, public static void DrawTriangle(VertexHelper vh, Vector3 p1,
Vector3 p2, Vector3 p3, Color color) Vector3 p2, Vector3 p3, Color32 color)
{ {
UIVertex v1 = new UIVertex(); UIVertex v1 = new UIVertex();
v1.position = p1; v1.position = p1;
@@ -179,12 +179,14 @@ namespace xcharts
v3.position = p3; v3.position = p3;
v3.color = color; v3.color = color;
v3.uv0 = Vector3.zero; v3.uv0 = Vector3.zero;
int startIndex = vh.currentVertCount;
vh.AddVert(v1); vh.AddVert(v1);
vh.AddVert(v2); vh.AddVert(v2);
vh.AddVert(v3); vh.AddVert(v3);
vh.AddTriangle(startIndex, startIndex + 1, startIndex + 2);
} }
public static void DrawCricle(VertexHelper vh, Vector3 p, float radius, Color color, public static void DrawCricle(VertexHelper vh, Vector3 p, float radius, Color32 color,
int segments = 0, bool fill = true) int segments = 0, bool fill = true)
{ {
if (segments <= 0) if (segments <= 0)
@@ -195,7 +197,7 @@ namespace xcharts
} }
public static void DrawCicleNotFill(VertexHelper vh, Vector3 p, float radius, float tickness, public static void DrawCicleNotFill(VertexHelper vh, Vector3 p, float radius, float tickness,
Color color, int segments = 0) Color32 color, int segments = 0)
{ {
if (segments <= 0) if (segments <= 0)
{ {
@@ -215,7 +217,7 @@ namespace xcharts
} }
} }
public static void DrawSector(VertexHelper vh, Vector3 p, float radius, Color color, public static void DrawSector(VertexHelper vh, Vector3 p, float radius, Color32 color,
float startDegree, float toDegree, int segments = 0) float startDegree, float toDegree, int segments = 0)
{ {
if (segments <= 0) if (segments <= 0)
@@ -237,7 +239,7 @@ namespace xcharts
} }
public static void DrawDoughnut(VertexHelper vh, Vector3 p, float insideRadius, float outsideRadius, public static void DrawDoughnut(VertexHelper vh, Vector3 p, float insideRadius, float outsideRadius,
float startDegree, float toDegree, Color color, int segments = 0) float startDegree, float toDegree, Color32 color, int segments = 0)
{ {
if (insideRadius <= 0) if (insideRadius <= 0)
{ {
@@ -277,7 +279,7 @@ namespace xcharts
Vector3 cp2 = sp + dist / k * dir * (k - 1); Vector3 cp2 = sp + dist / k * dir * (k - 1);
cp1.y = sp.y; cp1.y = sp.y;
cp2.y = ep.y; cp2.y = ep.y;
int segment = (int)(dist / 0.1f); int segment = (int)(dist / 0.3f);
return GetBezierList2(sp, ep, segment, cp1, cp2); return GetBezierList2(sp, ep, segment, cp1, cp2);
} }

View File

@@ -48,7 +48,7 @@ namespace xcharts
{ {
if (!legend.IsShowSeries(j)) continue; if (!legend.IsShowSeries(j)) continue;
Series series = seriesList[j]; Series series = seriesList[j];
Color color = themeInfo.GetColor(j); Color32 color = themeInfo.GetColor(j);
Vector3 lp = Vector3.zero; Vector3 lp = Vector3.zero;
Vector3 np = Vector3.zero; Vector3 np = Vector3.zero;
float startX = zeroX + (xAxis.boundaryGap ? scaleWid / 2 : 0); float startX = zeroX + (xAxis.boundaryGap ? scaleWid / 2 : 0);