mirror of
https://github.com/XCharts-Team/XCharts.git
synced 2026-05-24 18:00:26 +00:00
增加IconStyle子组件,优化SerieData的图标配置
This commit is contained in:
67
Assets/XCharts/Editor/PropertyDrawers/IconStyleDrawer.cs
Normal file
67
Assets/XCharts/Editor/PropertyDrawers/IconStyleDrawer.cs
Normal file
@@ -0,0 +1,67 @@
|
|||||||
|
/******************************************/
|
||||||
|
/* */
|
||||||
|
/* Copyright (c) 2018 monitor1394 */
|
||||||
|
/* https://github.com/monitor1394 */
|
||||||
|
/* */
|
||||||
|
/******************************************/
|
||||||
|
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using UnityEditor;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
namespace XCharts
|
||||||
|
{
|
||||||
|
[CustomPropertyDrawer(typeof(IconStyle), true)]
|
||||||
|
public class IconStyleDrawer : PropertyDrawer
|
||||||
|
{
|
||||||
|
private Dictionary<string, bool> m_IconStyleToggle = new Dictionary<string, bool>();
|
||||||
|
|
||||||
|
public override void OnGUI(Rect pos, SerializedProperty prop, GUIContent label)
|
||||||
|
{
|
||||||
|
Rect drawRect = pos;
|
||||||
|
drawRect.height = EditorGUIUtility.singleLineHeight;
|
||||||
|
SerializedProperty m_Show = prop.FindPropertyRelative("m_Show");
|
||||||
|
SerializedProperty m_Layer = prop.FindPropertyRelative("m_Layer");
|
||||||
|
SerializedProperty m_Sprite = prop.FindPropertyRelative("m_Sprite");
|
||||||
|
SerializedProperty m_Color = prop.FindPropertyRelative("m_Color");
|
||||||
|
SerializedProperty m_Width = prop.FindPropertyRelative("m_Width");
|
||||||
|
SerializedProperty m_Height = prop.FindPropertyRelative("m_Height");
|
||||||
|
SerializedProperty m_Offset = prop.FindPropertyRelative("m_Offset");
|
||||||
|
ChartEditorHelper.MakeFoldout(ref drawRect, ref m_IconStyleToggle, prop, null, m_Show, false);
|
||||||
|
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
||||||
|
if (ChartEditorHelper.IsToggle(m_IconStyleToggle, prop))
|
||||||
|
{
|
||||||
|
++EditorGUI.indentLevel;
|
||||||
|
|
||||||
|
EditorGUI.PropertyField(drawRect, m_Layer);
|
||||||
|
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
||||||
|
EditorGUI.PropertyField(drawRect, m_Sprite);
|
||||||
|
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
||||||
|
EditorGUI.PropertyField(drawRect, m_Color);
|
||||||
|
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
||||||
|
EditorGUI.PropertyField(drawRect, m_Width);
|
||||||
|
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
||||||
|
EditorGUI.PropertyField(drawRect, m_Height);
|
||||||
|
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
||||||
|
EditorGUI.PropertyField(drawRect, m_Offset);
|
||||||
|
drawRect.y += EditorGUI.GetPropertyHeight(m_Offset);
|
||||||
|
--EditorGUI.indentLevel;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public override float GetPropertyHeight(SerializedProperty prop, GUIContent label)
|
||||||
|
{
|
||||||
|
if (ChartEditorHelper.IsToggle(m_IconStyleToggle, prop))
|
||||||
|
{
|
||||||
|
var hight = 6 * EditorGUIUtility.singleLineHeight + 6 * EditorGUIUtility.standardVerticalSpacing;
|
||||||
|
hight += EditorGUI.GetPropertyHeight(prop.FindPropertyRelative("m_Offset"));
|
||||||
|
hight += EditorGUIUtility.standardVerticalSpacing;
|
||||||
|
return hight;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 9cae26ad61d224d8a97d41bdc52ec0b7
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@@ -173,7 +173,7 @@ namespace XCharts
|
|||||||
{
|
{
|
||||||
EditorGUI.indentLevel++;
|
EditorGUI.indentLevel++;
|
||||||
|
|
||||||
float nameWid = 40;
|
float nameWid = 42;
|
||||||
EditorGUI.PropertyField(new Rect(drawRect.x, drawRect.y, pos.width - 2 * nameWid - 2, pos.height), m_DataDimension);
|
EditorGUI.PropertyField(new Rect(drawRect.x, drawRect.y, pos.width - 2 * nameWid - 2, pos.height), m_DataDimension);
|
||||||
var nameRect = new Rect(pos.width - 2 * nameWid + 14, drawRect.y, nameWid, pos.height);
|
var nameRect = new Rect(pos.width - 2 * nameWid + 14, drawRect.y, nameWid, pos.height);
|
||||||
if (GUI.Button(nameRect, new GUIContent("Name")))
|
if (GUI.Button(nameRect, new GUIContent("Name")))
|
||||||
@@ -181,7 +181,7 @@ namespace XCharts
|
|||||||
m_ShowDataName.boolValue = !m_ShowDataName.boolValue;
|
m_ShowDataName.boolValue = !m_ShowDataName.boolValue;
|
||||||
}
|
}
|
||||||
var iconRect = new Rect(pos.width - nameWid + 14, drawRect.y, nameWid, pos.height);
|
var iconRect = new Rect(pos.width - nameWid + 14, drawRect.y, nameWid, pos.height);
|
||||||
if (GUI.Button(iconRect, new GUIContent("Icon")))
|
if (GUI.Button(iconRect, new GUIContent("Other")))
|
||||||
{
|
{
|
||||||
m_ShowDataIcon.boolValue = !m_ShowDataIcon.boolValue;
|
m_ShowDataIcon.boolValue = !m_ShowDataIcon.boolValue;
|
||||||
}
|
}
|
||||||
@@ -232,7 +232,7 @@ namespace XCharts
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void DrawDataElement(ref Rect drawRect, int dimension, SerializedProperty m_Datas, bool showName,
|
private void DrawDataElement(ref Rect drawRect, int dimension, SerializedProperty m_Datas, bool showName,
|
||||||
bool showIconDetail, bool showSelected, int index, float currentWidth)
|
bool showDetail, bool showSelected, int index, float currentWidth)
|
||||||
{
|
{
|
||||||
var lastX = drawRect.x;
|
var lastX = drawRect.x;
|
||||||
var lastWid = drawRect.width;
|
var lastWid = drawRect.width;
|
||||||
@@ -253,7 +253,7 @@ namespace XCharts
|
|||||||
if (showSelected)
|
if (showSelected)
|
||||||
{
|
{
|
||||||
drawRect.width = drawRect.width - 18;
|
drawRect.width = drawRect.width - 18;
|
||||||
EditorGUI.PropertyField(drawRect, element);
|
EditorGUI.PropertyField(drawRect, element, new GUIContent("Element " + index));
|
||||||
drawRect.x = currentWidth - 45;
|
drawRect.x = currentWidth - 45;
|
||||||
EditorGUI.PropertyField(drawRect, selected, GUIContent.none);
|
EditorGUI.PropertyField(drawRect, selected, GUIContent.none);
|
||||||
drawRect.x = lastX;
|
drawRect.x = lastX;
|
||||||
@@ -261,13 +261,14 @@ namespace XCharts
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
EditorGUI.PropertyField(drawRect, element);
|
EditorGUI.PropertyField(drawRect, element, new GUIContent("Element " + index));
|
||||||
}
|
}
|
||||||
drawRect.y += EditorGUI.GetPropertyHeight(element) + EditorGUIUtility.standardVerticalSpacing;
|
drawRect.y += EditorGUI.GetPropertyHeight(element) + EditorGUIUtility.standardVerticalSpacing;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
EditorGUI.LabelField(drawRect, "Element " + index);
|
EditorGUI.LabelField(drawRect, "Element " + index);
|
||||||
|
Debug.LogError("Element " + index);
|
||||||
var startX = drawRect.x + EditorGUIUtility.labelWidth - EditorGUI.indentLevel * 15;
|
var startX = drawRect.x + EditorGUIUtility.labelWidth - EditorGUI.indentLevel * 15;
|
||||||
var dataWidTotal = (currentWidth - (startX + 20.5f + 1));
|
var dataWidTotal = (currentWidth - (startX + 20.5f + 1));
|
||||||
var dataWid = dataWidTotal / fieldCount;
|
var dataWid = dataWidTotal / fieldCount;
|
||||||
@@ -296,36 +297,12 @@ namespace XCharts
|
|||||||
EditorGUIUtility.fieldWidth = lastFieldWid;
|
EditorGUIUtility.fieldWidth = lastFieldWid;
|
||||||
EditorGUIUtility.labelWidth = lastLabelWid;
|
EditorGUIUtility.labelWidth = lastLabelWid;
|
||||||
}
|
}
|
||||||
if (showIconDetail)
|
if (showDetail)
|
||||||
{
|
{
|
||||||
EditorGUI.indentLevel++;
|
EditorGUI.indentLevel++;
|
||||||
var m_ShowIcon = serieData.FindPropertyRelative("m_ShowIcon");
|
var m_Icon = serieData.FindPropertyRelative("m_IconStyle");
|
||||||
var m_IconImage = serieData.FindPropertyRelative("m_IconImage");
|
EditorGUI.PropertyField(drawRect, m_Icon);
|
||||||
var m_IconColor = serieData.FindPropertyRelative("m_IconColor");
|
drawRect.y += EditorGUI.GetPropertyHeight(m_Icon);
|
||||||
var m_IconWidth = serieData.FindPropertyRelative("m_IconWidth");
|
|
||||||
var m_IconHeight = serieData.FindPropertyRelative("m_IconHeight");
|
|
||||||
var m_IconOffset = serieData.FindPropertyRelative("m_IconOffset");
|
|
||||||
EditorGUI.PropertyField(drawRect, m_ShowIcon);
|
|
||||||
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
|
||||||
EditorGUI.PropertyField(drawRect, m_IconImage);
|
|
||||||
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
|
||||||
EditorGUI.PropertyField(drawRect, m_IconColor);
|
|
||||||
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
|
||||||
EditorGUI.PropertyField(drawRect, m_IconWidth);
|
|
||||||
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
|
||||||
EditorGUI.PropertyField(drawRect, m_IconHeight);
|
|
||||||
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
|
||||||
|
|
||||||
EditorGUI.LabelField(drawRect, "Icon Offset");
|
|
||||||
var startX = drawRect.x + EditorGUIUtility.labelWidth - EditorGUI.indentLevel * 15;
|
|
||||||
var tempWidth = (drawRect.width - startX + 72) / 2;
|
|
||||||
var centerXRect = new Rect(startX, drawRect.y, tempWidth, drawRect.height);
|
|
||||||
var centerYRect = new Rect(centerXRect.x + tempWidth - 58, drawRect.y, tempWidth, drawRect.height);
|
|
||||||
var x = EditorGUI.FloatField(centerXRect, m_IconOffset.vector3Value.x);
|
|
||||||
var y = EditorGUI.FloatField(centerYRect, m_IconOffset.vector3Value.y);
|
|
||||||
m_IconOffset.vector3Value = new Vector3(x, y);
|
|
||||||
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
|
||||||
|
|
||||||
EditorGUI.indentLevel--;
|
EditorGUI.indentLevel--;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -373,15 +350,25 @@ namespace XCharts
|
|||||||
if (m_DataFoldout[index])
|
if (m_DataFoldout[index])
|
||||||
{
|
{
|
||||||
SerializedProperty m_Data = prop.FindPropertyRelative("m_Data");
|
SerializedProperty m_Data = prop.FindPropertyRelative("m_Data");
|
||||||
int num = m_Data.arraySize + 2;
|
height += 2 * EditorGUIUtility.singleLineHeight + 1 * EditorGUIUtility.standardVerticalSpacing;
|
||||||
if (num > 30) num = 15;
|
int num = m_Data.arraySize;
|
||||||
|
if (num > 30)
|
||||||
|
{
|
||||||
|
num = 11;
|
||||||
|
height += (num + 1) * EditorGUIUtility.singleLineHeight + (num) * EditorGUIUtility.standardVerticalSpacing;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
height += (num) * EditorGUIUtility.singleLineHeight + (num - 1) * EditorGUIUtility.standardVerticalSpacing;
|
||||||
|
}
|
||||||
if (prop.FindPropertyRelative("m_ShowDataIcon").boolValue)
|
if (prop.FindPropertyRelative("m_ShowDataIcon").boolValue)
|
||||||
{
|
{
|
||||||
num *= 5;
|
for (int i = 0; i < num; i++)
|
||||||
num += 2;
|
{
|
||||||
|
var item = m_Data.GetArrayElementAtIndex(i);
|
||||||
|
height += EditorGUI.GetPropertyHeight(item.FindPropertyRelative("m_IconStyle"));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
height += num * EditorGUIUtility.singleLineHeight + (num - 1) * EditorGUIUtility.standardVerticalSpacing;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
if (m_ShowJsonDataArea)
|
if (m_ShowJsonDataArea)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ namespace XCharts
|
|||||||
[CustomPropertyDrawer(typeof(TextStyle), true)]
|
[CustomPropertyDrawer(typeof(TextStyle), true)]
|
||||||
public class TextStyleDrawer : PropertyDrawer
|
public class TextStyleDrawer : PropertyDrawer
|
||||||
{
|
{
|
||||||
private Dictionary<string, bool> m_TextStyleToggle = new Dictionary<string, bool>();
|
//private Dictionary<string, bool> m_TextStyleToggle = new Dictionary<string, bool>();
|
||||||
|
|
||||||
public override void OnGUI(Rect pos, SerializedProperty prop, GUIContent label)
|
public override void OnGUI(Rect pos, SerializedProperty prop, GUIContent label)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -114,7 +114,7 @@ public class ChartEditorHelper
|
|||||||
{
|
{
|
||||||
if (showProp.propertyType == SerializedPropertyType.Boolean)
|
if (showProp.propertyType == SerializedPropertyType.Boolean)
|
||||||
{
|
{
|
||||||
drawRect.width = 60;
|
drawRect.width = 80;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1028,7 +1028,7 @@ namespace XCharts
|
|||||||
{
|
{
|
||||||
foreach (var data in m_Data)
|
foreach (var data in m_Data)
|
||||||
{
|
{
|
||||||
data.showIcon = flag;
|
data.iconStyle.show = flag;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1042,7 +1042,7 @@ namespace XCharts
|
|||||||
if (dataIndex >= 0 && dataIndex < m_Data.Count)
|
if (dataIndex >= 0 && dataIndex < m_Data.Count)
|
||||||
{
|
{
|
||||||
var data = m_Data[dataIndex];
|
var data = m_Data[dataIndex];
|
||||||
data.showIcon = flag;
|
data.iconStyle.show = flag;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1055,8 +1055,8 @@ namespace XCharts
|
|||||||
{
|
{
|
||||||
foreach (var data in m_Data)
|
foreach (var data in m_Data)
|
||||||
{
|
{
|
||||||
data.iconWidth = width;
|
data.iconStyle.width = width;
|
||||||
data.iconHeight = height;
|
data.iconStyle.height = height;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1070,7 +1070,7 @@ namespace XCharts
|
|||||||
if (dataIndex >= 0 && dataIndex < m_Data.Count)
|
if (dataIndex >= 0 && dataIndex < m_Data.Count)
|
||||||
{
|
{
|
||||||
var data = m_Data[dataIndex];
|
var data = m_Data[dataIndex];
|
||||||
data.iconImage = image;
|
data.iconStyle.sprite = image;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1078,7 +1078,7 @@ namespace XCharts
|
|||||||
{
|
{
|
||||||
foreach (var data in m_Data)
|
foreach (var data in m_Data)
|
||||||
{
|
{
|
||||||
if (data.showIcon) return true;
|
if (data.iconStyle.show) return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -1094,8 +1094,8 @@ namespace XCharts
|
|||||||
if (dataIndex >= 0 && dataIndex < m_Data.Count)
|
if (dataIndex >= 0 && dataIndex < m_Data.Count)
|
||||||
{
|
{
|
||||||
var data = m_Data[dataIndex];
|
var data = m_Data[dataIndex];
|
||||||
data.iconWidth = width;
|
data.iconStyle.width = width;
|
||||||
data.iconHeight = height;
|
data.iconStyle.height = height;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1109,7 +1109,7 @@ namespace XCharts
|
|||||||
if (dataIndex >= 0 && dataIndex < m_Data.Count)
|
if (dataIndex >= 0 && dataIndex < m_Data.Count)
|
||||||
{
|
{
|
||||||
var data = m_Data[dataIndex];
|
var data = m_Data[dataIndex];
|
||||||
data.iconColor = color;
|
data.iconStyle.color = color;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
105
Assets/XCharts/Runtime/Component/Sub/IconStyle.cs
Normal file
105
Assets/XCharts/Runtime/Component/Sub/IconStyle.cs
Normal file
@@ -0,0 +1,105 @@
|
|||||||
|
/******************************************/
|
||||||
|
/* */
|
||||||
|
/* Copyright (c) 2018 monitor1394 */
|
||||||
|
/* https://github.com/monitor1394 */
|
||||||
|
/* */
|
||||||
|
/******************************************/
|
||||||
|
|
||||||
|
using UnityEngine;
|
||||||
|
using UnityEngine.UI;
|
||||||
|
|
||||||
|
namespace XCharts
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 系列数据项的图标
|
||||||
|
/// </summary>
|
||||||
|
[System.Serializable]
|
||||||
|
public class IconStyle : SubComponent
|
||||||
|
{
|
||||||
|
public enum Layer
|
||||||
|
{
|
||||||
|
UnderLabel,
|
||||||
|
AboveLabel
|
||||||
|
}
|
||||||
|
[SerializeField] private bool m_Show;
|
||||||
|
[SerializeField] private Layer m_Layer;
|
||||||
|
[SerializeField] private Sprite m_Sprite;
|
||||||
|
[SerializeField] private Color m_Color = Color.white;
|
||||||
|
[SerializeField] private float m_Width = 40;
|
||||||
|
[SerializeField] private float m_Height = 40;
|
||||||
|
[SerializeField] private Vector3 m_Offset;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Whether the data icon is show.
|
||||||
|
/// 是否显示图标。
|
||||||
|
/// </summary>
|
||||||
|
public bool show { get { return m_Show; } set { m_Show = value; UpdateIcon(); } }
|
||||||
|
/// <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; } }
|
||||||
|
|
||||||
|
public Image image { get; private set; }
|
||||||
|
public RectTransform rect { get; private set; }
|
||||||
|
|
||||||
|
public void SetImage(Image image)
|
||||||
|
{
|
||||||
|
this.image = image;
|
||||||
|
if (image)
|
||||||
|
{
|
||||||
|
rect = image.GetComponent<RectTransform>();
|
||||||
|
if (m_Layer == Layer.UnderLabel)
|
||||||
|
rect.SetSiblingIndex(0);
|
||||||
|
else
|
||||||
|
rect.SetSiblingIndex(image.transform.childCount - 1);
|
||||||
|
UpdateIcon();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void SetActive(bool flag)
|
||||||
|
{
|
||||||
|
if (image)
|
||||||
|
{
|
||||||
|
ChartHelper.SetActive(image.gameObject, flag);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void UpdateIcon()
|
||||||
|
{
|
||||||
|
if (image == null) return;
|
||||||
|
if (show)
|
||||||
|
{
|
||||||
|
ChartHelper.SetActive(image.gameObject, true);
|
||||||
|
image.sprite = m_Sprite;
|
||||||
|
image.color = m_Color;
|
||||||
|
rect.sizeDelta = new Vector2(m_Width, m_Height);
|
||||||
|
image.transform.localPosition = m_Offset;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ChartHelper.SetActive(image.gameObject, false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
11
Assets/XCharts/Runtime/Component/Sub/IconStyle.cs.meta
Normal file
11
Assets/XCharts/Runtime/Component/Sub/IconStyle.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 82c4d360f7b5b4ee7845e9bbe611c8a3
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@@ -9,6 +9,7 @@ using System.Linq;
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using UnityEngine.UI;
|
using UnityEngine.UI;
|
||||||
|
using System;
|
||||||
|
|
||||||
namespace XCharts
|
namespace XCharts
|
||||||
{
|
{
|
||||||
@@ -22,13 +23,7 @@ namespace XCharts
|
|||||||
[SerializeField] private string m_Name;
|
[SerializeField] private string m_Name;
|
||||||
[SerializeField] private bool m_Selected;
|
[SerializeField] private bool m_Selected;
|
||||||
[SerializeField] private float m_Radius;
|
[SerializeField] private float m_Radius;
|
||||||
[SerializeField] private bool m_ShowIcon;
|
[SerializeField] private IconStyle m_IconStyle = new IconStyle();
|
||||||
[SerializeField] private Sprite m_IconImage;
|
|
||||||
[SerializeField] private Color m_IconColor = Color.white;
|
|
||||||
[SerializeField] private float m_IconWidth = 40;
|
|
||||||
[SerializeField] private float m_IconHeight = 40;
|
|
||||||
[SerializeField] private Vector3 m_IconOffset;
|
|
||||||
|
|
||||||
[SerializeField] private List<float> m_Data = new List<float>();
|
[SerializeField] private List<float> m_Data = new List<float>();
|
||||||
|
|
||||||
private bool m_Show = true;
|
private bool m_Show = true;
|
||||||
@@ -58,32 +53,10 @@ namespace XCharts
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public bool selected { get { return m_Selected; } set { m_Selected = value; } }
|
public bool selected { get { return m_Selected; } set { m_Selected = value; } }
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Whether the data icon is show.
|
/// the icon of data.
|
||||||
/// 是否显示图标。
|
/// 数据项图标样式。
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public bool showIcon { get { return m_ShowIcon; } set { m_ShowIcon = value; } }
|
public IconStyle iconStyle { get { return m_IconStyle; } set { m_IconStyle = value; } }
|
||||||
/// <summary>
|
|
||||||
/// The image of icon.
|
|
||||||
/// 图标的图片。
|
|
||||||
/// </summary>
|
|
||||||
public Sprite iconImage { get { return m_IconImage; } set { m_IconImage = value; } }
|
|
||||||
/// <summary>
|
|
||||||
/// 图标颜色。
|
|
||||||
/// </summary>
|
|
||||||
public Color iconColor { get { return m_IconColor; } set { m_IconColor = value; } }
|
|
||||||
/// <summary>
|
|
||||||
/// 图标宽。
|
|
||||||
/// </summary>
|
|
||||||
public float iconWidth { get { return m_IconWidth; } set { m_IconWidth = value; } }
|
|
||||||
/// <summary>
|
|
||||||
/// 图标高。
|
|
||||||
/// </summary>
|
|
||||||
public float iconHeight { get { return m_IconHeight; } set { m_IconHeight = value; } }
|
|
||||||
/// <summary>
|
|
||||||
/// 图标偏移。
|
|
||||||
/// </summary>
|
|
||||||
public Vector3 iconOffset { get { return m_IconOffset; } set { m_IconOffset = value; } }
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// An arbitrary dimension data list of data item.
|
/// An arbitrary dimension data list of data item.
|
||||||
/// 可指定任意维数的数值列表。
|
/// 可指定任意维数的数值列表。
|
||||||
@@ -124,8 +97,7 @@ namespace XCharts
|
|||||||
/// 最小值。
|
/// 最小值。
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public float min { get { return m_Data.Min(); } }
|
public float min { get { return m_Data.Min(); } }
|
||||||
public Image icon { get; private set; }
|
|
||||||
public RectTransform iconRect { get; private set; }
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 关联的gameObject
|
/// 关联的gameObject
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -238,28 +210,19 @@ namespace XCharts
|
|||||||
if (labelRect) labelRect.localPosition = position;
|
if (labelRect) labelRect.localPosition = position;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetIconObj(GameObject iconObj)
|
[Obsolete("Use SerieData.SetIconImage() instead.", true)]
|
||||||
|
public void SetIconObj(GameObject iconObj) { }
|
||||||
|
|
||||||
|
public void SetIconImage(Image image)
|
||||||
{
|
{
|
||||||
icon = iconObj.GetComponent<Image>();
|
if (iconStyle == null) return;
|
||||||
iconRect = iconObj.GetComponent<RectTransform>();
|
iconStyle.SetImage(image);
|
||||||
UpdateIcon();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void UpdateIcon()
|
public void UpdateIcon()
|
||||||
{
|
{
|
||||||
if (icon == null) return;
|
if (iconStyle == null) return;
|
||||||
if (m_ShowIcon)
|
iconStyle.UpdateIcon();
|
||||||
{
|
|
||||||
ChartHelper.SetActive(icon.gameObject, true);
|
|
||||||
icon.sprite = m_IconImage;
|
|
||||||
icon.color = m_IconColor;
|
|
||||||
iconRect.sizeDelta = new Vector2(m_IconWidth, m_IconHeight);
|
|
||||||
icon.transform.localPosition = m_IconOffset;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
ChartHelper.SetActive(icon.gameObject, false);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -311,9 +311,8 @@ namespace XCharts
|
|||||||
(Color)m_ThemeInfo.GetColor(i);
|
(Color)m_ThemeInfo.GetColor(i);
|
||||||
}
|
}
|
||||||
var labelObj = SerieLabelPool.Get(textName, labelObject.transform, serie.label, m_ThemeInfo.font, color, serieData);
|
var labelObj = SerieLabelPool.Get(textName, labelObject.transform, serie.label, m_ThemeInfo.font, color, serieData);
|
||||||
var iconObj = labelObj.transform.Find("Icon").gameObject;
|
var iconImage = labelObj.transform.Find("Icon").GetComponent<Image>();
|
||||||
serieData.SetIconObj(iconObj);
|
serieData.SetIconImage(iconImage);
|
||||||
iconObj.GetComponent<RectTransform>().SetSiblingIndex(0);
|
|
||||||
|
|
||||||
var isAutoSize = serie.label.backgroundWidth == 0 || serie.label.backgroundHeight == 0;
|
var isAutoSize = serie.label.backgroundWidth == 0 || serie.label.backgroundHeight == 0;
|
||||||
serieData.InitLabel(labelObj, isAutoSize, serie.label.paddingLeftRight, serie.label.paddingTopBottom);
|
serieData.InitLabel(labelObj, isAutoSize, serie.label.paddingLeftRight, serie.label.paddingTopBottom);
|
||||||
|
|||||||
@@ -1325,7 +1325,7 @@ namespace XCharts
|
|||||||
for (int j = 0; j < serie.data.Count; j++)
|
for (int j = 0; j < serie.data.Count; j++)
|
||||||
{
|
{
|
||||||
var serieData = serie.data[j];
|
var serieData = serie.data[j];
|
||||||
if (serie.label.show || serieData.showIcon)
|
if (serie.label.show || serieData.iconStyle.show)
|
||||||
{
|
{
|
||||||
var pos = serie.dataPoints[j];
|
var pos = serie.dataPoints[j];
|
||||||
var value = serieData.data[1];
|
var value = serieData.data[1];
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ namespace XCharts
|
|||||||
element = ChartHelper.AddSerieLabel(name, parent, font,
|
element = ChartHelper.AddSerieLabel(name, parent, font,
|
||||||
color, label.backgroundColor, label.fontSize, label.fontStyle, label.rotate,
|
color, label.backgroundColor, label.fontSize, label.fontStyle, label.rotate,
|
||||||
label.backgroundWidth, label.backgroundHeight);
|
label.backgroundWidth, label.backgroundHeight);
|
||||||
ChartHelper.AddIcon("Icon", element.transform, serieData.iconWidth, serieData.iconHeight);
|
ChartHelper.AddIcon("Icon", element.transform, serieData.iconStyle.width, serieData.iconStyle.height);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -337,7 +337,7 @@ namespace XCharts
|
|||||||
var currAngle = serieData.runtimePieHalfAngle;
|
var currAngle = serieData.runtimePieHalfAngle;
|
||||||
var isHighlight = (serieData.highlighted && serie.emphasis.label.show);
|
var isHighlight = (serieData.highlighted && serie.emphasis.label.show);
|
||||||
var showLabel = ((serie.label.show || isHighlight) && serieData.canShowLabel);
|
var showLabel = ((serie.label.show || isHighlight) && serieData.canShowLabel);
|
||||||
if (showLabel || serieData.showIcon)
|
if (showLabel || serieData.iconStyle.show)
|
||||||
{
|
{
|
||||||
serieData.SetLabelActive(showLabel);
|
serieData.SetLabelActive(showLabel);
|
||||||
float rotate = 0;
|
float rotate = 0;
|
||||||
|
|||||||
Reference in New Issue
Block a user