mirror of
https://github.com/XCharts-Team/XCharts.git
synced 2026-05-30 13:28:47 +00:00
优化Editor下编辑性能
This commit is contained in:
@@ -53,14 +53,18 @@ namespace XCharts.Editor
|
||||
}
|
||||
}
|
||||
|
||||
private void PropertyFieldData()
|
||||
{
|
||||
m_DataFoldout = ChartEditorHelper.DrawHeader("Data", m_DataFoldout, false, null, null,
|
||||
new HeaderMenuInfo("Import ECharts Data", () =>
|
||||
private HeaderMenuInfo headMenuInfo = new HeaderMenuInfo("Import ECharts Data", null);
|
||||
|
||||
private void HeadMenuInfoCallback()
|
||||
{
|
||||
PraseExternalDataEditor.UpdateData(chart, serie, null, false);
|
||||
PraseExternalDataEditor.ShowWindow();
|
||||
}));
|
||||
}
|
||||
|
||||
private void PropertyFieldData()
|
||||
{
|
||||
headMenuInfo.action = HeadMenuInfoCallback;
|
||||
m_DataFoldout = ChartEditorHelper.DrawHeader("Data", m_DataFoldout, false, null, null, headMenuInfo);
|
||||
if (!m_DataFoldout) return;
|
||||
EditorGUI.indentLevel++;
|
||||
var m_Datas = FindProperty("m_Data");
|
||||
@@ -103,14 +107,18 @@ namespace XCharts.Editor
|
||||
EditorGUI.indentLevel--;
|
||||
}
|
||||
|
||||
private HeaderMenuInfo linkHeadMenuInfo = new HeaderMenuInfo("Import ECharts Link", null);
|
||||
|
||||
private void LinkHeadMenuInfoCallback()
|
||||
{
|
||||
PraseExternalDataEditor.UpdateData(chart, serie, null, false);
|
||||
PraseExternalDataEditor.ShowWindow();
|
||||
}
|
||||
|
||||
protected void PropertyFieldLinks()
|
||||
{
|
||||
m_LinksFoldout = ChartEditorHelper.DrawHeader("Links", m_LinksFoldout, false, null, null,
|
||||
new HeaderMenuInfo("Import ECharts Link", () =>
|
||||
{
|
||||
//PraseExternalDataEditor.UpdateData(chart, serie, null, true);
|
||||
//PraseExternalDataEditor.ShowWindow();
|
||||
}));
|
||||
linkHeadMenuInfo.action = LinkHeadMenuInfoCallback;
|
||||
m_LinksFoldout = ChartEditorHelper.DrawHeader("Links", m_LinksFoldout, false, null, null, linkHeadMenuInfo);
|
||||
if (!m_LinksFoldout) return;
|
||||
EditorGUI.indentLevel++;
|
||||
var m_Links = FindProperty("m_Links");
|
||||
@@ -154,20 +162,14 @@ namespace XCharts.Editor
|
||||
}
|
||||
}
|
||||
|
||||
private void DrawSerieData(int dimension, SerializedProperty m_Datas, int index, bool showName)
|
||||
{
|
||||
bool flag;
|
||||
if (!m_DataElementFoldout.TryGetValue(index, out flag))
|
||||
{
|
||||
flag = false;
|
||||
m_DataElementFoldout[index] = false;
|
||||
}
|
||||
var fieldCount = dimension + (showName ? 1 : 0);
|
||||
var serieData = m_Datas.GetArrayElementAtIndex(index);
|
||||
var dataIndex = serieData.FindPropertyRelative("m_Index").intValue;
|
||||
m_DataElementFoldout[index] = ChartEditorHelper.DrawHeader("SerieData " + dataIndex, flag, false, null,
|
||||
delegate (Rect drawRect)
|
||||
private void DrawSerieDataHeader(Rect drawRect,HeaderCallbackContext context)
|
||||
{
|
||||
var serieData = context.serieData;
|
||||
var fieldCount = context.fieldCount;
|
||||
var showName = context.showName;
|
||||
var index = context.index;
|
||||
var dimension = context.dimension;
|
||||
|
||||
//drawRect.width -= 2f;
|
||||
var maxX = drawRect.xMax;
|
||||
var currentWidth = drawRect.width;
|
||||
@@ -175,7 +177,6 @@ namespace XCharts.Editor
|
||||
var lastWid = drawRect.width;
|
||||
var lastFieldWid = EditorGUIUtility.fieldWidth;
|
||||
var lastLabelWid = EditorGUIUtility.labelWidth;
|
||||
//var serieData = m_Datas.GetArrayElementAtIndex(index);
|
||||
var sereName = serieData.FindPropertyRelative("m_Name");
|
||||
var data = serieData.FindPropertyRelative("m_Data");
|
||||
#if UNITY_2019_3_OR_NEWER
|
||||
@@ -228,7 +229,27 @@ namespace XCharts.Editor
|
||||
EditorGUIUtility.fieldWidth = lastFieldWid;
|
||||
EditorGUIUtility.labelWidth = lastLabelWid;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void DrawSerieData(int dimension, SerializedProperty m_Datas, int index, bool showName)
|
||||
{
|
||||
bool flag;
|
||||
if (!m_DataElementFoldout.TryGetValue(index, out flag))
|
||||
{
|
||||
flag = false;
|
||||
m_DataElementFoldout[index] = false;
|
||||
}
|
||||
var fieldCount = dimension + (showName ? 1 : 0);
|
||||
var serieData = m_Datas.GetArrayElementAtIndex(index);
|
||||
var dataIndex = serieData.FindPropertyRelative("m_Index").intValue;
|
||||
var callbackContext = new HeaderCallbackContext(){
|
||||
serieData = serieData,
|
||||
fieldCount = fieldCount,
|
||||
showName = showName,
|
||||
index = index,
|
||||
dimension = dimension
|
||||
};
|
||||
m_DataElementFoldout[index] = ChartEditorHelper.DrawSerieDataHeader("SerieData " + dataIndex, flag, false, null, callbackContext, DrawSerieDataHeader);
|
||||
if (m_DataElementFoldout[index])
|
||||
{
|
||||
if (!(serie is ISimplifiedSerie))
|
||||
|
||||
@@ -6,6 +6,15 @@ using XCharts.Runtime;
|
||||
|
||||
namespace XCharts.Editor
|
||||
{
|
||||
public class HeaderCallbackContext
|
||||
{
|
||||
public int fieldCount = 0;
|
||||
public SerializedProperty serieData;
|
||||
public bool showName;
|
||||
public int index;
|
||||
public int dimension;
|
||||
}
|
||||
|
||||
public class HeaderMenuInfo
|
||||
{
|
||||
public string name;
|
||||
@@ -586,6 +595,31 @@ namespace XCharts.Editor
|
||||
return state;
|
||||
}
|
||||
|
||||
public static bool DrawSerieDataHeader(string title, bool state, bool drawBackground, SerializedProperty activeField,
|
||||
HeaderCallbackContext context, Action<Rect, HeaderCallbackContext> drawCallback, params HeaderMenuInfo[] menus)
|
||||
{
|
||||
var rect = GUILayoutUtility.GetRect(1f, HEADER_HEIGHT);
|
||||
var labelRect = DrawHeaderInternal(rect, title, ref state, drawBackground, activeField);
|
||||
DrawMenu(rect, menus);
|
||||
if (drawCallback != null)
|
||||
{
|
||||
drawCallback(rect, context);
|
||||
}
|
||||
var e = Event.current;
|
||||
if (e.type == EventType.MouseDown)
|
||||
{
|
||||
if (labelRect.Contains(e.mousePosition))
|
||||
{
|
||||
if (e.button == 0)
|
||||
{
|
||||
state = !state;
|
||||
e.Use();
|
||||
}
|
||||
}
|
||||
}
|
||||
return state;
|
||||
}
|
||||
|
||||
internal static bool DrawHeader(string title, bool state, bool drawBackground, SerializedProperty activeField,
|
||||
Action<Rect> drawCallback, List<HeaderMenuInfo> menus)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user