3.0 - unitypackage

This commit is contained in:
monitor1394
2022-01-05 21:40:48 +08:00
parent c160867765
commit 228a4b2840
846 changed files with 105 additions and 467693 deletions

View File

@@ -0,0 +1,141 @@
using UnityEngine;
namespace XCharts
{
/// <summary>
/// The style of area.
/// 区域填充样式。
/// </summary>
[System.Serializable]
public class AreaStyle : ChildComponent, ISerieExtraComponent
{
/// <summary>
/// Origin position of area.
/// 图形区域的起始位置。默认情况下,图形会从坐标轴轴线到数据间进行填充。如果需要填充的区域是坐标轴最大值到数据间,或者坐标轴最小值到数据间,则可以通过这个配置项进行设置。
/// </summary>
public enum AreaOrigin
{
/// <summary>
/// to fill between axis line to data.
/// 填充坐标轴轴线到数据间的区域。
/// </summary>
Auto,
/// <summary>
/// to fill between min axis value (when not inverse) to data.
/// 填充坐标轴底部到数据间的区域。
/// </summary>
Start,
/// <summary>
/// to fill between max axis value (when not inverse) to data.
/// 填充坐标轴顶部到数据间的区域。
/// </summary>
End
}
[SerializeField] private bool m_Show = true;
[SerializeField] private AreaOrigin m_Origin;
[SerializeField] private Color32 m_Color;
[SerializeField] private Color32 m_ToColor;
[SerializeField] [Range(0, 1)] private float m_Opacity = 0.6f;
[SerializeField] private bool m_TooltipHighlight;
[SerializeField] private Color32 m_HighlightColor;
[SerializeField] private Color32 m_HighlightToColor;
/// <summary>
/// Set this to false to prevent the areafrom showing.
/// 是否显示区域填充。
/// </summary>
public bool show
{
get { return m_Show; }
set { if (PropertyUtil.SetStruct(ref m_Show, value)) SetVerticesDirty(); }
}
/// <summary>
/// the origin of area.
/// 区域填充的起始位置。
/// </summary>
public AreaOrigin origin
{
get { return m_Origin; }
set { if (PropertyUtil.SetStruct(ref m_Origin, value)) SetVerticesDirty(); }
}
/// <summary>
/// the color of area,default use serie color.
/// 区域填充的颜色如果toColor不是默认值则表示渐变色的起点颜色。
/// </summary>
public Color32 color
{
get { return m_Color; }
set { if (PropertyUtil.SetColor(ref m_Color, value)) SetVerticesDirty(); }
}
/// <summary>
/// Gradient color, start color to toColor.
/// 渐变色的终点颜色。
/// </summary>
public Color32 toColor
{
get { return m_ToColor; }
set { if (PropertyUtil.SetColor(ref m_ToColor, value)) SetVerticesDirty(); }
}
/// <summary>
/// Opacity of the component. Supports value from 0 to 1, and the component will not be drawn when set to 0.
/// 图形透明度。支持从 0 到 1 的数字,为 0 时不绘制该图形。
/// </summary>
public float opacity
{
get { return m_Opacity; }
set { if (PropertyUtil.SetStruct(ref m_Opacity, value)) SetVerticesDirty(); }
}
/// <summary>
/// 鼠标悬浮时是否高亮之前的区域
/// </summary>
public bool tooltipHighlight
{
get { return m_TooltipHighlight; }
set { if (PropertyUtil.SetStruct(ref m_TooltipHighlight, value)) SetVerticesDirty(); }
}
/// <summary>
/// the color of area,default use serie color.
/// 高亮时区域填充的颜色如果highlightToColor不是默认值则表示渐变色的起点颜色。
/// </summary>
public Color32 highlightColor
{
get { return m_HighlightColor; }
set { if (PropertyUtil.SetColor(ref m_HighlightColor, value)) SetVerticesDirty(); }
}
/// <summary>
/// Gradient color, start highlightColor to highlightToColor.
/// 高亮时渐变色的终点颜色。
/// </summary>
public Color32 highlightToColor
{
get { return m_HighlightToColor; }
set { if (PropertyUtil.SetColor(ref m_HighlightToColor, value)) SetVerticesDirty(); }
}
public Color32 GetColor()
{
if (m_Opacity == 1)
return m_Color;
var color = m_Color;
color.a = (byte)(color.a * m_Opacity);
return color;
}
public Color32 GetColor(Color32 themeColor)
{
if (!ChartHelper.IsClearColor(color))
{
return GetColor();
}
else
{
var color = themeColor;
color.a = (byte)(color.a * opacity);
return color;
}
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: ec0d95a9298bb4c159dcae36020beec9
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,93 @@
using System;
using UnityEngine;
namespace XCharts
{
/// <summary>
/// </summary>
[Serializable]
public class ArrowStyle : ChildComponent
{
[SerializeField] private float m_Width = 10;
[SerializeField] private float m_Height = 15;
[SerializeField] private float m_Offset = 0;
[SerializeField] private float m_Dent = 3;
[SerializeField] private Color32 m_Color = Color.clear;
/// <summary>
/// The widht of arrow.
/// 箭头宽。
/// </summary>
public float width
{
get { return m_Width; }
set { if (PropertyUtil.SetStruct(ref m_Width, value)) SetVerticesDirty(); }
}
/// <summary>
/// The height of arrow.
/// 箭头高。
/// </summary>
public float height
{
get { return m_Height; }
set { if (PropertyUtil.SetStruct(ref m_Height, value)) SetVerticesDirty(); }
}
/// <summary>
/// The offset of arrow.
/// 箭头偏移。
/// </summary>
public float offset
{
get { return m_Offset; }
set { if (PropertyUtil.SetStruct(ref m_Offset, value)) SetVerticesDirty(); }
}
/// <summary>
/// The dent of arrow.
/// 箭头的凹度。
/// </summary>
public float dent
{
get { return m_Dent; }
set { if (PropertyUtil.SetStruct(ref m_Dent, value)) SetVerticesDirty(); }
}
/// <summary>
/// the color of arrow.
/// 箭头颜色。
/// </summary>
public Color32 color
{
get { return m_Color; }
set { if (PropertyUtil.SetColor(ref m_Color, value)) SetVerticesDirty(); }
}
public ArrowStyle Clone()
{
var arrow = new ArrowStyle();
arrow.width = width;
arrow.height = height;
arrow.offset = offset;
arrow.dent = dent;
arrow.color = color;
return arrow;
}
public void Copy(ArrowStyle arrow)
{
width = arrow.width;
height = arrow.height;
offset = arrow.offset;
dent = arrow.dent;
color = arrow.color;
}
public Color32 GetColor(Color32 defaultColor)
{
if (ChartHelper.IsClearColor(color))
return defaultColor;
else
return color;
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 2232b812c68f042d29c44863e38d0417
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,83 @@
using UnityEngine;
namespace XCharts
{
/// <summary>
/// Settings related to base line.
/// 线条基础配置。
/// </summary>
[System.Serializable]
public class BaseLine : ChildComponent
{
[SerializeField] protected bool m_Show;
[SerializeField] protected LineStyle m_LineStyle = new LineStyle();
/// <summary>
/// Set this to false to prevent the axis line from showing.
/// 是否显示坐标轴轴线。
/// </summary>
public bool show
{
get { return m_Show; }
set { if (PropertyUtil.SetStruct(ref m_Show, value)) SetVerticesDirty(); }
}
/// <summary>
/// 线条样式
/// </summary>
public LineStyle lineStyle
{
get { return m_LineStyle; }
set { if (value != null) { m_LineStyle = value; SetVerticesDirty(); } }
}
public static BaseLine defaultBaseLine
{
get
{
var axisLine = new BaseLine
{
m_Show = true,
m_LineStyle = new LineStyle()
};
return axisLine;
}
}
public BaseLine()
{
lineStyle = new LineStyle();
}
public BaseLine(bool show) : base()
{
m_Show = show;
}
public void Copy(BaseLine axisLine)
{
show = axisLine.show;
lineStyle.Copy(axisLine.lineStyle);
}
public LineStyle.Type GetType(LineStyle.Type themeType)
{
return lineStyle.GetType(themeType);
}
public float GetWidth(float themeWidth)
{
return lineStyle.GetWidth(themeWidth);
}
public float GetLength(float themeLength)
{
return lineStyle.GetLength(themeLength);
}
public Color32 GetColor(Color32 themeColor)
{
return lineStyle.GetColor(themeColor);
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 4c431b00ccffe4db4b61179b6df06eb2
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,73 @@
using UnityEngine;
namespace XCharts
{
/// <summary>
/// 高亮的图形样式和文本标签样式。
/// </summary>
[System.Serializable]
public class Emphasis : ChildComponent, ISerieExtraComponent, ISerieDataComponent
{
[SerializeField] private bool m_Show;
[SerializeField] private LabelStyle m_Label = new LabelStyle();
[SerializeField] private LabelLine m_LabelLine = new LabelLine();
[SerializeField] private ItemStyle m_ItemStyle = new ItemStyle();
public void Reset()
{
m_Show = false;
m_Label.Reset();
m_LabelLine.Reset();
m_ItemStyle.Reset();
}
/// <summary>
/// 是否启用高亮样式。
/// </summary>
public bool show
{
get { return m_Show; }
set { m_Show = value; }
}
/// <summary>
/// 图形文本标签。
/// </summary>
public LabelStyle label
{
get { return m_Label; }
set { if (PropertyUtil.SetClass(ref m_Label, value, true)) SetAllDirty(); }
}
public LabelLine labelLine
{
get { return m_LabelLine; }
set { if (PropertyUtil.SetClass(ref m_LabelLine, value, true)) SetAllDirty(); }
}
/// <summary>
/// 图形样式。
/// </summary>
public ItemStyle itemStyle
{
get { return m_ItemStyle; }
set { if (PropertyUtil.SetClass(ref m_ItemStyle, value, true)) SetVerticesDirty(); }
}
public override bool vertsDirty { get { return m_VertsDirty || label.vertsDirty || itemStyle.vertsDirty; } }
public override bool componentDirty { get { return m_ComponentDirty || label.componentDirty; } }
public override void ClearVerticesDirty()
{
base.ClearVerticesDirty();
label.ClearVerticesDirty();
itemStyle.ClearVerticesDirty();
}
public override void ClearComponentDirty()
{
base.ClearComponentDirty();
label.ClearComponentDirty();
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 6e0b1690532674b24952a87e0aead6fa
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,11 @@
using System;
using UnityEngine;
namespace XCharts
{
[System.Serializable]
public class EndLabelStyle : LabelStyle
{
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: b3ca55f3ab0314339ae171c8ac07c4e2
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,102 @@

using UnityEngine;
using UnityEngine.UI;
namespace XCharts
{
[System.Serializable]
public class IconStyle : ChildComponent, ISerieExtraComponent, ISerieDataComponent
{
public enum Layer
{
UnderLabel,
AboveLabel
}
[SerializeField] private bool m_Show;
[SerializeField] private Layer m_Layer;
[SerializeField] private Align m_Align = Align.Left;
[SerializeField] private Sprite m_Sprite;
[SerializeField] private Color m_Color = Color.white;
[SerializeField] private float m_Width = 20;
[SerializeField] private float m_Height = 20;
[SerializeField] private Vector3 m_Offset;
[SerializeField] private bool m_AutoHideWhenLabelEmpty = false;
public void Reset()
{
m_Show = false;
m_Layer = Layer.UnderLabel;
m_Sprite = null;
m_Color = Color.white;
m_Width = 20;
m_Height = 20;
m_Offset = Vector3.zero;
m_AutoHideWhenLabelEmpty = false;
}
/// <summary>
/// Whether the data icon is show.
/// 是否显示图标。
/// </summary>
public bool show { get { return m_Show; } set { m_Show = value; } }
/// <summary>
/// 显示在上层还是在下层。
/// </summary>
public Layer layer { get { return m_Layer; } set { m_Layer = value; } }
/// <summary>
/// The image of icon.
/// 图标的图片。
/// </summary>
public Sprite sprite { get { return m_Sprite; } set { m_Sprite = value; } }
/// <summary>
/// 图标颜色。
/// </summary>
public Color color { get { return m_Color; } set { m_Color = value; } }
/// <summary>
/// 图标宽。
/// </summary>
public float width { get { return m_Width; } set { m_Width = value; } }
/// <summary>
/// 图标高。
/// </summary>
public float height { get { return m_Height; } set { m_Height = value; } }
/// <summary>
/// 图标偏移。
/// </summary>
public Vector3 offset { get { return m_Offset; } set { m_Offset = value; } }
/// <summary>
/// 水平方向对齐方式。
/// </summary>
public Align align { get { return m_Align; } set { m_Align = value; } }
/// <summary>
/// 当label内容为空时是否自动隐藏图标
/// </summary>
public bool autoHideWhenLabelEmpty { get { return m_AutoHideWhenLabelEmpty; } set { m_AutoHideWhenLabelEmpty = value; } }
public IconStyle Clone()
{
var iconStyle = new IconStyle();
iconStyle.show = show;
iconStyle.layer = layer;
iconStyle.sprite = sprite;
iconStyle.color = color;
iconStyle.width = width;
iconStyle.height = height;
iconStyle.offset = offset;
iconStyle.align = align;
iconStyle.autoHideWhenLabelEmpty = autoHideWhenLabelEmpty;
return iconStyle;
}
public void Copy(IconStyle iconStyle)
{
show = iconStyle.show;
layer = iconStyle.layer;
sprite = iconStyle.sprite;
color = iconStyle.color;
width = iconStyle.width;
height = iconStyle.height;
offset = iconStyle.offset;
align = iconStyle.align;
autoHideWhenLabelEmpty = iconStyle.autoHideWhenLabelEmpty;
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 82c4d360f7b5b4ee7845e9bbe611c8a3
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,359 @@
using System;
using System.Collections.Generic;
using UnityEngine;
namespace XCharts
{
/// <summary>
/// 图形样式。
/// </summary>
[System.Serializable]
public class ItemStyle : ChildComponent, ISerieDataComponent
{
/// <summary>
/// 线的类型。
/// </summary>
public enum Type
{
/// <summary>
/// 实线
/// </summary>
Solid,
/// <summary>
/// 虚线
/// </summary>
Dashed,
/// <summary>
/// 点线
/// </summary>
Dotted
}
[SerializeField] private bool m_Show = true;
[SerializeField] private Color32 m_Color;
[SerializeField] private Color32 m_Color0;
[SerializeField] private Color32 m_ToColor;
[SerializeField] private Color32 m_ToColor2;
[SerializeField] private Color32 m_BackgroundColor;
[SerializeField] private float m_BackgroundWidth;
[SerializeField] private Color32 m_CenterColor;
[SerializeField] private float m_CenterGap;
[SerializeField] private Type m_BorderType = Type.Solid;
[SerializeField] private float m_BorderWidth = 0;
[SerializeField] private Color32 m_BorderColor;
[SerializeField] private Color32 m_BorderColor0;
[SerializeField] private Color32 m_BorderToColor;
[SerializeField] [Range(0, 1)] private float m_Opacity = 1;
[SerializeField] private string m_ItemMarker;
[SerializeField] private string m_ItemFormatter;
[SerializeField] private string m_NumericFormatter = "";
[SerializeField] private float[] m_CornerRadius = new float[] { 0, 0, 0, 0 };
public void Reset()
{
m_Show = false;
m_Color = Color.clear;
m_Color0 = Color.clear;
m_ToColor = Color.clear;
m_ToColor2 = Color.clear;
m_BackgroundColor = Color.clear;
m_BackgroundWidth = 0;
m_CenterColor = Color.clear;
m_CenterGap = 0;
m_BorderType = Type.Solid;
m_BorderWidth = 0;
m_BorderColor = Color.clear;
m_BorderColor0 = Color.clear;
m_BorderToColor = Color.clear;
m_Opacity = 1;
m_ItemFormatter = null;
m_ItemMarker = null;
m_NumericFormatter = "";
if (m_CornerRadius == null)
{
m_CornerRadius = new float[] { 0, 0, 0, 0 };
}
else
{
for (int i = 0; i < m_CornerRadius.Length; i++)
m_CornerRadius[i] = 0;
}
}
/// <summary>
/// 是否启用。
/// </summary>
public bool show
{
get { return m_Show; }
set { if (PropertyUtil.SetStruct(ref m_Show, value)) SetVerticesDirty(); }
}
/// <summary>
/// 数据项颜色。
/// </summary>
public Color32 color
{
get { return m_Color; }
set { if (PropertyUtil.SetColor(ref m_Color, value)) SetVerticesDirty(); }
}
/// <summary>
/// 数据项颜色。
/// </summary>
public Color32 color0
{
get { return m_Color0; }
set { if (PropertyUtil.SetColor(ref m_Color0, value)) SetVerticesDirty(); }
}
/// <summary>
/// Gradient color1.
/// 渐变色的颜色1。
/// </summary>
public Color32 toColor
{
get { return m_ToColor; }
set { if (PropertyUtil.SetColor(ref m_ToColor, value)) SetVerticesDirty(); }
}
/// <summary>
/// Gradient color2.Only valid in line diagrams.
/// 渐变色的颜色2。只在折线图中有效。
/// </summary>
public Color32 toColor2
{
get { return m_ToColor2; }
set { if (PropertyUtil.SetColor(ref m_ToColor2, value)) SetVerticesDirty(); }
}
/// <summary>
/// 数据项背景颜色。
/// </summary>
public Color32 backgroundColor
{
get { return m_BackgroundColor; }
set { if (PropertyUtil.SetColor(ref m_BackgroundColor, value)) SetVerticesDirty(); }
}
/// <summary>
/// 中心区域颜色。
/// </summary>
public Color32 centerColor
{
get { return m_CenterColor; }
set { if (PropertyUtil.SetColor(ref m_CenterColor, value)) SetVerticesDirty(); }
}
/// <summary>
/// 中心区域间隙。
/// </summary>
public float centerGap
{
get { return m_CenterGap; }
set { if (PropertyUtil.SetStruct(ref m_CenterGap, value)) SetVerticesDirty(); }
}
/// <summary>
/// 数据项背景宽度。
/// </summary>
public float backgroundWidth
{
get { return m_BackgroundWidth; }
set { if (PropertyUtil.SetStruct(ref m_BackgroundWidth, value)) SetVerticesDirty(); }
}
/// <summary>
/// 边框的类型。
/// </summary>
public Type borderType
{
get { return m_BorderType; }
set { if (PropertyUtil.SetStruct(ref m_BorderType, value)) SetVerticesDirty(); }
}
/// <summary>
/// 边框的颜色。
/// </summary>
public Color32 borderColor
{
get { return m_BorderColor; }
set { if (PropertyUtil.SetColor(ref m_BorderColor, value)) SetVerticesDirty(); }
}
/// <summary>
/// 边框的颜色。
/// </summary>
public Color32 borderColor0
{
get { return m_BorderColor0; }
set { if (PropertyUtil.SetColor(ref m_BorderColor0, value)) SetVerticesDirty(); }
}
/// <summary>
/// 边框的渐变色。
/// </summary>
public Color32 borderToColor
{
get { return m_BorderToColor; }
set { if (PropertyUtil.SetColor(ref m_BorderToColor, value)) SetVerticesDirty(); }
}
/// <summary>
/// 边框宽。
/// </summary>
public float borderWidth
{
get { return m_BorderWidth; }
set { if (PropertyUtil.SetStruct(ref m_BorderWidth, value)) SetVerticesDirty(); }
}
/// <summary>
/// 透明度。支持从 0 到 1 的数字,为 0 时不绘制该图形。
/// </summary>
public float opacity
{
get { return m_Opacity; }
set { if (PropertyUtil.SetStruct(ref m_Opacity, value)) SetVerticesDirty(); }
}
/// <summary>
/// 提示框单项的字符串模版格式器。具体配置参考`Tooltip`的`formatter`
/// </summary>
public string itemFormatter
{
get { return m_ItemFormatter; }
set { if (PropertyUtil.SetClass(ref m_ItemFormatter, value)) SetVerticesDirty(); }
}
/// <summary>
/// 提示框单项的字符标志。用在Tooltip中。
/// </summary>
public string itemMarker
{
get { return m_ItemMarker; }
set { if (PropertyUtil.SetClass(ref m_ItemMarker, value)) SetVerticesDirty(); }
}
/// <summary>
/// Standard numeric format strings.
/// 标准数字格式字符串。用于将数值格式化显示为字符串。
/// 使用Axx的形式A是格式说明符的单字符支持C货币、D十进制、E指数、F定点数、G常规、N数字、P百分比、R往返、X十六进制的。xx是精度说明从0-99。
/// 参考https://docs.microsoft.com/zh-cn/dotnet/standard/base-types/standard-numeric-format-strings
/// </summary>
/// <value></value>
public string numericFormatter
{
get { return m_NumericFormatter; }
set { if (PropertyUtil.SetClass(ref m_NumericFormatter, value)) SetComponentDirty(); }
}
/// <summary>
/// The radius of rounded corner. Its unit is px. Use array to respectively specify the 4 corner radiuses((clockwise upper left, upper right, bottom right and bottom left)).
/// 圆角半径。用数组分别指定4个圆角半径顺时针左上右上右下左下
/// </summary>
public float[] cornerRadius
{
get { return m_CornerRadius; }
set { if (PropertyUtil.SetClass(ref m_CornerRadius, value, true)) SetVerticesDirty(); }
}
/// <summary>
/// 实际边框宽。边框不显示时为0。
/// </summary>
public float runtimeBorderWidth { get { return NeedShowBorder() ? borderWidth : 0; } }
/// <summary>
/// 是否需要显示边框。
/// </summary>
public bool NeedShowBorder()
{
return borderWidth != 0 && !ChartHelper.IsClearColor(borderColor);
}
public Color32 GetColor()
{
if (m_Opacity == 1 || m_Color.a == 0)
return m_Color;
var color = m_Color;
color.a = (byte)(color.a * m_Opacity);
return color;
}
public Color32 GetColor0()
{
if (m_Opacity == 1 || m_Color0.a == 0)
return m_Color0;
var color = m_Color0;
color.a = (byte)(color.a * m_Opacity);
return color;
}
public Color32 GetColor(Color32 defaultColor)
{
var color = ChartHelper.IsClearColor(m_Color) ? defaultColor : m_Color;
if (m_Opacity == 1 || color.a == 0)
return color;
color.a = (byte)(color.a * m_Opacity);
return color;
}
public Color32 GetColor0(Color32 defaultColor)
{
var color = ChartHelper.IsClearColor(m_Color0) ? defaultColor : m_Color0;
if (m_Opacity == 1 || color.a == 0)
return color;
color.a = (byte)(color.a * m_Opacity);
return color;
}
public Color32 GetBorderColor(Color32 defaultColor)
{
var color = ChartHelper.IsClearColor(m_BorderColor) ? defaultColor : m_BorderColor;
if (m_Opacity == 1 || color.a == 0)
return color;
color.a = (byte)(color.a * m_Opacity);
return color;
}
public Color32 GetBorderColor0(Color32 defaultColor)
{
var color = ChartHelper.IsClearColor(m_BorderColor0) ? defaultColor : m_BorderColor0;
if (m_Opacity == 1 || color.a == 0)
return color;
color.a = (byte)(color.a * m_Opacity);
return color;
}
public bool IsNeedGradient()
{
return !ChartHelper.IsClearColor(m_ToColor) || !ChartHelper.IsClearColor(m_ToColor2);
}
public Color32 GetGradientColor(float value, Color32 defaultColor)
{
if (!IsNeedGradient())
return ChartConst.clearColor32;
value = Mathf.Clamp01(value);
var startColor = ChartHelper.IsClearColor(m_Color) ? defaultColor : m_Color;
Color32 color;
if (!ChartHelper.IsClearColor(m_ToColor2))
{
if (value <= 0.5f)
color = Color32.Lerp(startColor, m_ToColor, 2 * value);
else
color = Color32.Lerp(m_ToColor, m_ToColor2, 2 * (value - 0.5f));
}
else
{
color = Color32.Lerp(startColor, m_ToColor, value);
}
if (m_Opacity != 1)
{
color.a = (byte)(color.a * m_Opacity);
}
return color;
}
}
public static class ItemStyleHelper
{
public static bool IsNeedCorner(ItemStyle itemStyle)
{
if (itemStyle.cornerRadius == null) return false;
foreach (var value in itemStyle.cornerRadius)
{
if (value != 0) return true;
}
return false;
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 3ca9b30f9779c4a16b60cc21334828b0
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,112 @@

using System;
using UnityEngine;
namespace XCharts
{
[System.Serializable]
public class LabelLine : ChildComponent, ISerieExtraComponent, ISerieDataComponent
{
/// <summary>
/// 标签视觉引导线类型
/// </summary>
public enum LineType
{
/// <summary>
/// 折线
/// </summary>
BrokenLine,
/// <summary>
/// 曲线
/// </summary>
Curves,
/// <summary>
/// 水平线
/// </summary>
HorizontalLine
}
[SerializeField] private bool m_Show = false;
[SerializeField] private LineType m_LineType = LineType.BrokenLine;
[SerializeField] private Color32 m_LineColor = ChartConst.clearColor32;
[SerializeField] private float m_LineWidth = 1.0f;
[SerializeField] private float m_LineGap = 1.0f;
[SerializeField] private float m_LineLength1 = 25f;
[SerializeField] private float m_LineLength2 = 15f;
public void Reset()
{
m_Show = false;
m_LineType = LineType.BrokenLine;
m_LineColor = Color.clear;
m_LineWidth = 1.0f;
m_LineGap = 1.0f;
m_LineLength1 = 25f;
m_LineLength2 = 15f;
}
/// <summary>
/// Whether the label line is showed.
/// 是否显示视觉引导线。
/// </summary>
public bool show
{
get { return m_Show; }
set { if (PropertyUtil.SetStruct(ref m_Show, value)) SetAllDirty(); }
}
/// <summary>
/// the type of visual guide line.
/// 视觉引导线类型。
/// </summary>
public LineType lineType
{
get { return m_LineType; }
set { if (PropertyUtil.SetStruct(ref m_LineType, value)) SetVerticesDirty(); }
}
/// <summary>
/// the color of visual guild line.
/// 视觉引导线颜色。默认和serie一致取自调色板。
/// </summary>
public Color32 lineColor
{
get { return m_LineColor; }
set { if (PropertyUtil.SetStruct(ref m_LineColor, value)) SetVerticesDirty(); }
}
/// <summary>
/// the width of visual guild line.
/// 视觉引导线的宽度。
/// </summary>
public float lineWidth
{
get { return m_LineWidth; }
set { if (PropertyUtil.SetStruct(ref m_LineWidth, value)) SetVerticesDirty(); }
}
/// <summary>
/// the gap of container and guild line.
/// 视觉引导线和容器的间距。
/// </summary>
public float lineGap
{
get { return m_LineGap; }
set { if (PropertyUtil.SetStruct(ref m_LineGap, value)) SetVerticesDirty(); }
}
/// <summary>
/// The length of the first segment of visual guide line.
/// 视觉引导线第一段的长度。
/// </summary>
public float lineLength1
{
get { return m_LineLength1; }
set { if (PropertyUtil.SetStruct(ref m_LineLength1, value)) SetVerticesDirty(); }
}
/// <summary>
/// The length of the second segment of visual guide line.
/// 视觉引导线第二段的长度。
/// </summary>
public float lineLength2
{
get { return m_LineLength2; }
set { if (PropertyUtil.SetStruct(ref m_LineLength2, value)) SetVerticesDirty(); }
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 1c3977205b6f14d8a97ae32177691580
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,304 @@

using System;
using UnityEngine;
namespace XCharts
{
/// <summary>
/// Text label of chart, to explain some data information about graphic item like value, name and so on.
/// 图形上的文本标签,可用于说明图形的一些数据信息,比如值,名称等。
/// </summary>
[System.Serializable]
public class LabelStyle : ChildComponent, ISerieExtraComponent, ISerieDataComponent
{
/// <summary>
/// The position of label.
/// 标签的位置。
/// </summary>
public enum Position
{
/// <summary>
/// Outside of sectors of pie chart, which relates to corresponding sector through visual guide line.
/// 饼图扇区外侧,通过视觉引导线连到相应的扇区。
/// </summary>
Outside,
/// <summary>
/// Inside the sectors of pie chart.
/// 饼图扇区内部。
/// </summary>
Inside,
/// <summary>
/// In the center of pie chart.
/// 在饼图中心位置。
/// </summary>
Center,
/// <summary>
/// top of symbol.
/// 图形标志的顶部。
/// </summary>
Top,
/// <summary>
/// the bottom of symbol.
/// 图形标志的底部。
/// </summary>
Bottom,
/// <summary>
/// the left of symbol.
/// 图形标志的左边。
/// </summary>
Left,
/// <summary>
/// the right of symbol.
/// 图形标志的右边。
/// </summary>
Right,
/// <summary>
/// the start of line.
/// 线的起始点。
/// </summary>
Start,
/// <summary>
/// the middle of line.
/// 线的中点。
/// </summary>
Middle,
/// <summary>
/// the end of line.
/// 线的结束点。
/// </summary>
End
}
[SerializeField] private bool m_Show = true;
[SerializeField] Position m_Position = Position.Outside;
[SerializeField] private Vector3 m_Offset;
[SerializeField] private float m_Margin;
[SerializeField] private string m_Formatter;
[SerializeField] private float m_PaddingLeftRight = 2f;
[SerializeField] private float m_PaddingTopBottom = 2f;
[SerializeField] private float m_BackgroundWidth = 0;
[SerializeField] private float m_BackgroundHeight = 0;
[SerializeField] private bool m_Border = false;
[SerializeField] private float m_BorderWidth = 0.5f;
[SerializeField] private Color32 m_BorderColor = ChartConst.greyColor32;
[SerializeField] private string m_NumericFormatter = "";
[SerializeField] private bool m_AutoOffset = false;
[SerializeField] private TextStyle m_TextStyle = new TextStyle();
private DelegateSerieLabelFormatter m_FormatterFunction;
public void Reset()
{
m_Show = false;
m_Position = Position.Outside;
m_Offset = Vector3.zero;
m_Margin = 0;
m_PaddingLeftRight = 2f;
m_PaddingTopBottom = 2f;
m_BackgroundWidth = 0;
m_BackgroundHeight = 0;
m_Border = false;
m_BorderWidth = 0.5f;
m_BorderColor = Color.grey;
m_NumericFormatter = "";
m_AutoOffset = false;
}
/// <summary>
/// Whether the label is showed.
/// 是否显示文本标签。
/// </summary>
public bool show
{
get { return m_Show; }
set { if (PropertyUtil.SetStruct(ref m_Show, value)) SetAllDirty(); }
}
/// <summary>
/// The position of label.
/// 标签的位置。
/// </summary>
public Position position
{
get { return m_Position; }
set { if (PropertyUtil.SetStruct(ref m_Position, value)) SetVerticesDirty(); }
}
/// <summary>
/// 标签内容字符串模版格式器。支持用 \n 换行。
/// 模板变量有:
/// <list type="bullet">
/// <item><description>{a}:系列名。</description></item>
/// <item><description>{b}:数据名。</description></item>
/// <item><description>{c}:数据值。</description></item>
/// <item><description>{d}:百分比。</description></item>
/// </list>
/// </summary>
/// <example>
/// 示例:“{b}:{c}”
/// </example>
public string formatter
{
get { return m_Formatter; }
set { if (PropertyUtil.SetClass(ref m_Formatter, value)) SetVerticesDirty(); }
}
/// <summary>
/// offset to the host graphic element.
/// 距离图形元素的偏移
/// </summary>
public Vector3 offset
{
get { return m_Offset; }
set { if (PropertyUtil.SetStruct(ref m_Offset, value)) SetVerticesDirty(); }
}
/// <summary>
/// 距离轴线的距离。
/// </summary>
public float margin
{
get { return m_Margin; }
set { if (PropertyUtil.SetStruct(ref m_Margin, value)) SetVerticesDirty(); }
}
/// <summary>
/// the width of background. If set as default value 0, it means than the background width auto set as the text width.
/// 标签的背景宽度。一般不用指定,不指定时则自动是文字的宽度。
/// </summary>
/// <value></value>
public float backgroundWidth
{
get { return m_BackgroundWidth; }
set { if (PropertyUtil.SetStruct(ref m_BackgroundWidth, value)) SetComponentDirty(); }
}
/// <summary>
/// the height of background. If set as default value 0, it means than the background height auto set as the text height.
/// 标签的背景高度。一般不用指定,不指定时则自动是文字的高度。
/// </summary>
/// <value></value>
public float backgroundHeight
{
get { return m_BackgroundHeight; }
set { if (PropertyUtil.SetStruct(ref m_BackgroundHeight, value)) SetComponentDirty(); }
}
/// <summary>
/// the text padding of left and right. defaut:2.
/// 左右边距。
/// </summary>
public float paddingLeftRight
{
get { return m_PaddingLeftRight; }
set { if (PropertyUtil.SetStruct(ref m_PaddingLeftRight, value)) SetComponentDirty(); }
}
/// <summary>
/// the text padding of top and bottom. defaut:2.
/// 上下边距。
/// </summary>
public float paddingTopBottom
{
get { return m_PaddingTopBottom; }
set { if (PropertyUtil.SetStruct(ref m_PaddingTopBottom, value)) SetComponentDirty(); }
}
/// <summary>
/// Whether to show border.
/// 是否显示边框。
/// </summary>
public bool border
{
get { return m_Border; }
set { if (PropertyUtil.SetStruct(ref m_Border, value)) SetVerticesDirty(); }
}
/// <summary>
/// the width of border.
/// 边框宽度。
/// </summary>
public float borderWidth
{
get { return m_BorderWidth; }
set { if (PropertyUtil.SetStruct(ref m_BorderWidth, value)) SetVerticesDirty(); }
}
/// <summary>
/// the color of border.
/// 边框颜色。
/// </summary>
public Color32 borderColor
{
get { return m_BorderColor; }
set { if (PropertyUtil.SetStruct(ref m_BorderColor, value)) SetVerticesDirty(); }
}
/// <summary>
/// Standard numeric format strings.
/// 标准数字格式字符串。用于将数值格式化显示为字符串。
/// 使用Axx的形式A是格式说明符的单字符支持C货币、D十进制、E指数、F定点数、G常规、N数字、P百分比、R往返、X十六进制的。xx是精度说明从0-99。
/// 参考https://docs.microsoft.com/zh-cn/dotnet/standard/base-types/standard-numeric-format-strings
/// </summary>
/// <value></value>
public string numericFormatter
{
get { return m_NumericFormatter; }
set { if (PropertyUtil.SetClass(ref m_NumericFormatter, value)) SetComponentDirty(); }
}
/// <summary>
/// 是否开启自动偏移。当开启时Y的偏移会自动判断曲线的开口来决定向上还是向下偏移。
/// </summary>
public bool autoOffset
{
get { return m_AutoOffset; }
set { if (PropertyUtil.SetStruct(ref m_AutoOffset, value)) SetAllDirty(); }
}
/// <summary>
/// the sytle of text.
/// 文本样式。
/// </summary>
public TextStyle textStyle
{
get { return m_TextStyle; }
set { if (PropertyUtil.SetClass(ref m_TextStyle, value)) SetAllDirty(); }
}
public DelegateSerieLabelFormatter formatterFunction
{
get { return m_FormatterFunction; }
set { m_FormatterFunction = value; }
}
public bool IsInside()
{
return position == Position.Inside || position == Position.Center;
}
public Color GetColor(Color defaultColor)
{
if (ChartHelper.IsClearColor(textStyle.color))
{
return IsInside() ? Color.black : defaultColor;
}
else
{
return textStyle.color;
}
}
public TextAnchor GetAutoAlignment()
{
if (textStyle.autoAlign) return textStyle.alignment;
else
{
switch (position)
{
case LabelStyle.Position.Inside:
case LabelStyle.Position.Center:
case LabelStyle.Position.Top:
case LabelStyle.Position.Bottom:
return TextAnchor.MiddleCenter;
case LabelStyle.Position.Outside:
case LabelStyle.Position.Right:
return TextAnchor.MiddleLeft;
case LabelStyle.Position.Left:
return TextAnchor.MiddleRight;
default:
return TextAnchor.MiddleCenter;
}
}
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 0b2c690f282f04752898422894f61738
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,63 @@
using System;
using UnityEngine;
namespace XCharts
{
/// <summary>
/// </summary>
[Serializable]
public class LineArrow : ChildComponent, ISerieExtraComponent
{
public enum Position
{
/// <summary>
/// 末端箭头
/// </summary>
End,
/// <summary>
/// 头端箭头
/// </summary>
Start
}
[SerializeField] private bool m_Show;
[SerializeField] Position m_Position;
[SerializeField]
private ArrowStyle m_Arrow = new ArrowStyle()
{
width = 10,
height = 15,
offset = 0,
dent = 3
};
/// <summary>
/// Whether to show the arrow.
/// 是否显示箭头。
/// </summary>
public bool show
{
get { return m_Show; }
set { if (PropertyUtil.SetStruct(ref m_Show, value)) SetVerticesDirty(); }
}
/// <summary>
/// The position of arrow.
/// 箭头位置。
/// </summary>
public Position position
{
get { return m_Position; }
set { if (PropertyUtil.SetStruct(ref m_Position, value)) SetVerticesDirty(); }
}
/// <summary>
/// the arrow of line.
/// 箭头。
/// </summary>
public ArrowStyle arrow
{
get { return m_Arrow; }
set { if (PropertyUtil.SetClass(ref m_Arrow, value)) SetVerticesDirty(); }
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 8f2455acb3ba34409896bf03ddba593e
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,240 @@
using UnityEngine;
namespace XCharts
{
/// <summary>
/// The style of line.
/// 线条样式。
/// 注: 修改 lineStyle 中的颜色不会影响图例颜色,如果需要图例颜色和折线图颜色一致,需修改 itemStyle.color线条颜色默认也会取该颜色。
/// toColortoColor2可设置水平方向的渐变如需要设置垂直方向的渐变可使用VisualMap。
/// </summary>
[System.Serializable]
public class LineStyle : ChildComponent
{
/// <summary>
/// 线的类型。
/// </summary>
public enum Type
{
/// <summary>
/// 实线
/// </summary>
Solid,
/// <summary>
/// 虚线
/// </summary>
Dashed,
/// <summary>
/// 点线
/// </summary>
Dotted,
/// <summary>
/// 点划线
/// </summary>
DashDot,
/// <summary>
/// 双点划线
/// </summary>
DashDotDot,
None,
}
[SerializeField] private bool m_Show = true;
[SerializeField] private Type m_Type = Type.Solid;
[SerializeField] private Color32 m_Color;
[SerializeField] private Color32 m_ToColor;
[SerializeField] private Color32 m_ToColor2;
[SerializeField] private float m_Width = 0;
[SerializeField] private float m_Length = 0;
[SerializeField] [Range(0, 1)] private float m_Opacity = 1;
/// <summary>
/// Whether show line.
/// 是否显示线条。当作为子组件,它的父组件有参数控制是否显示时,改参数无效。
/// </summary>
public bool show
{
get { return m_Show; }
set { if (PropertyUtil.SetStruct(ref m_Show, value)) SetVerticesDirty(); }
}
/// <summary>
/// the type of line.
/// 线的类型。
/// </summary>
public Type type
{
get { return m_Type; }
set { if (PropertyUtil.SetStruct(ref m_Type, value)) SetVerticesDirty(); }
}
/// <summary>
/// the color of line, default use serie color.
/// 线的颜色。
/// </summary>
public Color32 color
{
get { return m_Color; }
set { if (PropertyUtil.SetColor(ref m_Color, value)) SetVerticesDirty(); }
}
/// <summary>
/// the middle color of line, default use serie color.
/// 线的渐变颜色(需要水平方向渐变时)。
/// </summary>
public Color32 toColor
{
get { return m_ToColor; }
set { if (PropertyUtil.SetColor(ref m_ToColor, value)) SetVerticesDirty(); }
}
/// <summary>
/// the end color of line, default use serie color.
/// 线的渐变颜色2需要水平方向三个渐变色的渐变时
/// </summary>
public Color32 toColor2
{
get { return m_ToColor2; }
set { if (PropertyUtil.SetColor(ref m_ToColor2, value)) SetVerticesDirty(); }
}
/// <summary>
/// the width of line.
/// 线宽。
/// /// </summary>
public float width
{
get { return m_Width; }
set { if (PropertyUtil.SetStruct(ref m_Width, value)) SetVerticesDirty(); }
}
/// <summary>
/// the length of line.
/// 线长。
/// /// </summary>
public float length
{
get { return m_Length; }
set { if (PropertyUtil.SetStruct(ref m_Length, value)) SetVerticesDirty(); }
}
/// <summary>
/// Opacity of the line. Supports value from 0 to 1, and the line will not be drawn when set to 0.
/// 线的透明度。支持从 0 到 1 的数字,为 0 时不绘制该图形。
/// </summary>
public float opacity
{
get { return m_Opacity; }
set { if (PropertyUtil.SetStruct(ref m_Opacity, value)) SetVerticesDirty(); }
}
public LineStyle()
{
}
public LineStyle(float width)
{
this.width = width;
}
public LineStyle(LineStyle.Type type)
{
this.type = type;
}
public LineStyle(LineStyle.Type type, float width)
{
this.type = type;
this.width = width;
}
public LineStyle Clone()
{
var lineStyle = new LineStyle();
lineStyle.show = show;
lineStyle.type = type;
lineStyle.color = color;
lineStyle.toColor = toColor;
lineStyle.toColor2 = toColor2;
lineStyle.width = width;
lineStyle.opacity = opacity;
return lineStyle;
}
public void Copy(LineStyle lineStyle)
{
show = lineStyle.show;
type = lineStyle.type;
color = lineStyle.color;
toColor = lineStyle.toColor;
toColor2 = lineStyle.toColor2;
width = lineStyle.width;
opacity = lineStyle.opacity;
}
public Color32 GetColor()
{
if (m_Opacity == 1)
return m_Color;
var color = m_Color;
color.a = (byte)(color.a * m_Opacity);
return color;
}
public bool IsNeedGradient()
{
return !ChartHelper.IsClearColor(m_ToColor) || !ChartHelper.IsClearColor(m_ToColor2);
}
public Color32 GetGradientColor(float value, Color32 defaultColor)
{
var color = ChartConst.clearColor32;
if (!IsNeedGradient())
return color;
value = Mathf.Clamp01(value);
var startColor = ChartHelper.IsClearColor(m_Color) ? defaultColor : m_Color;
if (!ChartHelper.IsClearColor(m_ToColor2))
{
if (value <= 0.5f)
color = Color32.Lerp(startColor, m_ToColor, 2 * value);
else
color = Color32.Lerp(m_ToColor, m_ToColor2, 2 * (value - 0.5f));
}
else
{
color = Color32.Lerp(startColor, m_ToColor, value);
}
if (m_Opacity != 1)
{
color.a = (byte)(color.a * m_Opacity);
}
return color;
}
public Type GetType(Type themeType)
{
return type == Type.None ? themeType : type;
}
public float GetWidth(float themeWidth)
{
return width == 0 ? themeWidth : width;
}
public float GetLength(float themeLength)
{
return length == 0 ? themeLength : length;
}
public Color32 GetColor(Color32 themeColor)
{
if (!ChartHelper.IsClearColor(color))
{
return GetColor();
}
else
{
var color = themeColor;
color.a = (byte)(color.a * opacity);
return color;
}
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 092f08a2daa4b4013a72ffc3c9a18f85
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,322 @@

using System;
using UnityEngine;
#if dUI_TextMeshPro
using TMPro;
#endif
namespace XCharts
{
/// <summary>
/// Location type. Quick to set the general location.
/// 位置类型。通过Align快速设置大体位置再通过leftrighttopbottom微调具体位置。
/// </summary>
[Serializable]
public class Location : ChildComponent, IPropertyChanged
{
/// <summary>
/// 对齐方式
/// </summary>
public enum Align
{
TopLeft,
TopRight,
TopCenter,
BottomLeft,
BottomRight,
BottomCenter,
Center,
CenterLeft,
CenterRight
}
[SerializeField] private Align m_Align = Align.TopCenter;
[SerializeField] private float m_Left;
[SerializeField] private float m_Right;
[SerializeField] private float m_Top;
[SerializeField] private float m_Bottom;
private TextAnchor m_TextAlignment;
#if dUI_TextMeshPro
private TextAlignmentOptions m_TMPTextAlignment;
#endif
private Vector2 m_AnchorMin;
private Vector2 m_AnchorMax;
private Vector2 m_Pivot;
/// <summary>
/// 对齐方式。
/// </summary>
public Align align
{
get { return m_Align; }
set { if (PropertyUtil.SetStruct(ref m_Align, value)) { SetComponentDirty(); UpdateAlign(); } }
}
/// <summary>
/// Distance between component and the left side of the container.
/// 离容器左侧的距离。
/// </summary>
public float left
{
get { return m_Left; }
set { if (PropertyUtil.SetStruct(ref m_Left, value)) { SetComponentDirty(); UpdateAlign(); } }
}
/// <summary>
/// Distance between component and the left side of the container.
/// 离容器右侧的距离。
/// </summary>
public float right
{
get { return m_Right; }
set { if (PropertyUtil.SetStruct(ref m_Right, value)) { SetComponentDirty(); UpdateAlign(); } }
}
/// <summary>
/// Distance between component and the left side of the container.
/// 离容器上侧的距离。
/// </summary>
public float top
{
get { return m_Top; }
set { if (PropertyUtil.SetStruct(ref m_Top, value)) { SetComponentDirty(); UpdateAlign(); } }
}
/// <summary>
/// Distance between component and the left side of the container.
/// 离容器下侧的距离。
/// </summary>
public float bottom
{
get { return m_Bottom; }
set { if (PropertyUtil.SetStruct(ref m_Bottom, value)) { SetComponentDirty(); UpdateAlign(); } }
}
/// <summary>
/// the anchor of text.
/// Location对应的Anchor锚点
/// </summary>
/// <value></value>
public TextAnchor runtimeTextAlignment { get { return m_TextAlignment; } }
#if dUI_TextMeshPro
public TextAlignmentOptions runtimeTMPTextAlignment { get { return m_TMPTextAlignment; } }
#endif
/// <summary>
/// the minimum achor.
/// Location对应的anchorMin。
/// </summary>
public Vector2 runtimeAnchorMin { get { return m_AnchorMin; } }
/// <summary>
/// the maximun achor.
/// Location对应的anchorMax.
/// </summary>
public Vector2 runtimeAnchorMax { get { return m_AnchorMax; } }
/// <summary>
/// the povot.
/// Loation对应的中心点。
/// </summary>
public Vector2 runtimePivot { get { return m_Pivot; } }
public float runtimeLeft { get; private set; }
public float runtimeRight { get; private set; }
public float runtimeBottom { get; private set; }
public float runtimeTop { get; private set; }
public static Location defaultLeft
{
get
{
return new Location()
{
align = Align.CenterLeft,
left = 0.03f,
right = 0,
top = 0,
bottom = 0
};
}
}
public static Location defaultRight
{
get
{
return new Location()
{
align = Align.CenterRight,
left = 0,
right = 0.03f,
top = 0,
bottom = 0
};
}
}
public static Location defaultTop
{
get
{
return new Location()
{
align = Align.TopCenter,
left = 0,
right = 0,
top = 0.03f,
bottom = 0
};
}
}
public static Location defaultBottom
{
get
{
return new Location()
{
align = Align.BottomCenter,
left = 0,
right = 0,
top = 0,
bottom = 0.03f
};
}
}
private void UpdateAlign()
{
switch (m_Align)
{
case Align.BottomCenter:
m_TextAlignment = TextAnchor.LowerCenter;
#if dUI_TextMeshPro
m_TMPTextAlignment = TextAlignmentOptions.Bottom;
#endif
m_AnchorMin = new Vector2(0.5f, 0);
m_AnchorMax = new Vector2(0.5f, 0);
m_Pivot = new Vector2(0.5f, 0);
break;
case Align.BottomLeft:
m_TextAlignment = TextAnchor.LowerLeft;
#if dUI_TextMeshPro
m_TMPTextAlignment = TextAlignmentOptions.BottomLeft;
#endif
m_AnchorMin = new Vector2(0, 0);
m_AnchorMax = new Vector2(0, 0);
m_Pivot = new Vector2(0, 0);
break;
case Align.BottomRight:
m_TextAlignment = TextAnchor.LowerRight;
#if dUI_TextMeshPro
m_TMPTextAlignment = TextAlignmentOptions.BottomRight;
#endif
m_AnchorMin = new Vector2(1, 0);
m_AnchorMax = new Vector2(1, 0);
m_Pivot = new Vector2(1, 0);
break;
case Align.Center:
m_TextAlignment = TextAnchor.MiddleCenter;
#if dUI_TextMeshPro
m_TMPTextAlignment = TextAlignmentOptions.Center;
#endif
m_AnchorMin = new Vector2(0.5f, 0.5f);
m_AnchorMax = new Vector2(0.5f, 0.5f);
m_Pivot = new Vector2(0.5f, 0.5f);
break;
case Align.CenterLeft:
m_TextAlignment = TextAnchor.MiddleLeft;
#if dUI_TextMeshPro
m_TMPTextAlignment = TextAlignmentOptions.Left;
#endif
m_AnchorMin = new Vector2(0, 0.5f);
m_AnchorMax = new Vector2(0, 0.5f);
m_Pivot = new Vector2(0, 0.5f);
break;
case Align.CenterRight:
m_TextAlignment = TextAnchor.MiddleRight;
#if dUI_TextMeshPro
m_TMPTextAlignment = TextAlignmentOptions.Right;
#endif
m_AnchorMin = new Vector2(1, 0.5f);
m_AnchorMax = new Vector2(1, 0.5f);
m_Pivot = new Vector2(1, 0.5f);
break;
case Align.TopCenter:
m_TextAlignment = TextAnchor.UpperCenter;
#if dUI_TextMeshPro
m_TMPTextAlignment = TextAlignmentOptions.Top;
#endif
m_AnchorMin = new Vector2(0.5f, 1);
m_AnchorMax = new Vector2(0.5f, 1);
m_Pivot = new Vector2(0.5f, 1);
break;
case Align.TopLeft:
m_TextAlignment = TextAnchor.UpperLeft;
#if dUI_TextMeshPro
m_TMPTextAlignment = TextAlignmentOptions.TopLeft;
#endif
m_AnchorMin = new Vector2(0, 1);
m_AnchorMax = new Vector2(0, 1);
m_Pivot = new Vector2(0, 1);
break;
case Align.TopRight:
m_TextAlignment = TextAnchor.UpperRight;
#if dUI_TextMeshPro
m_TMPTextAlignment = TextAlignmentOptions.TopRight;
#endif
m_AnchorMin = new Vector2(1, 1);
m_AnchorMax = new Vector2(1, 1);
m_Pivot = new Vector2(1, 1);
break;
default:
break;
}
}
public void UpdateRuntimeData(float chartWidth, float chartHeight)
{
runtimeLeft = left <= 1 ? left * chartWidth : left;
runtimeRight = right <= 1 ? right * chartWidth : right;
runtimeTop = top <= 1 ? top * chartHeight : top;
runtimeBottom = bottom <= 1 ? bottom * chartHeight : bottom;
}
/// <summary>
/// 返回在坐标系中的具体位置
/// </summary>
/// <param name="chartWidth"></param>
/// <param name="chartHeight"></param>
/// <returns></returns>
public Vector3 GetPosition(float chartWidth, float chartHeight)
{
UpdateRuntimeData(chartWidth, chartHeight);
switch (align)
{
case Align.BottomCenter:
return new Vector3(chartWidth / 2, runtimeBottom);
case Align.BottomLeft:
return new Vector3(runtimeLeft, runtimeBottom);
case Align.BottomRight:
return new Vector3(chartWidth - runtimeRight, runtimeBottom);
case Align.Center:
return new Vector3(chartWidth / 2, chartHeight / 2);
case Align.CenterLeft:
return new Vector3(runtimeLeft, chartHeight / 2);
case Align.CenterRight:
return new Vector3(chartWidth - runtimeRight, chartHeight / 2);
case Align.TopCenter:
return new Vector3(chartWidth / 2, chartHeight - runtimeTop);
case Align.TopLeft:
return new Vector3(runtimeLeft, chartHeight - runtimeTop);
case Align.TopRight:
return new Vector3(chartWidth - runtimeRight, chartHeight - runtimeTop);
default:
return Vector2.zero;
}
}
/// <summary>
/// 属性变更时更新textAnchor,minAnchor,maxAnchor,pivot
/// </summary>
public void OnChanged()
{
UpdateAlign();
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 7922ce86a6b0f4813a7f34e004b92e9a
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,27 @@
using System.Collections.Generic;
using UnityEngine;
namespace XCharts
{
[System.Serializable]
public class StageColor
{
[SerializeField] private float m_Percent;
[SerializeField] private Color32 m_Color;
/// <summary>
/// 结束位置百分比。
/// </summary>
public float percent { get { return m_Percent; } set { m_Percent = value; } }
/// <summary>
/// 颜色。
/// </summary>
public Color32 color { get { return m_Color; } set { m_Color = value; } }
public StageColor(float percent, Color32 color)
{
m_Percent = percent;
m_Color = color;
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: d40f9dfbc90e744858784753e0d7109d
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,403 @@

using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
namespace XCharts
{
/// <summary>
/// the type of symbol.
/// 标记图形的类型。
/// </summary>
public enum SymbolType
{
/// <summary>
/// 不显示标记。
/// </summary>
None,
/// <summary>
/// 自定义标记。
/// </summary>
Custom,
/// <summary>
/// 圆形。
/// </summary>
Circle,
/// <summary>
/// 空心圆。
/// </summary>
EmptyCircle,
/// <summary>
/// 正方形。可通过设置`itemStyle`的`cornerRadius`变成圆角矩形。
/// </summary>
Rect,
/// <summary>
/// 空心正方形。
/// </summary>
EmptyRect,
/// <summary>
/// 三角形。
/// </summary>
Triangle,
/// <summary>
/// 空心三角形。
/// </summary>
EmptyTriangle,
/// <summary>
/// 菱形。
/// </summary>
Diamond,
/// <summary>
/// 空心菱形。
/// </summary>
EmptyDiamond,
/// <summary>
/// 箭头。
/// </summary>
Arrow,
/// <summary>
/// 空心箭头。
/// </summary>
EmptyArrow
}
/// <summary>
/// The way to get serie symbol size.
/// 获取标记图形大小的方式。
/// </summary>
public enum SymbolSizeType
{
/// <summary>
/// Specify constant for symbol size.
/// 自定义大小。
/// </summary>
Custom,
/// <summary>
/// Specify the dataIndex and dataScale to calculate symbol size.
/// 通过 dataIndex 从数据中获取,再乘以一个比例系数 dataScale 。
/// </summary>
FromData,
/// <summary>
/// Specify callback function for symbol size.
/// 通过回调函数获取。
/// </summary>
Callback,
}
/// <summary>
/// 获取标记大小的回调。
/// </summary>
/// <param name="data"></param>
/// <returns></returns>
public delegate float SymbolSizeCallback(List<double> data);
/// <summary>
/// 系列数据项的标记的图形
/// </summary>
[System.Serializable]
public class SymbolStyle : ChildComponent, ISerieDataComponent
{
[SerializeField] private bool m_Show = true;
[SerializeField] private SymbolType m_Type = SymbolType.EmptyCircle;
[SerializeField] private SymbolSizeType m_SizeType = SymbolSizeType.Custom;
[SerializeField] private float m_Size = 0f;
[SerializeField] private float m_SelectedSize = 0f;
[SerializeField] private int m_DataIndex = 1;
[SerializeField] private float m_DataScale = 1;
[SerializeField] private float m_SelectedDataScale = 1.5f;
[SerializeField] private SymbolSizeCallback m_SizeCallback;
[SerializeField] private SymbolSizeCallback m_SelectedSizeCallback;
[SerializeField] private int m_StartIndex;
[SerializeField] private int m_Interval;
[SerializeField] private bool m_ForceShowLast = false;
[SerializeField] private float m_Gap = 0;
[SerializeField] private float m_Width = 0f;
[SerializeField] private float m_Height = 0f;
[SerializeField] private bool m_Repeat = false;
[SerializeField] private Vector2 m_Offset = Vector2.zero;
[SerializeField] private Sprite m_Image;
[SerializeField] private Image.Type m_ImageType;
public void Reset()
{
m_Show = false;
m_Type = SymbolType.EmptyCircle;
m_SizeType = SymbolSizeType.Custom;
m_Size = 0f;
m_SelectedSize = 0f;
m_DataIndex = 1;
m_DataScale = 1;
m_SelectedDataScale = 1.5f;
m_SizeCallback = null;
m_SelectedSizeCallback = null;
m_StartIndex = 0;
m_Interval = 0;
m_ForceShowLast = false;
m_Gap = 0;
m_Width = 0f;
m_Height = 0f;
m_Repeat = false;
m_Offset = Vector2.zero;
m_Image = null;
m_ImageType = Image.Type.Simple;
}
/// <summary>
/// Whether the symbol is showed.
/// 是否显示标记。
/// </summary>
public bool show
{
get { return m_Show; }
set { if (PropertyUtil.SetStruct(ref m_Show, value)) SetAllDirty(); }
}
/// <summary>
/// the type of symbol.
/// 标记类型。
/// </summary>
public SymbolType type
{
get { return m_Type; }
set { if (PropertyUtil.SetStruct(ref m_Type, value)) SetVerticesDirty(); }
}
/// <summary>
/// the type of symbol size.
/// 标记图形的大小获取方式。
/// </summary>
public SymbolSizeType sizeType
{
get { return m_SizeType; }
set { if (PropertyUtil.SetStruct(ref m_SizeType, value)) SetVerticesDirty(); }
}
/// <summary>
/// the size of symbol.
/// 标记的大小。
/// </summary>
public float size
{
get { return m_Size; }
set { if (PropertyUtil.SetStruct(ref m_Size, value)) SetVerticesDirty(); }
}
/// <summary>
/// the size of selected symbol.
/// 被选中的标记的大小。
/// </summary>
public float selectedSize
{
get { return m_SelectedSize; }
set { if (PropertyUtil.SetStruct(ref m_SelectedSize, value)) SetVerticesDirty(); }
}
/// <summary>
/// whitch data index is when the sizeType assined as FromData.
/// 当sizeType指定为FromData时指定的数据源索引。
/// </summary>
public int dataIndex
{
get { return m_DataIndex; }
set { if (PropertyUtil.SetStruct(ref m_DataIndex, value)) SetVerticesDirty(); }
}
/// <summary>
/// the scale of data when sizeType assined as FromData.
/// 当sizeType指定为FromData时指定的倍数系数。
/// </summary>
public float dataScale
{
get { return m_DataScale; }
set { if (PropertyUtil.SetStruct(ref m_DataScale, value)) SetVerticesDirty(); }
}
/// <summary>
/// the scale of selected data when sizeType assined as FromData.
/// 当sizeType指定为FromData时指定的高亮倍数系数。
/// </summary>
public float selectedDataScale
{
get { return m_SelectedDataScale; }
set { if (PropertyUtil.SetStruct(ref m_SelectedDataScale, value)) SetVerticesDirty(); }
}
/// <summary>
/// the callback of size when sizeType assined as Callback.
/// 当sizeType指定为Callback时指定的回调函数。
/// </summary>
public SymbolSizeCallback sizeCallback
{
get { return m_SizeCallback; }
set { if (PropertyUtil.SetClass(ref m_SizeCallback, value)) SetVerticesDirty(); }
}
/// <summary>
/// the callback of size when sizeType assined as Callback.
/// 当sizeType指定为Callback时指定的高亮回调函数。
/// </summary>
public SymbolSizeCallback selectedSizeCallback
{
get { return m_SelectedSizeCallback; }
set { if (PropertyUtil.SetClass(ref m_SelectedSizeCallback, value)) SetVerticesDirty(); }
}
/// <summary>
/// the index start to show symbol.
/// 开始显示图形标记的索引。
/// </summary>
public int startIndex
{
get { return m_StartIndex; }
set { if (PropertyUtil.SetStruct(ref m_StartIndex, value)) SetVerticesDirty(); }
}
/// <summary>
/// the interval of show symbol.
/// 显示图形标记的间隔。0表示显示所有标签1表示隔一个隔显示一个标签以此类推。
/// </summary>
public int interval
{
get { return m_Interval; }
set { if (PropertyUtil.SetStruct(ref m_Interval, value)) SetVerticesDirty(); }
}
/// <summary>
/// whether to show the last symbol.
/// 是否强制显示最后一个图形标记。
/// </summary>
public bool forceShowLast
{
get { return m_ForceShowLast; }
set { if (PropertyUtil.SetStruct(ref m_ForceShowLast, value)) SetVerticesDirty(); }
}
/// <summary>
/// the gap of symbol and line segment.
/// 图形标记和线条的间隙距离。
/// </summary>
public float gap
{
get { return m_Gap; }
set { if (PropertyUtil.SetStruct(ref m_Gap, value)) SetVerticesDirty(); }
}
/// <summary>
/// 图形的宽。
/// </summary>
public float width
{
get { return m_Width; }
set { if (PropertyUtil.SetStruct(ref m_Width, value)) SetAllDirty(); }
}
/// <summary>
/// 图形的高。
/// </summary>
public float height
{
get { return m_Height; }
set { if (PropertyUtil.SetStruct(ref m_Height, value)) SetAllDirty(); }
}
/// <summary>
/// 图形是否重复。
/// </summary>
public bool repeat
{
get { return m_Repeat; }
set { if (PropertyUtil.SetStruct(ref m_Repeat, value)) SetAllDirty(); }
}
/// <summary>
/// 自定义的标记图形。
/// </summary>
public Sprite image
{
get { return m_Image; }
set { if (PropertyUtil.SetClass(ref m_Image, value)) SetAllDirty(); }
}
public Image.Type imageType
{
get { return m_ImageType; }
set { if (PropertyUtil.SetStruct(ref m_ImageType, value)) SetAllDirty(); }
}
/// <summary>
/// 图形的偏移。
/// </summary>
public Vector2 offset
{
get { return m_Offset; }
set { if (PropertyUtil.SetStruct(ref m_Offset, value)) SetAllDirty(); }
}
public Vector3 offset3 { get { return new Vector3(m_Offset.x, m_Offset.y, 0); } }
private List<float> m_AnimationSize = new List<float>() { 0, 5, 10 };
/// <summary>
/// the setting for effect scatter.
/// 带有涟漪特效动画的散点图的动画参数。
/// </summary>
public List<float> animationSize { get { return m_AnimationSize; } }
/// <summary>
/// 根据指定的sizeType获得标记的大小
/// </summary>
/// <param name="data"></param>
/// <returns></returns>
public float GetSize(List<double> data, float themeSize)
{
switch (m_SizeType)
{
case SymbolSizeType.Custom:
return size == 0 ? themeSize : size;
case SymbolSizeType.FromData:
if (data != null && dataIndex >= 0 && dataIndex < data.Count)
{
return (float)data[dataIndex] * m_DataScale;
}
else
{
return size == 0 ? themeSize : size;
}
case SymbolSizeType.Callback:
if (data != null && sizeCallback != null) return sizeCallback(data);
else return size == 0 ? themeSize : size;
default: return size == 0 ? themeSize : size;
}
}
/// <summary>
/// 根据sizeType获得高亮时的标记大小
/// </summary>
/// <param name="data"></param>
/// <returns></returns>
public float GetSelectedSize(List<double> data, float themeSelectedSize)
{
switch (m_SizeType)
{
case SymbolSizeType.Custom:
return selectedSize == 0 ? themeSelectedSize : selectedSize;
case SymbolSizeType.FromData:
if (data != null && dataIndex >= 0 && dataIndex < data.Count)
{
return (float)data[dataIndex] * m_SelectedDataScale;
}
else
{
return selectedSize == 0 ? themeSelectedSize : selectedSize;
}
case SymbolSizeType.Callback:
if (data != null && selectedSizeCallback != null)
return selectedSizeCallback(data);
else
return selectedSize == 0 ? themeSelectedSize : selectedSize;
default: return selectedSize == 0 ? themeSelectedSize : selectedSize;
}
}
public bool ShowSymbol(int dataIndex, int dataCount)
{
if (!show)
return false;
if (dataIndex < startIndex)
return false;
if (m_Interval <= 0)
return true;
if (m_ForceShowLast && dataIndex == dataCount - 1)
return true;
return (dataIndex - startIndex) % (m_Interval + 1) == 0;
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 837d37f4d6f614b38bef9f075a64b6dc
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,152 @@
using System;
using UnityEngine;
using UnityEngine.UI;
namespace XCharts
{
/// <summary>
/// Text character limitation and adaptation component. When the length of the text exceeds the set length,
/// it is cropped and suffixes are appended to the end.Only valid in the category axis.
/// 文本字符限制和自适应。当文本长度超过设定的长度时进行裁剪,并将后缀附加在最后。
/// 只在类目轴中有效。
/// </summary>
[Serializable]
public class TextLimit : ChildComponent
{
[SerializeField] private bool m_Enable = false;
[SerializeField] private float m_MaxWidth = 0;
[SerializeField] private float m_Gap = 1;
[SerializeField] private string m_Suffix = "...";
/// <summary>
/// Whether to enable text limit.
/// 是否启用文本自适应。
/// [default:true]
/// </summary>
public bool enable
{
get { return m_Enable; }
set { if (PropertyUtil.SetStruct(ref m_Enable, value)) SetComponentDirty(); }
}
/// <summary>
/// Set the maximum width. A default of 0 indicates automatic fetch; otherwise, custom.
/// Clipping occurs when the width of the text is greater than this value.
/// 设定最大宽度。默认为0表示自动获取否则表示自定义。当文本的宽度大于该值进行裁剪。
/// </summary>
public float maxWidth
{
get { return m_MaxWidth; }
set { if (PropertyUtil.SetStruct(ref m_MaxWidth, value)) SetComponentDirty(); }
}
/// <summary>
/// White pixel distance at both ends.
/// 两边留白像素距离。
/// [default:10f]
/// </summary>
public float gap
{
get { return m_Gap; }
set { if (PropertyUtil.SetStruct(ref m_Gap, value)) SetComponentDirty(); }
}
/// <summary>
/// Suffixes when the length exceeds.
/// 长度超出时的后缀。
/// [default: "..."]
/// </summary>
public string suffix
{
get { return m_Suffix; }
set { if (PropertyUtil.SetClass(ref m_Suffix, value)) SetComponentDirty(); }
}
private ChartText m_RelatedText;
private float m_RelatedTextWidth = 0;
public TextLimit Clone()
{
var textLimit = new TextLimit();
textLimit.enable = enable;
textLimit.maxWidth = maxWidth;
textLimit.gap = gap;
textLimit.suffix = suffix;
return textLimit;
}
public void Copy(TextLimit textLimit)
{
enable = textLimit.enable;
maxWidth = textLimit.maxWidth;
gap = textLimit.gap;
suffix = textLimit.suffix;
}
public void SetRelatedText(ChartText txt, float labelWidth)
{
m_RelatedText = txt;
m_RelatedTextWidth = labelWidth;
}
public string GetLimitContent(string content)
{
float checkWidth = m_MaxWidth > 0 ? m_MaxWidth : m_RelatedTextWidth;
if (m_RelatedText == null || checkWidth <= 0)
{
return content;
}
else
{
if (m_Enable)
{
float len = m_RelatedText.GetPreferredWidth(content);
float suffixLen = m_RelatedText.GetPreferredWidth(suffix);
if (len >= checkWidth - m_Gap * 2)
{
return content.Substring(0, GetAdaptLength(content, suffixLen)) + suffix;
}
else
{
return content;
}
}
else
{
return content;
}
}
}
private int GetAdaptLength(string content, float suffixLen)
{
int start = 0;
int middle = content.Length / 2;
int end = content.Length;
float checkWidth = m_MaxWidth > 0 ? m_MaxWidth : m_RelatedTextWidth;
float limit = checkWidth - m_Gap * 2 - suffixLen;
if (limit < 0)
return 0;
float len = 0;
while (len != limit && middle != start)
{
len = m_RelatedText.GetPreferredWidth(content.Substring(0, middle));
if (len < limit)
{
start = middle;
}
else if (len > limit)
{
end = middle;
}
else
{
break;
}
middle = (start + end) / 2;
}
return middle;
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 3f49509a5de044535b1dd3f192f7008c
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,249 @@
using System;
using UnityEngine;
#if dUI_TextMeshPro
using TMPro;
#endif
namespace XCharts
{
/// <summary>
/// Settings related to text.
/// 文本的相关设置。
/// </summary>
[Serializable]
public class TextStyle : ChildComponent
{
[SerializeField] private Font m_Font;
[SerializeField] private bool m_AutoWrap = false;
[SerializeField] private bool m_AutoAlign = true;
[SerializeField] private float m_Rotate = 0;
[SerializeField] private float m_ExtraWidth = 0;
[SerializeField] private Vector2 m_Offset = Vector2.zero;
[SerializeField] private Color m_Color = Color.clear;
[SerializeField] private Color m_BackgroundColor = Color.clear;
[SerializeField] private int m_FontSize = 0;
[SerializeField] private FontStyle m_FontStyle = FontStyle.Normal;
[SerializeField] private float m_LineSpacing = 1f;
[SerializeField] private TextAnchor m_Alignment = TextAnchor.MiddleCenter;
#if dUI_TextMeshPro
[SerializeField] private TMP_FontAsset m_TMPFont;
[SerializeField] private FontStyles m_TMPFontStyle = FontStyles.Normal;
[SerializeField] private TextAlignmentOptions m_TMPAlignment = TextAlignmentOptions.Left;
#endif
/// <summary>
/// Rotation of text.
/// 文本的旋转。
/// [default: `0f`]
/// </summary>
public float rotate
{
get { return m_Rotate; }
set { if (PropertyUtil.SetStruct(ref m_Rotate, value)) SetComponentDirty(); }
}
/// <summary>
/// Extra width of text preferred width.
/// 额外的宽度
/// </summary>
public float extraWidth
{
get { return m_ExtraWidth; }
set { if (PropertyUtil.SetStruct(ref m_ExtraWidth, value)) SetComponentDirty(); }
}
/// <summary>
/// the offset of position.
/// 坐标偏移。
/// [Default: `Vector2.zero`]
/// </summary>
public Vector2 offset
{
get { return m_Offset; }
set { if (PropertyUtil.SetStruct(ref m_Offset, value)) SetComponentDirty(); }
}
public Vector3 offsetv3 { get { return new Vector3(m_Offset.x, m_Offset.y, 0); } }
/// <summary>
/// the color of text.
/// 文本的颜色。
/// [default: `Color.clear`]
/// </summary>
public Color color
{
get { return m_Color; }
set { if (PropertyUtil.SetColor(ref m_Color, value)) SetComponentDirty(); }
}
/// <summary>
/// the color of text.
/// 文本的背景颜色。
/// [default: `Color.clear`]
/// </summary>
public Color backgroundColor
{
get { return m_BackgroundColor; }
set { if (PropertyUtil.SetColor(ref m_BackgroundColor, value)) SetComponentDirty(); }
}
/// <summary>
/// the font of text. When `null`, the theme's font is used by default.
/// 文本字体。
/// [default: null]
/// </summary>
public Font font
{
get { return m_Font; }
set { if (PropertyUtil.SetClass(ref m_Font, value)) SetComponentDirty(); }
}
/// <summary>
/// font size.
/// 文本字体大小。
/// [default: 18]
/// </summary>
public int fontSize
{
get { return m_FontSize; }
set { if (PropertyUtil.SetStruct(ref m_FontSize, value)) SetComponentDirty(); }
}
/// <summary>
/// font style.
/// 文本字体的风格。
/// [default: FontStyle.Normal]
/// </summary>
public FontStyle fontStyle
{
get { return m_FontStyle; }
set { if (PropertyUtil.SetStruct(ref m_FontStyle, value)) SetComponentDirty(); }
}
/// <summary>
/// text line spacing.
/// 行间距。
/// [default: 1f]
/// </summary>
public float lineSpacing
{
get { return m_LineSpacing; }
set { if (PropertyUtil.SetStruct(ref m_LineSpacing, value)) SetComponentDirty(); }
}
/// <summary>
/// 是否自动换行。
/// </summary>
public bool autoWrap
{
get { return m_AutoWrap; }
set { if (PropertyUtil.SetStruct(ref m_AutoWrap, value)) SetComponentDirty(); }
}
/// <summary>
/// 文本是否让系统自动选对齐方式。为false时才会用alignment。
/// </summary>
public bool autoAlign
{
get { return m_AutoAlign; }
set { if (PropertyUtil.SetStruct(ref m_AutoAlign, value)) SetComponentDirty(); }
}
/// <summary>
/// 对齐方式。
/// </summary>
public TextAnchor alignment
{
get { return m_Alignment; }
set { if (PropertyUtil.SetStruct(ref m_Alignment, value)) SetComponentDirty(); }
}
#if dUI_TextMeshPro
public TMP_FontAsset tmpFont
{
get { return m_TMPFont; }
set { if (PropertyUtil.SetClass(ref m_TMPFont, value)) SetComponentDirty(); }
}
public FontStyles tmpFontStyle
{
get { return m_TMPFontStyle; }
set { if (PropertyUtil.SetStruct(ref m_TMPFontStyle, value)) SetComponentDirty(); }
}
public TextAlignmentOptions tmpAlignment
{
get { return m_TMPAlignment; }
set { if (PropertyUtil.SetStruct(ref m_TMPAlignment, value)) SetComponentDirty(); }
}
#endif
public TextStyle()
{
}
public TextStyle(int fontSize)
{
this.fontSize = fontSize;
}
public TextStyle(int fontSize, FontStyle fontStyle)
{
this.fontSize = fontSize;
this.fontStyle = fontStyle;
}
public TextStyle(int fontSize, FontStyle fontStyle, Color color)
{
this.fontSize = fontSize;
this.fontStyle = fontStyle;
this.color = color;
}
public TextStyle(int fontSize, FontStyle fontStyle, Color color, int rorate)
{
this.fontSize = fontSize;
this.fontStyle = fontStyle;
this.color = color;
this.rotate = rotate;
}
public void Copy(TextStyle textStyle)
{
font = textStyle.font;
rotate = textStyle.rotate;
offset = textStyle.offset;
color = textStyle.color;
backgroundColor = textStyle.backgroundColor;
fontSize = textStyle.fontSize;
fontStyle = textStyle.fontStyle;
lineSpacing = textStyle.lineSpacing;
alignment = textStyle.alignment;
autoWrap = textStyle.autoWrap;
autoAlign = textStyle.autoAlign;
#if dUI_TextMeshPro
m_TMPFont = textStyle.tmpFont;
m_TMPAlignment = textStyle.tmpAlignment;
m_TMPFontStyle = textStyle.tmpFontStyle;
#endif
}
public void UpdateAlignmentByLocation(Location location)
{
#if dUI_TextMeshPro
m_TMPAlignment = location.runtimeTMPTextAlignment;
#else
m_Alignment = location.runtimeTextAlignment;
#endif
}
public Color GetColor(Color defaultColor)
{
if (ChartHelper.IsClearColor(color))
return defaultColor;
else
return color;
}
public int GetFontSize(ComponentTheme defaultTheme)
{
if (fontSize == 0)
return defaultTheme.fontSize;
else
return fontSize;
}
public TextAnchor GetAlignment(TextAnchor systemAlignment)
{
return m_AutoAlign ? systemAlignment : alignment;
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: e8f6b652968894ab195666501dda672c
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: