mirror of
https://github.com/XCharts-Team/XCharts.git
synced 2026-05-31 13:58:48 +00:00
优化Editor下编辑性能
This commit is contained in:
@@ -53,14 +53,18 @@ namespace XCharts.Editor
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void PropertyFieldData()
|
private HeaderMenuInfo headMenuInfo = new HeaderMenuInfo("Import ECharts Data", null);
|
||||||
{
|
|
||||||
m_DataFoldout = ChartEditorHelper.DrawHeader("Data", m_DataFoldout, false, null, null,
|
private void HeadMenuInfoCallback()
|
||||||
new HeaderMenuInfo("Import ECharts Data", () =>
|
|
||||||
{
|
{
|
||||||
PraseExternalDataEditor.UpdateData(chart, serie, null, false);
|
PraseExternalDataEditor.UpdateData(chart, serie, null, false);
|
||||||
PraseExternalDataEditor.ShowWindow();
|
PraseExternalDataEditor.ShowWindow();
|
||||||
}));
|
}
|
||||||
|
|
||||||
|
private void PropertyFieldData()
|
||||||
|
{
|
||||||
|
headMenuInfo.action = HeadMenuInfoCallback;
|
||||||
|
m_DataFoldout = ChartEditorHelper.DrawHeader("Data", m_DataFoldout, false, null, null, headMenuInfo);
|
||||||
if (!m_DataFoldout) return;
|
if (!m_DataFoldout) return;
|
||||||
EditorGUI.indentLevel++;
|
EditorGUI.indentLevel++;
|
||||||
var m_Datas = FindProperty("m_Data");
|
var m_Datas = FindProperty("m_Data");
|
||||||
@@ -103,14 +107,18 @@ namespace XCharts.Editor
|
|||||||
EditorGUI.indentLevel--;
|
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()
|
protected void PropertyFieldLinks()
|
||||||
{
|
{
|
||||||
m_LinksFoldout = ChartEditorHelper.DrawHeader("Links", m_LinksFoldout, false, null, null,
|
linkHeadMenuInfo.action = LinkHeadMenuInfoCallback;
|
||||||
new HeaderMenuInfo("Import ECharts Link", () =>
|
m_LinksFoldout = ChartEditorHelper.DrawHeader("Links", m_LinksFoldout, false, null, null, linkHeadMenuInfo);
|
||||||
{
|
|
||||||
//PraseExternalDataEditor.UpdateData(chart, serie, null, true);
|
|
||||||
//PraseExternalDataEditor.ShowWindow();
|
|
||||||
}));
|
|
||||||
if (!m_LinksFoldout) return;
|
if (!m_LinksFoldout) return;
|
||||||
EditorGUI.indentLevel++;
|
EditorGUI.indentLevel++;
|
||||||
var m_Links = FindProperty("m_Links");
|
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)
|
private void DrawSerieDataHeader(Rect drawRect,HeaderCallbackContext context)
|
||||||
{
|
|
||||||
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)
|
|
||||||
{
|
{
|
||||||
|
var serieData = context.serieData;
|
||||||
|
var fieldCount = context.fieldCount;
|
||||||
|
var showName = context.showName;
|
||||||
|
var index = context.index;
|
||||||
|
var dimension = context.dimension;
|
||||||
|
|
||||||
//drawRect.width -= 2f;
|
//drawRect.width -= 2f;
|
||||||
var maxX = drawRect.xMax;
|
var maxX = drawRect.xMax;
|
||||||
var currentWidth = drawRect.width;
|
var currentWidth = drawRect.width;
|
||||||
@@ -175,7 +177,6 @@ namespace XCharts.Editor
|
|||||||
var lastWid = drawRect.width;
|
var lastWid = drawRect.width;
|
||||||
var lastFieldWid = EditorGUIUtility.fieldWidth;
|
var lastFieldWid = EditorGUIUtility.fieldWidth;
|
||||||
var lastLabelWid = EditorGUIUtility.labelWidth;
|
var lastLabelWid = EditorGUIUtility.labelWidth;
|
||||||
//var serieData = m_Datas.GetArrayElementAtIndex(index);
|
|
||||||
var sereName = serieData.FindPropertyRelative("m_Name");
|
var sereName = serieData.FindPropertyRelative("m_Name");
|
||||||
var data = serieData.FindPropertyRelative("m_Data");
|
var data = serieData.FindPropertyRelative("m_Data");
|
||||||
#if UNITY_2019_3_OR_NEWER
|
#if UNITY_2019_3_OR_NEWER
|
||||||
@@ -228,7 +229,27 @@ namespace XCharts.Editor
|
|||||||
EditorGUIUtility.fieldWidth = lastFieldWid;
|
EditorGUIUtility.fieldWidth = lastFieldWid;
|
||||||
EditorGUIUtility.labelWidth = lastLabelWid;
|
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 (m_DataElementFoldout[index])
|
||||||
{
|
{
|
||||||
if (!(serie is ISimplifiedSerie))
|
if (!(serie is ISimplifiedSerie))
|
||||||
|
|||||||
@@ -6,6 +6,15 @@ using XCharts.Runtime;
|
|||||||
|
|
||||||
namespace XCharts.Editor
|
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 class HeaderMenuInfo
|
||||||
{
|
{
|
||||||
public string name;
|
public string name;
|
||||||
@@ -586,6 +595,31 @@ namespace XCharts.Editor
|
|||||||
return state;
|
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,
|
internal static bool DrawHeader(string title, bool state, bool drawBackground, SerializedProperty activeField,
|
||||||
Action<Rect> drawCallback, List<HeaderMenuInfo> menus)
|
Action<Rect> drawCallback, List<HeaderMenuInfo> menus)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user