mirror of
https://github.com/XCharts-Team/XCharts.git
synced 2026-05-23 01:10:08 +00:00
整理和重构代码
This commit is contained in:
@@ -539,7 +539,7 @@ namespace XCharts.Editor
|
||||
return HEADER_HEIGHT;
|
||||
}
|
||||
|
||||
internal static bool DrawHeader(string title, bool state, bool drawBackground, SerializedProperty activeField,
|
||||
public static bool DrawHeader(string title, bool state, bool drawBackground, SerializedProperty activeField,
|
||||
Action<Rect> drawCallback, params HeaderMenuInfo[] menus)
|
||||
{
|
||||
var rect = GUILayoutUtility.GetRect(1f, HEADER_HEIGHT);
|
||||
|
||||
@@ -1,8 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b92d575a960f54e9a9417cca092d1e11
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,51 +0,0 @@
|
||||
using UnityEditor;
|
||||
using XCharts.Runtime;
|
||||
|
||||
namespace XCharts.Editor
|
||||
{
|
||||
[CustomEditor(typeof(ProgressBar), false)]
|
||||
public class ProgressBarEditor : UnityEditor.Editor
|
||||
{
|
||||
|
||||
[MenuItem("XCharts/ProgressBar", priority = 200)]
|
||||
[MenuItem("GameObject/XCharts/ProgressBar", priority = 200)]
|
||||
public static void AddPyramidChart()
|
||||
{
|
||||
XChartsEditor.AddChart<ProgressBar>("ProgressBar");
|
||||
}
|
||||
|
||||
protected SerializedProperty m_Script;
|
||||
protected SerializedProperty m_Value;
|
||||
protected SerializedProperty m_BackgroundColor;
|
||||
protected SerializedProperty m_StartColor;
|
||||
protected SerializedProperty m_EndColor;
|
||||
protected SerializedProperty m_CornerRadius;
|
||||
|
||||
protected virtual void OnEnable()
|
||||
{
|
||||
m_Script = serializedObject.FindProperty("m_Script");
|
||||
m_Value = serializedObject.FindProperty("m_Value");
|
||||
m_BackgroundColor = serializedObject.FindProperty("m_BackgroundColor");
|
||||
m_StartColor = serializedObject.FindProperty("m_StartColor");
|
||||
m_EndColor = serializedObject.FindProperty("m_EndColor");
|
||||
m_CornerRadius = serializedObject.FindProperty("m_CornerRadius");
|
||||
}
|
||||
|
||||
public override void OnInspectorGUI()
|
||||
{
|
||||
serializedObject.Update();
|
||||
OnStartInspectorGUI();
|
||||
serializedObject.ApplyModifiedProperties();
|
||||
}
|
||||
|
||||
protected virtual void OnStartInspectorGUI()
|
||||
{
|
||||
EditorGUILayout.PropertyField(m_Script);
|
||||
EditorGUILayout.PropertyField(m_BackgroundColor);
|
||||
EditorGUILayout.PropertyField(m_StartColor);
|
||||
EditorGUILayout.PropertyField(m_EndColor);
|
||||
EditorGUILayout.PropertyField(m_Value);
|
||||
EditorGUILayout.PropertyField(m_CornerRadius);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 17cd5e3604edc43e5b7b6bfc3c71857b
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -56,24 +56,30 @@ namespace XCharts.Editor
|
||||
}
|
||||
|
||||
public static T AddChart<T>(string chartName) where T : BaseChart
|
||||
{
|
||||
XCThemeMgr.CheckReloadTheme();
|
||||
return AddGraph<T>(chartName);
|
||||
}
|
||||
|
||||
public static T AddGraph<T>(string graphName) where T : BaseGraph
|
||||
{
|
||||
var parent = GetParent();
|
||||
if (parent == null) return null;
|
||||
XCThemeMgr.CheckReloadTheme();
|
||||
var chart = new GameObject();
|
||||
chart.name = GetName(parent, chartName);
|
||||
chart.layer = LayerMask.NameToLayer("UI");
|
||||
var t = chart.AddComponent<T>();
|
||||
chart.transform.SetParent(parent);
|
||||
chart.transform.localScale = Vector3.one;
|
||||
chart.transform.localPosition = Vector3.zero;
|
||||
chart.transform.localRotation = Quaternion.Euler(0, 0, 0);
|
||||
var rect = chart.GetComponent<RectTransform>();
|
||||
var obj = new GameObject();
|
||||
obj.name = GetName(parent, graphName);
|
||||
obj.layer = LayerMask.NameToLayer("UI");
|
||||
var t = obj.AddComponent<T>();
|
||||
obj.transform.SetParent(parent);
|
||||
obj.transform.localScale = Vector3.one;
|
||||
obj.transform.localPosition = Vector3.zero;
|
||||
obj.transform.localRotation = Quaternion.Euler(0, 0, 0);
|
||||
var rect = obj.GetComponent<RectTransform>();
|
||||
rect.anchorMin = new Vector2(0.5f, 0.5f);
|
||||
rect.anchorMax = new Vector2(0.5f, 0.5f);
|
||||
rect.pivot = new Vector2(0.5f, 0.5f);
|
||||
Selection.activeGameObject = chart;
|
||||
EditorUtility.SetDirty(chart);
|
||||
Selection.activeGameObject = obj;
|
||||
EditorUtility.SetDirty(obj);
|
||||
return t;
|
||||
}
|
||||
|
||||
|
||||
@@ -6,8 +6,7 @@ namespace XCharts.Runtime
|
||||
{
|
||||
/// <summary>
|
||||
/// Background component.
|
||||
/// |
|
||||
/// 背景组件。
|
||||
/// |背景组件。
|
||||
/// </summary>
|
||||
[Serializable]
|
||||
[DisallowMultipleComponent]
|
||||
@@ -27,7 +26,7 @@ namespace XCharts.Runtime
|
||||
public bool show
|
||||
{
|
||||
get { return m_Show; }
|
||||
internal set { if (PropertyUtil.SetStruct(ref m_Show, value)) SetComponentDirty(); }
|
||||
set { if (PropertyUtil.SetStruct(ref m_Show, value)) SetComponentDirty(); }
|
||||
}
|
||||
/// <summary>
|
||||
/// the image of background.
|
||||
|
||||
@@ -18,6 +18,7 @@ namespace XCharts.Runtime
|
||||
[SerializeField] protected string m_ChartName;
|
||||
[SerializeField] protected ThemeStyle m_Theme = new ThemeStyle();
|
||||
[SerializeField] protected Settings m_Settings;
|
||||
[SerializeField] protected DebugInfo m_DebugInfo = new DebugInfo();
|
||||
|
||||
#pragma warning disable 0414
|
||||
[SerializeField][ListForComponent(typeof(AngleAxis))] private List<AngleAxis> m_AngleAxes = new List<AngleAxis>();
|
||||
@@ -67,6 +68,8 @@ namespace XCharts.Runtime
|
||||
public List<MainComponent> components { get { return m_Components; } }
|
||||
|
||||
public List<Serie> series { get { return m_Series; } }
|
||||
public DebugInfo debug { get { return m_DebugInfo; } }
|
||||
public override HideFlags chartHideFlags { get { return m_DebugInfo.showAllChartObject ? HideFlags.None : HideFlags.HideInHierarchy; } }
|
||||
|
||||
protected float m_ChartWidth;
|
||||
protected float m_ChartHeight;
|
||||
|
||||
@@ -36,6 +36,11 @@ namespace XCharts.Runtime
|
||||
/// </summary>
|
||||
public Vector3 graphPosition { get { return m_GraphPosition; } }
|
||||
public Rect graphRect { get { return m_GraphRect; } }
|
||||
public Vector2 graphSizeDelta { get { return m_GraphSizeDelta; } }
|
||||
public Vector2 graphPivot { get { return m_GraphPivot; } }
|
||||
public Vector2 graphMinAnchor { get { return m_GraphMinAnchor; } }
|
||||
public Vector2 graphMaxAnchor { get { return m_GraphMaxAnchor; } }
|
||||
public Vector2 graphAnchoredPosition { get { return m_GraphAnchoredPosition; } }
|
||||
/// <summary>
|
||||
/// The postion of pointer.
|
||||
/// |鼠标位置。
|
||||
|
||||
@@ -10,9 +10,7 @@ namespace XCharts.Runtime
|
||||
IPointerEnterHandler, IPointerExitHandler, IBeginDragHandler, IPointerClickHandler,
|
||||
IDragHandler, IEndDragHandler, IScrollHandler
|
||||
{
|
||||
|
||||
[SerializeField] protected bool m_EnableTextMeshPro = false;
|
||||
[SerializeField] protected DebugInfo m_DebugInfo = new DebugInfo();
|
||||
|
||||
protected Painter m_Painter;
|
||||
protected int m_SiblingIndex;
|
||||
@@ -45,11 +43,8 @@ namespace XCharts.Runtime
|
||||
protected Action<PointerEventData, BaseGraph> m_OnEndDrag;
|
||||
protected Action<PointerEventData, BaseGraph> m_OnScroll;
|
||||
|
||||
protected Vector2 graphAnchorMax { get { return m_GraphMinAnchor; } }
|
||||
protected Vector2 graphAnchorMin { get { return m_GraphMaxAnchor; } }
|
||||
protected Vector2 graphPivot { get { return m_GraphPivot; } }
|
||||
public HideFlags chartHideFlags { get { return m_DebugInfo.showAllChartObject ? HideFlags.None : HideFlags.HideInHierarchy; } }
|
||||
public DebugInfo debug { get { return m_DebugInfo; } }
|
||||
public virtual HideFlags chartHideFlags { get { return HideFlags.None; } }
|
||||
|
||||
private ScrollRect m_ScrollRect;
|
||||
|
||||
public Painter painter { get { return m_Painter; } }
|
||||
@@ -128,8 +123,7 @@ namespace XCharts.Runtime
|
||||
}
|
||||
|
||||
#if UNITY_EDITOR
|
||||
protected override void Reset()
|
||||
{ }
|
||||
protected override void Reset() { }
|
||||
|
||||
protected override void OnValidate()
|
||||
{
|
||||
@@ -253,16 +247,14 @@ namespace XCharts.Runtime
|
||||
m_RefreshChart = true;
|
||||
}
|
||||
|
||||
protected virtual void OnLocalPositionChanged()
|
||||
{ }
|
||||
protected virtual void OnLocalPositionChanged() { }
|
||||
|
||||
protected virtual void OnDrawPainterBase(VertexHelper vh, Painter painter)
|
||||
{
|
||||
DrawPainterBase(vh);
|
||||
}
|
||||
|
||||
protected virtual void DrawPainterBase(VertexHelper vh)
|
||||
{ }
|
||||
protected virtual void DrawPainterBase(VertexHelper vh) { }
|
||||
|
||||
public virtual void OnPointerClick(PointerEventData eventData)
|
||||
{
|
||||
|
||||
@@ -1,51 +0,0 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using XUGL;
|
||||
|
||||
namespace XCharts.Runtime
|
||||
{
|
||||
[ExecuteInEditMode]
|
||||
[RequireComponent(typeof(RectTransform))]
|
||||
[DisallowMultipleComponent]
|
||||
public class ProgressBar : BaseChart
|
||||
{
|
||||
[SerializeField][Range(0f, 1f)] private float m_Value = 0.5f;
|
||||
[SerializeField] private Color m_BackgroundColor = new Color32(255, 233, 233, 255);
|
||||
[SerializeField] private Color m_StartColor = Color.blue;
|
||||
[SerializeField] private Color m_EndColor = Color.red;
|
||||
[SerializeField] private float[] m_CornerRadius = new float[] { 0, 0, 0, 0 };
|
||||
|
||||
public float value { get { return m_Value; } set { m_Value = value; SetVerticesDirty(); } }
|
||||
public Color32 backgroundColor { get { return m_BackgroundColor; } set { m_BackgroundColor = value; SetVerticesDirty(); } }
|
||||
public Color32 startColor { get { return m_StartColor; } set { m_StartColor = value; SetVerticesDirty(); } }
|
||||
public Color32 endColor { get { return m_EndColor; } set { m_EndColor = value; SetVerticesDirty(); } }
|
||||
public float[] cornerRadius { get { return m_CornerRadius; } set { m_CornerRadius = value; SetVerticesDirty(); } }
|
||||
|
||||
#if UNITY_EDITOR
|
||||
protected override void Reset()
|
||||
{
|
||||
base.Reset();
|
||||
var title = GetOrAddChartComponent<Title>();
|
||||
title.text = "ProgressBar";
|
||||
title.show = false;
|
||||
SetSize(580, 4);
|
||||
RemoveData();
|
||||
}
|
||||
#endif
|
||||
|
||||
protected override void OnDrawPainterBase(VertexHelper vh, Painter painter)
|
||||
{
|
||||
vh.Clear();
|
||||
var centerPos = new Vector3(chartPosition.x + m_ChartWidth / 2, chartPosition.y + m_ChartHeight / 2);
|
||||
UGL.DrawRoundRectangle(vh, centerPos, m_ChartWidth, m_ChartHeight, m_BackgroundColor, m_BackgroundColor,
|
||||
0, m_CornerRadius, true);
|
||||
|
||||
var valueWidth = m_Value * m_ChartWidth;
|
||||
var valuePos = new Vector3(chartPosition.x + valueWidth / 2, centerPos.y);
|
||||
var endColor = Color.Lerp(m_StartColor, m_EndColor, m_Value);
|
||||
UGL.DrawRoundRectangle(vh, valuePos, valueWidth, m_ChartHeight, m_StartColor, endColor, 0,
|
||||
m_CornerRadius, true);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: cd18af5634e604a3c97fb1ff0fc5d682
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user