mirror of
https://github.com/XCharts-Team/XCharts.git
synced 2026-05-23 01:10:08 +00:00
修复Chart节点下不能放自定义节点的问题
This commit is contained in:
@@ -394,7 +394,7 @@ namespace XCharts.Runtime
|
||||
{
|
||||
var index = settings.reversePainter ? settings.maxPainter - 1 - i : i;
|
||||
var painter = ChartHelper.AddPainterObject("painter_" + index, transform, m_GraphMinAnchor,
|
||||
m_GraphMaxAnchor, m_GraphPivot, sizeDelta, chartHideFlags, 2 + index);
|
||||
m_GraphMaxAnchor, m_GraphPivot, sizeDelta, chartHideFlags, 2 + index, m_ChildNodeNames);
|
||||
painter.index = m_PainterList.Count;
|
||||
painter.type = Painter.Type.Serie;
|
||||
painter.onPopulateMesh = OnDrawPainterSerie;
|
||||
@@ -404,7 +404,7 @@ namespace XCharts.Runtime
|
||||
m_PainterList.Add(painter);
|
||||
}
|
||||
m_PainterUpper = ChartHelper.AddPainterObject("painter_u", transform, m_GraphMinAnchor,
|
||||
m_GraphMaxAnchor, m_GraphPivot, sizeDelta, chartHideFlags, 2 + settings.maxPainter);
|
||||
m_GraphMaxAnchor, m_GraphPivot, sizeDelta, chartHideFlags, 2 + settings.maxPainter, m_ChildNodeNames);
|
||||
m_PainterUpper.type = Painter.Type.Top;
|
||||
m_PainterUpper.onPopulateMesh = OnDrawPainterUpper;
|
||||
m_PainterUpper.SetActive(true, m_DebugInfo.showAllChartObject);
|
||||
@@ -412,7 +412,7 @@ namespace XCharts.Runtime
|
||||
m_PainterUpper.transform.SetSiblingIndex(settings.maxPainter + 1);
|
||||
|
||||
m_PainterTop = ChartHelper.AddPainterObject("painter_t", transform, m_GraphMinAnchor,
|
||||
m_GraphMaxAnchor, m_GraphPivot, sizeDelta, chartHideFlags, 2 + settings.maxPainter);
|
||||
m_GraphMaxAnchor, m_GraphPivot, sizeDelta, chartHideFlags, 2 + settings.maxPainter, m_ChildNodeNames);
|
||||
m_PainterTop.type = Painter.Type.Top;
|
||||
m_PainterTop.onPopulateMesh = OnDrawPainterTop;
|
||||
m_PainterTop.SetActive(true, m_DebugInfo.showAllChartObject);
|
||||
|
||||
@@ -158,8 +158,8 @@ namespace XCharts.Runtime
|
||||
/// </summary>
|
||||
public void RebuildChartObject()
|
||||
{
|
||||
ChartHelper.DestroyAllChildren(transform);
|
||||
SetAllComponentDirty();
|
||||
ChartHelper.DestoryGameObjectByMatch(transform, m_ChildNodeNames);
|
||||
//SetAllComponentDirty();
|
||||
}
|
||||
|
||||
public bool ScreenPointToChartPoint(Vector2 screenPoint, out Vector2 chartPoint)
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
using UnityEngine.UI;
|
||||
@@ -14,6 +15,7 @@ namespace XCharts.Runtime
|
||||
IDragHandler, IEndDragHandler, IScrollHandler
|
||||
{
|
||||
[SerializeField] protected bool m_EnableTextMeshPro = false;
|
||||
[SerializeField] protected List<string> m_ChildNodeNames = new List<string>();
|
||||
|
||||
protected Painter m_Painter;
|
||||
protected int m_SiblingIndex;
|
||||
@@ -54,6 +56,7 @@ namespace XCharts.Runtime
|
||||
private ScrollRect m_ScrollRect;
|
||||
|
||||
public Painter painter { get { return m_Painter; } }
|
||||
public List<string> childrenNodeNames { get { return m_ChildNodeNames; } }
|
||||
|
||||
protected virtual void InitComponent()
|
||||
{
|
||||
@@ -158,7 +161,7 @@ namespace XCharts.Runtime
|
||||
protected virtual void InitPainter()
|
||||
{
|
||||
m_Painter = ChartHelper.AddPainterObject("painter_b", transform, m_GraphMinAnchor,
|
||||
m_GraphMaxAnchor, m_GraphPivot, new Vector2(m_GraphWidth, m_GraphHeight), chartHideFlags, 1);
|
||||
m_GraphMaxAnchor, m_GraphPivot, new Vector2(m_GraphWidth, m_GraphHeight), chartHideFlags, 1, m_ChildNodeNames);
|
||||
m_Painter.type = Painter.Type.Base;
|
||||
m_Painter.onPopulateMesh = OnDrawPainterBase;
|
||||
m_Painter.transform.SetSiblingIndex(0);
|
||||
|
||||
@@ -156,6 +156,21 @@ namespace XCharts.Runtime
|
||||
}
|
||||
}
|
||||
|
||||
public static void DestoryGameObjectByMatch(Transform parent, List<string> children)
|
||||
{
|
||||
if (parent == null) return;
|
||||
if (children == null || children.Count == 0) return;
|
||||
var childCount = parent.childCount;
|
||||
for (int i = childCount - 1; i >= 0; i--)
|
||||
{
|
||||
var go = parent.GetChild(i);
|
||||
if (go != null && children.Contains(go.name))
|
||||
{
|
||||
GameObject.DestroyImmediate(go.gameObject, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void DestoryGameObject(GameObject go)
|
||||
{
|
||||
if (go != null) GameObject.DestroyImmediate(go, true);
|
||||
@@ -233,7 +248,7 @@ namespace XCharts.Runtime
|
||||
}
|
||||
|
||||
public static GameObject AddObject(string name, Transform parent, Vector2 anchorMin,
|
||||
Vector2 anchorMax, Vector2 pivot, Vector2 sizeDelta, int replaceIndex = -1)
|
||||
Vector2 anchorMax, Vector2 pivot, Vector2 sizeDelta, int replaceIndex = -1, List<string> cacheNames = null)
|
||||
{
|
||||
GameObject obj;
|
||||
if (parent.Find(name))
|
||||
@@ -267,6 +282,8 @@ namespace XCharts.Runtime
|
||||
rect.anchorMax = anchorMax;
|
||||
rect.pivot = pivot;
|
||||
rect.anchoredPosition3D = Vector3.zero;
|
||||
|
||||
if (cacheNames != null && !cacheNames.Contains(name)) cacheNames.Add(name);
|
||||
return obj;
|
||||
}
|
||||
|
||||
@@ -332,9 +349,9 @@ namespace XCharts.Runtime
|
||||
}
|
||||
|
||||
public static Painter AddPainterObject(string name, Transform parent, Vector2 anchorMin, Vector2 anchorMax,
|
||||
Vector2 pivot, Vector2 sizeDelta, HideFlags hideFlags, int siblingIndex)
|
||||
Vector2 pivot, Vector2 sizeDelta, HideFlags hideFlags, int siblingIndex, List<string> childNodeNames)
|
||||
{
|
||||
var painterObj = ChartHelper.AddObject(name, parent, anchorMin, anchorMax, pivot, sizeDelta);
|
||||
var painterObj = ChartHelper.AddObject(name, parent, anchorMin, anchorMax, pivot, sizeDelta, -1, childNodeNames);
|
||||
painterObj.hideFlags = hideFlags;
|
||||
painterObj.transform.SetSiblingIndex(siblingIndex);
|
||||
return ChartHelper.EnsureComponent<Painter>(painterObj);
|
||||
|
||||
Reference in New Issue
Block a user