mirror of
https://github.com/XCharts-Team/XCharts.git
synced 2026-05-26 10:50:08 +00:00
增加Settings全局参数配置组件,开放更多参数可配置
This commit is contained in:
@@ -7,7 +7,6 @@ namespace XCharts
|
||||
{
|
||||
public static class ChartDrawer
|
||||
{
|
||||
public static float CRICLE_SMOOTHNESS = 2f;
|
||||
private static UIVertex[] vertex = new UIVertex[4];
|
||||
private static List<Vector3> s_CurvesPosList = new List<Vector3>();
|
||||
|
||||
@@ -182,44 +181,21 @@ namespace XCharts
|
||||
}
|
||||
|
||||
public static void DrawCricle(VertexHelper vh, Vector3 p, float radius, Color32 color,
|
||||
int segments = 0)
|
||||
float smoothness = 2f)
|
||||
{
|
||||
if (segments <= 0)
|
||||
{
|
||||
segments = (int)((2 * Mathf.PI * radius) / CRICLE_SMOOTHNESS);
|
||||
}
|
||||
if (segments < 3) segments = 3;
|
||||
DrawSector(vh, p, radius, color, 0, 360, segments);
|
||||
DrawSector(vh, p, radius, color, 0, 360, smoothness);
|
||||
}
|
||||
|
||||
public static void DrawCicleNotFill(VertexHelper vh, Vector3 p, float radius, float tickness,
|
||||
Color32 color, int segments = 0)
|
||||
public static void DrawEmptyCricle(VertexHelper vh, Vector3 p, float radius, float tickness,
|
||||
Color32 color, Color emptyColor, float smoothness = 2f)
|
||||
{
|
||||
if (segments <= 0)
|
||||
{
|
||||
segments = (int)((2 * Mathf.PI * radius) / CRICLE_SMOOTHNESS);
|
||||
}
|
||||
float startDegree = 0, toDegree = 360;
|
||||
Vector3 p2, p3;
|
||||
float startAngle = startDegree * Mathf.Deg2Rad;
|
||||
float angle = (toDegree - startDegree) * Mathf.Deg2Rad / segments;
|
||||
p2 = new Vector3(p.x + radius * Mathf.Sin(startAngle), p.y + radius * Mathf.Cos(startAngle));
|
||||
for (int i = 0; i <= segments; i++)
|
||||
{
|
||||
float currAngle = startAngle + i * angle;
|
||||
p3 = new Vector3(p.x + radius * Mathf.Sin(currAngle), p.y + radius * Mathf.Cos(currAngle));
|
||||
DrawLine(vh, p2, p3, tickness, color);
|
||||
p2 = p3;
|
||||
}
|
||||
DrawDoughnut(vh, p, radius - tickness, radius, color, emptyColor, smoothness);
|
||||
}
|
||||
|
||||
public static void DrawSector(VertexHelper vh, Vector3 p, float radius, Color32 color,
|
||||
float startDegree, float toDegree, int segments = 0)
|
||||
float startDegree, float toDegree, float smoothness = 2f)
|
||||
{
|
||||
if (segments <= 0)
|
||||
{
|
||||
segments = (int)((2 * Mathf.PI * radius) / CRICLE_SMOOTHNESS);
|
||||
}
|
||||
int segments = (int)((2 * Mathf.PI * radius) / (smoothness < 0 ? 2f : smoothness));
|
||||
Vector3 p2, p3;
|
||||
float startAngle = startDegree * Mathf.Deg2Rad;
|
||||
float angle = (toDegree - startDegree) * Mathf.Deg2Rad / segments;
|
||||
@@ -235,18 +211,15 @@ namespace XCharts
|
||||
}
|
||||
|
||||
public static void DrawDoughnut(VertexHelper vh, Vector3 p, float insideRadius, float outsideRadius,
|
||||
float startDegree, float toDegree, Color32 color, int segments = 0)
|
||||
Color32 color, Color emptyColor, float smoothness = 2f, float startDegree = 0, float toDegree = 360)
|
||||
{
|
||||
if (insideRadius <= 0)
|
||||
{
|
||||
DrawSector(vh, p, outsideRadius, color, startDegree, toDegree, segments);
|
||||
DrawSector(vh, p, outsideRadius, color, startDegree, toDegree, smoothness);
|
||||
return;
|
||||
}
|
||||
if (segments <= 0)
|
||||
{
|
||||
segments = (int)((2 * Mathf.PI * outsideRadius) / CRICLE_SMOOTHNESS);
|
||||
}
|
||||
Vector3 p1, p2, p3, p4;
|
||||
int segments = (int)((2 * Mathf.PI * outsideRadius) / (smoothness < 0 ? 2f : smoothness));
|
||||
float startAngle = startDegree * Mathf.Deg2Rad;
|
||||
float angle = (toDegree - startDegree) * Mathf.Deg2Rad / segments;
|
||||
p1 = new Vector3(p.x + insideRadius * Mathf.Sin(startAngle),
|
||||
@@ -260,6 +233,7 @@ namespace XCharts
|
||||
p.y + outsideRadius * Mathf.Cos(currAngle));
|
||||
p4 = new Vector3(p.x + insideRadius * Mathf.Sin(currAngle),
|
||||
p.y + insideRadius * Mathf.Cos(currAngle));
|
||||
if (emptyColor != Color.clear) DrawTriangle(vh, p, p1, p4, emptyColor);
|
||||
DrawPolygon(vh, p1, p2, p3, p4, color);
|
||||
p1 = p4;
|
||||
p2 = p3;
|
||||
@@ -277,10 +251,10 @@ namespace XCharts
|
||||
/// <param name="lineWidth">曲线宽</param>
|
||||
/// <param name="lineColor">曲线颜色</param>
|
||||
public static void DrawCurves(VertexHelper vh, Vector3 sp, Vector3 ep, Vector3 cp1, Vector3 cp2,
|
||||
float lineWidth, Color lineColor)
|
||||
float lineWidth, Color lineColor, float smoothness)
|
||||
{
|
||||
var dist = Vector3.Distance(sp, ep);
|
||||
var segment = (int)(dist / 1f);
|
||||
var segment = (int)(dist / (smoothness <= 0 ? 2f : smoothness));
|
||||
ChartHelper.GetBezierList2(ref s_CurvesPosList, sp, ep, segment, cp1, cp2);
|
||||
if (s_CurvesPosList.Count > 1)
|
||||
{
|
||||
|
||||
@@ -236,7 +236,7 @@ namespace XCharts
|
||||
return labelObj;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static void GetPointList(ref List<Vector3> posList, Vector3 sp, Vector3 ep, float k = 30f)
|
||||
{
|
||||
Vector3 dir = (ep - sp).normalized;
|
||||
@@ -252,7 +252,7 @@ namespace XCharts
|
||||
}
|
||||
|
||||
public static void GetBezierList(ref List<Vector3> posList, Vector3 sp, Vector3 ep,
|
||||
Vector3 lsp, Vector3 nep, bool fine, float k = 2.0f)
|
||||
Vector3 lsp, Vector3 nep, float smoothness = 2f, float k = 2.0f)
|
||||
{
|
||||
float dist = Mathf.Abs(sp.x - ep.x);
|
||||
Vector3 cp1, cp2;
|
||||
@@ -271,13 +271,13 @@ namespace XCharts
|
||||
if (nep == ep) cp2 = ep;
|
||||
else cp2 = ep - (nep - sp).normalized * diff;
|
||||
dist = Vector3.Distance(sp, ep);
|
||||
int segment = (int)(dist / (fine ? 2f : 6f));
|
||||
int segment = (int)(dist / (smoothness <= 0 ? 2f : smoothness));
|
||||
if (segment < 1) segment = (int)(dist / 0.5f);
|
||||
if (segment < 4) segment = 4;
|
||||
GetBezierList2(ref posList, sp, ep, segment, cp1, cp2);
|
||||
}
|
||||
|
||||
public static void GetBezierListVertical(ref List<Vector3> posList, Vector3 sp, Vector3 ep, bool fine, float k = 2.0f)
|
||||
public static void GetBezierListVertical(ref List<Vector3> posList, Vector3 sp, Vector3 ep, float smoothness = 2f, float k = 2.0f)
|
||||
{
|
||||
Vector3 dir = (ep - sp).normalized;
|
||||
float dist = Vector3.Distance(sp, ep);
|
||||
@@ -285,7 +285,7 @@ namespace XCharts
|
||||
Vector3 cp2 = sp + dist / k * dir * (k - 1);
|
||||
cp1.x = sp.x;
|
||||
cp2.x = ep.x;
|
||||
int segment = (int)(dist / (fine ? 3f : 7f));
|
||||
int segment = (int)(dist / (smoothness <= 0 ? 2f : smoothness));
|
||||
GetBezierList2(ref posList, sp, ep, segment, cp1, cp2);
|
||||
}
|
||||
|
||||
@@ -332,39 +332,6 @@ namespace XCharts
|
||||
t * t * t * ep;
|
||||
}
|
||||
|
||||
public static List<Vector3> GetBezierN(List<Vector3> arrayToCurve, float smoothness = 1.0f)
|
||||
{
|
||||
List<Vector3> points;
|
||||
List<Vector3> curvedPoints;
|
||||
int pointsLength = 0;
|
||||
int curvedLength = 0;
|
||||
|
||||
if (smoothness < 1.0f) smoothness = 1.0f;
|
||||
|
||||
pointsLength = arrayToCurve.Count;
|
||||
|
||||
curvedLength = (pointsLength * Mathf.RoundToInt(smoothness)) - 1;
|
||||
curvedPoints = new List<Vector3>(curvedLength);
|
||||
|
||||
float t = 0.0f;
|
||||
for (int pointInTimeOnCurve = 0; pointInTimeOnCurve < curvedLength + 1; pointInTimeOnCurve++)
|
||||
{
|
||||
t = Mathf.InverseLerp(0, curvedLength, pointInTimeOnCurve);
|
||||
|
||||
points = new List<Vector3>(arrayToCurve);
|
||||
|
||||
for (int j = pointsLength - 1; j > 0; j--)
|
||||
{
|
||||
for (int i = 0; i < j; i++)
|
||||
{
|
||||
points[i] = (1 - t) * points[i] + t * points[i + 1];
|
||||
}
|
||||
}
|
||||
curvedPoints.Add(points[0]);
|
||||
}
|
||||
return curvedPoints;
|
||||
}
|
||||
|
||||
public static bool IsValueEqualsColor(Color32 color1, Color32 color2)
|
||||
{
|
||||
return color1.a == color2.a &&
|
||||
|
||||
Reference in New Issue
Block a user