增加MainComponent的order设置执行优先级

This commit is contained in:
monitor1394
2024-01-11 22:34:18 +08:00
parent 318bdcb1f2
commit 29e9593179
3 changed files with 8 additions and 2 deletions

View File

@@ -7,17 +7,20 @@ namespace XCharts.Runtime
{ {
public readonly Type handler; public readonly Type handler;
public readonly bool allowMultiple = true; public readonly bool allowMultiple = true;
public readonly int order = 3;
public ComponentHandlerAttribute(Type handler) public ComponentHandlerAttribute(Type handler, int order = 3)
{ {
this.handler = handler; this.handler = handler;
this.allowMultiple = true; this.allowMultiple = true;
this.order = order;
} }
public ComponentHandlerAttribute(Type handler, bool allowMultiple) public ComponentHandlerAttribute(Type handler, bool allowMultiple, int order = 3)
{ {
this.handler = handler; this.handler = handler;
this.allowMultiple = allowMultiple; this.allowMultiple = allowMultiple;
this.order = order;
} }
} }
} }

View File

@@ -123,9 +123,11 @@ namespace XCharts.Runtime
var handler = (MainComponentHandler)Activator.CreateInstance(attrubte.handler); var handler = (MainComponentHandler)Activator.CreateInstance(attrubte.handler);
handler.attribute = attrubte; handler.attribute = attrubte;
handler.chart = this; handler.chart = this;
handler.order = attrubte.order;
handler.SetComponent(component); handler.SetComponent(component);
component.handler = handler; component.handler = handler;
m_ComponentHandlers.Add(handler); m_ComponentHandlers.Add(handler);
m_ComponentHandlers.Sort((a, b) => { return a.order.CompareTo(b.order); });
} }
public bool RemoveChartComponent<T>(int index = 0) public bool RemoveChartComponent<T>(int index = 0)

View File

@@ -88,6 +88,7 @@ namespace XCharts.Runtime
public abstract class MainComponentHandler public abstract class MainComponentHandler
{ {
public int order { get; internal set; }
public BaseChart chart { get; internal set; } public BaseChart chart { get; internal set; }
public ComponentHandlerAttribute attribute { get; internal set; } public ComponentHandlerAttribute attribute { get; internal set; }