mirror of
https://github.com/XCharts-Team/XCharts.git
synced 2026-05-23 01:10:08 +00:00
增加GaugeChart仪表盘
This commit is contained in:
305
Runtime/Component/Sub/GaugeAxis.cs
Normal file
305
Runtime/Component/Sub/GaugeAxis.cs
Normal file
@@ -0,0 +1,305 @@
|
||||
/******************************************/
|
||||
/* */
|
||||
/* Copyright (c) 2018 monitor1394 */
|
||||
/* https://github.com/monitor1394 */
|
||||
/* */
|
||||
/******************************************/
|
||||
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace XCharts
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// Settings related to gauge axis line.
|
||||
/// 仪表盘轴线相关设置。
|
||||
/// </summary>
|
||||
[System.Serializable]
|
||||
public class GaugeAxis : SubComponent
|
||||
{
|
||||
[System.Serializable]
|
||||
public class AxisLine
|
||||
{
|
||||
[System.Serializable]
|
||||
public class StageColor
|
||||
{
|
||||
[SerializeField] private float m_Percent;
|
||||
[SerializeField] private Color m_Color;
|
||||
/// <summary>
|
||||
/// 结束位置百分比。
|
||||
/// </summary>
|
||||
public float percent { get { return m_Percent; } set { m_Percent = value; } }
|
||||
/// <summary>
|
||||
/// 颜色。
|
||||
/// </summary>
|
||||
public Color color { get { return m_Color; } set { m_Color = value; } }
|
||||
|
||||
public StageColor(float percent, Color color)
|
||||
{
|
||||
m_Percent = percent;
|
||||
m_Color = color;
|
||||
}
|
||||
}
|
||||
[SerializeField] private bool m_Show = true;
|
||||
[SerializeField] private float m_Width = 15f;
|
||||
[SerializeField] private float m_Opacity = 1f;
|
||||
[SerializeField] private Color m_BarColor;
|
||||
[SerializeField] private Color m_BarBackgroundColor = new Color32(200, 200, 200, 255);
|
||||
[SerializeField]
|
||||
private List<StageColor> m_StageColor = new List<StageColor>()
|
||||
{
|
||||
new StageColor(0.2f,new Color32(145,199,174,255)),
|
||||
new StageColor(0.8f,new Color32(99,134,158,255)),
|
||||
new StageColor(1.0f,new Color32(194,53,49,255)),
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// Set this to false to prevent the axis line from showing.
|
||||
/// 是否显示坐标轴轴线。
|
||||
/// </summary>
|
||||
public bool show { get { return m_Show; } set { m_Show = value; } }
|
||||
/// <summary>
|
||||
/// line style line width.
|
||||
/// 坐标轴线线宽。
|
||||
/// </summary>
|
||||
public float width { get { return m_Width; } set { m_Width = value; } }
|
||||
/// <summary>
|
||||
/// The opacity of axis line.
|
||||
/// 透明度。
|
||||
/// </summary>
|
||||
public float opacity { get { return m_Opacity; } set { m_Opacity = value; } }
|
||||
/// <summary>
|
||||
/// 进度条颜色。
|
||||
/// </summary>
|
||||
public Color barColor { get { return m_BarColor; } set { m_BarColor = value; } }
|
||||
/// <summary>
|
||||
/// 进度条背景颜色。
|
||||
/// </summary>
|
||||
public Color barBackgroundColor { get { return m_BarBackgroundColor; } set { m_BarBackgroundColor = value; } }
|
||||
/// <summary>
|
||||
/// 阶段颜色。
|
||||
/// </summary>
|
||||
public List<StageColor> stageColor { get { return m_StageColor; } set { m_StageColor = value; } }
|
||||
}
|
||||
/// <summary>
|
||||
/// 分割线
|
||||
/// </summary>
|
||||
[System.Serializable]
|
||||
public class SplitLine
|
||||
{
|
||||
[SerializeField] private bool m_Show = true;
|
||||
[SerializeField] private float m_Length = 15;
|
||||
[SerializeField]
|
||||
private LineStyle m_LineStyle = new LineStyle()
|
||||
{
|
||||
width = 1.5f,
|
||||
type = LineStyle.Type.Solid,
|
||||
color = new Color32(238, 238, 238, 255)
|
||||
};
|
||||
/// <summary>
|
||||
/// 是否显示分割线。
|
||||
/// </summary>
|
||||
public bool show { get { return m_Show; } set { m_Show = value; } }
|
||||
/// <summary>
|
||||
/// 分割线长度。
|
||||
/// </summary>
|
||||
public float length { get { return m_Length; } set { m_Length = value; } }
|
||||
/// <summary>
|
||||
/// 分割线样式。
|
||||
/// </summary>
|
||||
public LineStyle lineStyle { get { return m_LineStyle; } set { m_LineStyle = value; } }
|
||||
}
|
||||
/// <summary>
|
||||
/// 刻度
|
||||
/// </summary>
|
||||
[System.Serializable]
|
||||
public class AxisTick
|
||||
{
|
||||
[SerializeField] private bool m_Show = true;
|
||||
[SerializeField] private float m_Length = 5;
|
||||
[SerializeField] private float m_SplitNumber = 5;
|
||||
[SerializeField]
|
||||
private LineStyle m_LineStyle = new LineStyle()
|
||||
{
|
||||
width = 1f,
|
||||
type = LineStyle.Type.Solid,
|
||||
color = new Color32(238, 238, 238, 255)
|
||||
};
|
||||
/// <summary>
|
||||
/// 是否显示刻度。
|
||||
/// </summary>
|
||||
public bool show { get { return m_Show; } set { m_Show = value; } }
|
||||
/// <summary>
|
||||
/// 刻度长度。当为0-1的浮点数时表示半径的百分比。
|
||||
/// </summary>
|
||||
public float length { get { return m_Length; } set { m_Length = value; } }
|
||||
/// <summary>
|
||||
/// 分割线之间的分割段数。
|
||||
/// </summary>
|
||||
public float splitNumber { get { return m_SplitNumber; } set { m_SplitNumber = value; } }
|
||||
/// <summary>
|
||||
/// 刻度线样式。
|
||||
/// </summary>
|
||||
public LineStyle lineStyle { get { return m_LineStyle; } set { m_LineStyle = value; } }
|
||||
}
|
||||
[SerializeField] private bool m_Show = true;
|
||||
[SerializeField] private AxisLine m_AxisLine = new AxisLine();
|
||||
[SerializeField] private SplitLine m_SplitLine = new SplitLine();
|
||||
[SerializeField] private AxisTick m_AxisTick = new AxisTick();
|
||||
[SerializeField] private SerieLabel m_AxisLabel = new SerieLabel();
|
||||
[SerializeField] private List<string> m_AxisLabelText = new List<string>();
|
||||
|
||||
public bool show { get { return m_Show; } set { m_Show = value; } }
|
||||
/// <summary>
|
||||
/// 仪表盘轴线。
|
||||
/// </summary>
|
||||
public AxisLine axisLine { get { return m_AxisLine; } set { m_AxisLine = value; } }
|
||||
/// <summary>
|
||||
/// 分割线。
|
||||
/// </summary>
|
||||
public SplitLine splitLine { get { return m_SplitLine; } set { m_SplitLine = value; } }
|
||||
/// <summary>
|
||||
/// 刻度。
|
||||
/// </summary>
|
||||
public AxisTick axisTick { get { return m_AxisTick; } set { m_AxisTick = value; } }
|
||||
/// <summary>
|
||||
/// 文本标签。
|
||||
/// </summary>
|
||||
public SerieLabel axisLabel { get { return m_AxisLabel; } set { m_AxisLabel = value; } }
|
||||
/// <summary>
|
||||
/// 自定义Label的内容。
|
||||
/// </summary>
|
||||
public List<string> axisLabelText { get { return m_AxisLabelText; } set { m_AxisLabelText = value; } }
|
||||
|
||||
public List<float> runtimeStageAngle = new List<float>();
|
||||
public List<Vector3> runtimeLabelPosition = new List<Vector3>();
|
||||
private List<LabelObject> m_RuntimeLabelList = new List<LabelObject>();
|
||||
|
||||
internal Color GetAxisLineColor(ThemeInfo theme, int index)
|
||||
{
|
||||
var color = axisLine.barColor != Color.clear ? axisLine.barColor : (Color)theme.GetColor(index);
|
||||
color.a *= axisLine.opacity;
|
||||
return color;
|
||||
}
|
||||
|
||||
internal Color GetAxisLineBackgroundColor(ThemeInfo theme, int index)
|
||||
{
|
||||
var color = axisLine.barBackgroundColor != Color.clear ? axisLine.barBackgroundColor : Color.grey;
|
||||
color.a *= axisLine.opacity;
|
||||
return color;
|
||||
}
|
||||
|
||||
internal Color GetSplitLineColor(ThemeInfo theme, int serieIndex, float angle)
|
||||
{
|
||||
Color color;
|
||||
if (splitLine.lineStyle.color != Color.clear)
|
||||
{
|
||||
color = splitLine.lineStyle.color;
|
||||
color.a *= splitLine.lineStyle.opacity;
|
||||
return color;
|
||||
}
|
||||
for (int i = 0; i < runtimeStageAngle.Count; i++)
|
||||
{
|
||||
if (angle < runtimeStageAngle[i])
|
||||
{
|
||||
color = axisLine.stageColor[i].color;
|
||||
color.a *= splitLine.lineStyle.opacity;
|
||||
return color;
|
||||
}
|
||||
}
|
||||
color = theme.GetColor(serieIndex);
|
||||
color.a *= splitLine.lineStyle.opacity;
|
||||
return color;
|
||||
}
|
||||
|
||||
internal Color GetAxisTickColor(ThemeInfo theme, int serieIndex, float angle)
|
||||
{
|
||||
Color color;
|
||||
if (axisTick.lineStyle.color != Color.clear)
|
||||
{
|
||||
color = axisTick.lineStyle.color;
|
||||
color.a *= axisTick.lineStyle.opacity;
|
||||
return color;
|
||||
}
|
||||
for (int i = 0; i < runtimeStageAngle.Count; i++)
|
||||
{
|
||||
if (angle < runtimeStageAngle[i])
|
||||
{
|
||||
color = axisLine.stageColor[i].color;
|
||||
color.a *= axisTick.lineStyle.opacity;
|
||||
return color;
|
||||
}
|
||||
}
|
||||
color = theme.GetColor(serieIndex);
|
||||
color.a *= axisTick.lineStyle.opacity;
|
||||
return color;
|
||||
}
|
||||
|
||||
internal Color GetPointerColor(ThemeInfo theme, int serieIndex, float angle, ItemStyle itemStyle)
|
||||
{
|
||||
Color color;
|
||||
if (itemStyle.color != Color.clear)
|
||||
{
|
||||
color = itemStyle.color;
|
||||
color.a *= itemStyle.opacity;
|
||||
return color;
|
||||
}
|
||||
for (int i = 0; i < runtimeStageAngle.Count; i++)
|
||||
{
|
||||
if (angle < runtimeStageAngle[i])
|
||||
{
|
||||
color = axisLine.stageColor[i].color;
|
||||
color.a *= itemStyle.opacity;
|
||||
return color;
|
||||
}
|
||||
}
|
||||
color = theme.GetColor(serieIndex);
|
||||
color.a *= itemStyle.opacity;
|
||||
return color;
|
||||
}
|
||||
|
||||
public void ClearLabelObject()
|
||||
{
|
||||
m_RuntimeLabelList.Clear();
|
||||
}
|
||||
|
||||
public void AddLabelObject(LabelObject label)
|
||||
{
|
||||
m_RuntimeLabelList.Add(label);
|
||||
}
|
||||
|
||||
public LabelObject GetLabelObject(int index)
|
||||
{
|
||||
if (index >= 0 && index < m_RuntimeLabelList.Count)
|
||||
{
|
||||
return m_RuntimeLabelList[index];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void SetLabelObjectPosition(int index, Vector3 pos)
|
||||
{
|
||||
if (index >= 0 && index < m_RuntimeLabelList.Count)
|
||||
{
|
||||
m_RuntimeLabelList[index].SetPosition(pos);
|
||||
}
|
||||
}
|
||||
|
||||
public void SetLabelObjectText(int index, string text)
|
||||
{
|
||||
if (index >= 0 && index < m_RuntimeLabelList.Count)
|
||||
{
|
||||
m_RuntimeLabelList[index].SetText(text);
|
||||
}
|
||||
}
|
||||
|
||||
public void SetLabelObjectActive(bool flag)
|
||||
{
|
||||
foreach (var label in m_RuntimeLabelList)
|
||||
{
|
||||
label.SetActive(flag);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Runtime/Component/Sub/GaugeAxis.cs.meta
Normal file
11
Runtime/Component/Sub/GaugeAxis.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 67cba46d89b9b478fa6dcf067e7b49b7
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
40
Runtime/Component/Sub/GaugePointer.cs
Normal file
40
Runtime/Component/Sub/GaugePointer.cs
Normal file
@@ -0,0 +1,40 @@
|
||||
/******************************************/
|
||||
/* */
|
||||
/* Copyright (c) 2018 monitor1394 */
|
||||
/* https://github.com/monitor1394 */
|
||||
/* */
|
||||
/******************************************/
|
||||
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace XCharts
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// Settings related to gauge pointer.
|
||||
/// 仪表盘指针相关设置。
|
||||
/// </summary>
|
||||
[System.Serializable]
|
||||
public class GaugePointer : SubComponent
|
||||
{
|
||||
[SerializeField] private bool m_Show = true;
|
||||
[SerializeField] private float m_Length = 0.8f;
|
||||
[SerializeField] private float m_Width = 15;
|
||||
|
||||
/// <summary>
|
||||
/// 是否显示指针。
|
||||
/// </summary>
|
||||
public bool show { get { return m_Show; } set { m_Show = value; } }
|
||||
/// <summary>
|
||||
/// 指针长度。可以是绝对值,也可以是相对于半径的百分比(0-1的浮点数)
|
||||
/// </summary>
|
||||
/// <value></value>
|
||||
public float length { get { return m_Length; } set { m_Length = value; } }
|
||||
/// <summary>
|
||||
/// 指针宽度。
|
||||
/// </summary>
|
||||
/// <value></value>
|
||||
public float width { get { return m_Width; } set { m_Width = value; } }
|
||||
}
|
||||
}
|
||||
11
Runtime/Component/Sub/GaugePointer.cs.meta
Normal file
11
Runtime/Component/Sub/GaugePointer.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 55e453b57f6514da09e98571439d4dcc
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -23,10 +23,12 @@ namespace XCharts
|
||||
}
|
||||
[SerializeField] private bool m_Enable = true;
|
||||
[SerializeField] private Easing m_Easting;
|
||||
[SerializeField] private int m_Duration = 1000;
|
||||
[SerializeField] private float m_Duration = 1000;
|
||||
[SerializeField] private int m_Threshold = 2000;
|
||||
[SerializeField] private int m_Delay = 0;
|
||||
[SerializeField] private int m_ActualDuration;
|
||||
[SerializeField] private float m_Delay = 0;
|
||||
[SerializeField] private bool m_UpdateAnimation = false;
|
||||
[SerializeField] private float m_UpdateDuration = 500;
|
||||
[SerializeField] private float m_ActualDuration;
|
||||
|
||||
/// <summary>
|
||||
/// Whether to enable animation.
|
||||
@@ -42,12 +44,12 @@ namespace XCharts
|
||||
/// The milliseconds duration of the first animation.
|
||||
/// 设定的动画时长(毫秒)。
|
||||
/// </summary>
|
||||
public int duration { get { return m_Duration; } set { m_Duration = value; } }
|
||||
public float duration { get { return m_Duration; } set { m_Duration = value < 0 ? 0 : value; } }
|
||||
/// <summary>
|
||||
/// The milliseconds actual duration of the first animation.
|
||||
/// 实际的动画时长(毫秒)。
|
||||
/// </summary>
|
||||
public int actualDuration { get { return m_ActualDuration; } }
|
||||
public float actualDuration { get { return m_ActualDuration; } }
|
||||
/// <summary>
|
||||
/// Whether to set graphic number threshold to animation. Animation will be disabled when graphic number is larger than threshold.
|
||||
/// 是否开启动画的阈值,当单个系列显示的图形数量大于这个阈值时会关闭动画。
|
||||
@@ -57,7 +59,16 @@ namespace XCharts
|
||||
/// The milliseconds delay before updating the first animation.
|
||||
/// 动画延时(毫秒)。
|
||||
/// </summary>
|
||||
public int delay { get { return m_Delay; } set { m_Delay = value; if (m_Delay < 0) m_Delay = 0; } }
|
||||
public float delay { get { return m_Delay; } set { m_Delay = value < 0 ? 0 : value; } }
|
||||
/// <summary>
|
||||
/// 是否开启数据变更动画。
|
||||
/// </summary>
|
||||
public bool updateAnimation { get { return m_UpdateAnimation; } set { m_UpdateAnimation = value; } }
|
||||
/// <summary>
|
||||
/// The milliseconds duration of the first animation.
|
||||
/// 数据变更的动画时长(毫秒)。
|
||||
/// </summary>
|
||||
public float updateDuration { get { return m_UpdateDuration; } set { m_UpdateDuration = value < 0 ? 0 : value; } }
|
||||
|
||||
private Dictionary<int, float> m_DataAnimationState = new Dictionary<int, float>();
|
||||
private bool m_IsStart = false;
|
||||
@@ -232,5 +243,11 @@ namespace XCharts
|
||||
{
|
||||
return m_CurrDataProgress;
|
||||
}
|
||||
|
||||
public float GetUpdateAnimationDuration()
|
||||
{
|
||||
if (m_Enable && m_UpdateAnimation && IsFinish()) return m_UpdateDuration;
|
||||
else return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -24,6 +24,8 @@ namespace XCharts
|
||||
[SerializeField] private bool m_Selected;
|
||||
[SerializeField] private float m_Radius;
|
||||
[SerializeField] private IconStyle m_IconStyle = new IconStyle();
|
||||
[SerializeField] private bool m_EnableLabel = false;
|
||||
[SerializeField] private SerieLabel m_Label = new SerieLabel();
|
||||
[SerializeField] private List<float> m_Data = new List<float>();
|
||||
|
||||
private bool m_Show = true;
|
||||
@@ -58,6 +60,14 @@ namespace XCharts
|
||||
/// </summary>
|
||||
public IconStyle iconStyle { get { return m_IconStyle; } set { m_IconStyle = value; } }
|
||||
/// <summary>
|
||||
/// 是否启用单个数据项的标签设置。
|
||||
/// </summary>
|
||||
public bool enableLabel { get { return m_EnableLabel; } set { m_EnableLabel = value; } }
|
||||
/// <summary>
|
||||
/// 单个数据项的标签设置。
|
||||
/// </summary>
|
||||
public SerieLabel label { get { return m_Label; } set { m_Label = value; } }
|
||||
/// <summary>
|
||||
/// An arbitrary dimension data list of data item.
|
||||
/// 可指定任意维数的数值列表。
|
||||
/// </summary>
|
||||
@@ -143,12 +153,67 @@ namespace XCharts
|
||||
public float runtimePieOffsetRadius { get; internal set; }
|
||||
public Vector3 runtiemPieOffsetCenter { get; internal set; }
|
||||
|
||||
private bool m_DataChanged;
|
||||
private float m_LastData;
|
||||
private float m_DataUpdateTime;
|
||||
|
||||
public float GetData(int index)
|
||||
{
|
||||
if (index >= 0 && index < m_Data.Count) return m_Data[index];
|
||||
if (index >= 0 && index < m_Data.Count)
|
||||
{
|
||||
return m_Data[index];
|
||||
}
|
||||
else return 0;
|
||||
}
|
||||
|
||||
public float GetCurrData(int index, float animationDuration = 500f)
|
||||
{
|
||||
if (index == 1 && m_DataChanged)
|
||||
{
|
||||
var time = Time.time - m_DataUpdateTime;
|
||||
var total = animationDuration / 1000;
|
||||
if (animationDuration > 0 && time <= total)
|
||||
{
|
||||
var curr = Mathf.Lerp(m_LastData, GetData(index), time / total);
|
||||
return curr;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_DataChanged = false;
|
||||
return GetData(index);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return GetData(index);
|
||||
}
|
||||
}
|
||||
|
||||
public float GetLastData(int index)
|
||||
{
|
||||
if (index == 1 && m_DataChanged) return m_LastData;
|
||||
else return GetData(index);
|
||||
}
|
||||
|
||||
public void UpdateData(int dimension, float value)
|
||||
{
|
||||
if (dimension >= 0 && dimension < data.Count)
|
||||
{
|
||||
if (dimension == 1)
|
||||
{
|
||||
m_LastData = data[dimension];
|
||||
m_DataUpdateTime = Time.time;
|
||||
m_DataChanged = true;
|
||||
}
|
||||
data[dimension] = value;
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsDataChanged()
|
||||
{
|
||||
return m_DataChanged;
|
||||
}
|
||||
|
||||
public void InitLabel(GameObject labelObj, bool autoSize, float paddingLeftRight, float paddingTopBottom)
|
||||
{
|
||||
gameObject = labelObj;
|
||||
@@ -169,7 +234,7 @@ namespace XCharts
|
||||
|
||||
public bool SetLabelText(string text)
|
||||
{
|
||||
if (labelText)
|
||||
if (labelText && !labelText.text.Equals(text))
|
||||
{
|
||||
labelText.text = text;
|
||||
if (m_LabelAutoSize)
|
||||
@@ -185,6 +250,14 @@ namespace XCharts
|
||||
return false;
|
||||
}
|
||||
|
||||
public void SetLabelColor(Color color)
|
||||
{
|
||||
if (labelText)
|
||||
{
|
||||
labelText.color = color;
|
||||
}
|
||||
}
|
||||
|
||||
public float GetLabelWidth()
|
||||
{
|
||||
if (labelRect) return labelRect.sizeDelta.x;
|
||||
@@ -224,5 +297,16 @@ namespace XCharts
|
||||
if (iconStyle == null) return;
|
||||
iconStyle.UpdateIcon();
|
||||
}
|
||||
|
||||
public bool IsInitLabel()
|
||||
{
|
||||
return labelText != null;
|
||||
}
|
||||
|
||||
public SerieLabel GetSerieLabel(SerieLabel parentLabel)
|
||||
{
|
||||
if (enableLabel) return label;
|
||||
else return parentLabel;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -80,6 +80,7 @@ namespace XCharts
|
||||
[SerializeField] private bool m_Show = false;
|
||||
[SerializeField] Position m_Position;
|
||||
[SerializeField] private Vector3 m_Offset;
|
||||
[SerializeField] private float m_Margin;
|
||||
[SerializeField] private string m_Formatter;
|
||||
[SerializeField] private float m_Rotate = 0;
|
||||
[SerializeField] private float m_PaddingLeftRight = 2f;
|
||||
@@ -130,6 +131,10 @@ namespace XCharts
|
||||
/// </summary>
|
||||
public Vector3 offset { get { return m_Offset; } set { m_Offset = value; } }
|
||||
/// <summary>
|
||||
/// 距离轴线的距离。
|
||||
/// </summary>
|
||||
public float margin { get { return m_Margin; } set { m_Margin = value; } }
|
||||
/// <summary>
|
||||
/// Text color,If set as default ,the color will assigned as series color.
|
||||
/// 自定义文字颜色,默认和系列的颜色一致。
|
||||
/// </summary>
|
||||
|
||||
109
Runtime/Component/Sub/TitleStyle.cs
Normal file
109
Runtime/Component/Sub/TitleStyle.cs
Normal file
@@ -0,0 +1,109 @@
|
||||
/*
|
||||
/******************************************/
|
||||
/* */
|
||||
/* Copyright (c) 2018 monitor1394 */
|
||||
/* https://github.com/monitor1394 */
|
||||
/* */
|
||||
/******************************************/
|
||||
|
||||
using System;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace XCharts
|
||||
{
|
||||
/// <summary>
|
||||
/// the title of serie.
|
||||
/// 标题相关设置。
|
||||
/// </summary>
|
||||
[Serializable]
|
||||
public class TitleStyle : SubComponent, IEquatable<TitleStyle>
|
||||
{
|
||||
[SerializeField] private bool m_Show;
|
||||
[SerializeField] private TextStyle m_textStyle = new TextStyle(18);
|
||||
|
||||
/// <summary>
|
||||
/// Whether to show title.
|
||||
/// 是否显示标题。
|
||||
/// </summary>
|
||||
public bool show { get { return m_Show; } set { m_Show = value; } }
|
||||
|
||||
/// <summary>
|
||||
/// the color of text.
|
||||
/// 文本的颜色。
|
||||
/// </summary>
|
||||
public TextStyle textStyle { get { return m_textStyle; } set { m_textStyle = value; } }
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public Text runtimeText { get; set; }
|
||||
|
||||
public TitleStyle Clone()
|
||||
{
|
||||
var title = new TitleStyle();
|
||||
title.show = show;
|
||||
title.textStyle = textStyle.Clone();
|
||||
return title;
|
||||
}
|
||||
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
if (ReferenceEquals(null, obj))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else if (obj is TitleStyle)
|
||||
{
|
||||
return Equals((TitleStyle)obj);
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public bool Equals(TitleStyle other)
|
||||
{
|
||||
if (ReferenceEquals(null, other))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return textStyle.Equals(other.textStyle);
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return base.GetHashCode();
|
||||
}
|
||||
|
||||
public bool IsInited()
|
||||
{
|
||||
return runtimeText != null;
|
||||
}
|
||||
|
||||
public void SetActive(bool active)
|
||||
{
|
||||
if (runtimeText)
|
||||
{
|
||||
ChartHelper.SetActive(runtimeText, active);
|
||||
}
|
||||
}
|
||||
|
||||
public void UpdatePosition(Vector3 pos)
|
||||
{
|
||||
if (runtimeText)
|
||||
{
|
||||
runtimeText.transform.localPosition = pos + new Vector3(m_textStyle.offset.x, m_textStyle.offset.y);
|
||||
}
|
||||
}
|
||||
|
||||
public void SetText(string text)
|
||||
{
|
||||
if (runtimeText)
|
||||
{
|
||||
if (textStyle.color != Color.clear) runtimeText.color = textStyle.color;
|
||||
runtimeText.text = text;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Runtime/Component/Sub/TitleStyle.cs.meta
Normal file
11
Runtime/Component/Sub/TitleStyle.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0f3865dea73ae403581fe83cfeca13f0
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user