mirror of
https://github.com/XCharts-Team/XCharts.git
synced 2026-05-27 11:40:13 +00:00
3.0
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -146,6 +146,7 @@ namespace XCharts.Runtime
|
||||
public void RemoveSerie(Serie serie)
|
||||
{
|
||||
serie.OnRemove();
|
||||
m_SerieHandlers.Remove(serie.handler);
|
||||
m_Series.Remove(serie);
|
||||
RefreshChart();
|
||||
}
|
||||
|
||||
@@ -143,9 +143,9 @@ namespace XCharts.Runtime
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 移除并重新初始化所有组件。
|
||||
/// 移除并重新创建所有图表的Object。
|
||||
/// </summary>
|
||||
public void RemoveAndReinitChartObject()
|
||||
public void RebuildChartObject()
|
||||
{
|
||||
ChartHelper.DestroyAllChildren(transform);
|
||||
SetAllComponentDirty();
|
||||
|
||||
@@ -125,7 +125,7 @@ namespace XCharts.Runtime
|
||||
if (m_EnableTextMeshPro != enableTextMeshPro)
|
||||
{
|
||||
m_EnableTextMeshPro = enableTextMeshPro;
|
||||
RemoveAndReinitChartObject();
|
||||
RebuildChartObject();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
|
||||
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace XCharts.Runtime
|
||||
{
|
||||
|
||||
@@ -122,7 +122,7 @@ namespace XCharts.Runtime
|
||||
foreach (var chart in chartList)
|
||||
{
|
||||
if (chart != null)
|
||||
chart.RemoveAndReinitChartObject();
|
||||
chart.RebuildChartObject();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
{
|
||||
|
||||
@@ -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);
|
||||
33
Runtime/Widgets/SVGImage.cs
Normal file
33
Runtime/Widgets/SVGImage.cs
Normal file
@@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
11
Runtime/Widgets/SVGImage.cs.meta
Normal file
11
Runtime/Widgets/SVGImage.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: fe10ee35a038646b6aedfffb30f84024
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
8
Runtime/XUGL/SVG.meta
Normal file
8
Runtime/XUGL/SVG.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6e78d1d27fb8f42948af1c6050eb6a46
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
39
Runtime/XUGL/SVG/SVG.cs
Normal file
39
Runtime/XUGL/SVG/SVG.cs
Normal file
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Runtime/XUGL/SVG/SVG.cs.meta
Normal file
11
Runtime/XUGL/SVG/SVG.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: cbe2b3aa282ad4cd9b469792fde7e092
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
203
Runtime/XUGL/SVG/SVGPath.cs
Normal file
203
Runtime/XUGL/SVG/SVGPath.cs
Normal file
@@ -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<SVGPathSeg> segs = new List<SVGPathSeg>();
|
||||
|
||||
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<Vector3>();
|
||||
var bezierList = new List<Vector3>();
|
||||
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<Vector3> 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();
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Runtime/XUGL/SVG/SVGPath.cs.meta
Normal file
11
Runtime/XUGL/SVG/SVGPath.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c4119dc5490ec4f8bbcc67aa6eee024a
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
36
Runtime/XUGL/SVG/SVGPathSeg.cs
Normal file
36
Runtime/XUGL/SVG/SVGPathSeg.cs
Normal file
@@ -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<float> parameters = new List<float>();
|
||||
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])); } }
|
||||
}
|
||||
}
|
||||
11
Runtime/XUGL/SVG/SVGPathSeg.cs.meta
Normal file
11
Runtime/XUGL/SVG/SVGPathSeg.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2c97d44ceb28a471aa3d657f3984e6b1
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
51
Runtime/XUGL/SVG/SVGPathSegType.cs
Normal file
51
Runtime/XUGL/SVG/SVGPathSegType.cs
Normal file
@@ -0,0 +1,51 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Text.RegularExpressions;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace XUGL
|
||||
{
|
||||
public enum SVGPathSegType
|
||||
{
|
||||
/// <summary>
|
||||
/// move to
|
||||
/// </summary>
|
||||
M,
|
||||
/// <summary>
|
||||
/// line to
|
||||
/// </summary>
|
||||
L,
|
||||
/// <summary>
|
||||
/// horizontal line to
|
||||
/// </summary>
|
||||
H,
|
||||
/// <summary>
|
||||
/// vertial line to
|
||||
/// </summary>
|
||||
V,
|
||||
/// <summary>
|
||||
/// curve to
|
||||
/// </summary>
|
||||
C,
|
||||
/// <summary>
|
||||
/// smooth curve to
|
||||
/// </summary>
|
||||
S,
|
||||
/// <summary>
|
||||
/// quadratic bezier curve
|
||||
/// </summary>
|
||||
Q,
|
||||
/// <summary>
|
||||
/// smooth quadratic bezier curve to
|
||||
/// </summary>
|
||||
T,
|
||||
/// <summary>
|
||||
/// elliptical Arc
|
||||
/// </summary>
|
||||
A,
|
||||
/// <summary>
|
||||
/// close path
|
||||
/// </summary>
|
||||
Z
|
||||
}
|
||||
}
|
||||
11
Runtime/XUGL/SVG/SVGPathSegType.cs.meta
Normal file
11
Runtime/XUGL/SVG/SVGPathSegType.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ebd7fe1a38c81433697bbe21c2e962ba
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -122,6 +122,11 @@ namespace XUGL
|
||||
|
||||
public static void DrawLine(VertexHelper vh, List<Vector3> 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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<T>(List<T> list1, List<T> list2)
|
||||
{
|
||||
if (list1 == null || list2 == null)
|
||||
|
||||
Reference in New Issue
Block a user