xericScrollRect添加了运行时更新功能
This commit is contained in:
@@ -83,6 +83,8 @@ namespace XericUI.OverrideLayout
|
|||||||
|
|
||||||
private Queue<RectTransform> _activeQueue = new Queue<RectTransform>();
|
private Queue<RectTransform> _activeQueue = new Queue<RectTransform>();
|
||||||
|
|
||||||
|
private bool layoutDirty;
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
[Serializable]
|
[Serializable]
|
||||||
@@ -159,17 +161,7 @@ namespace XericUI.OverrideLayout
|
|||||||
base.OnValidate();
|
base.OnValidate();
|
||||||
if (childrenPool.Parent == null)
|
if (childrenPool.Parent == null)
|
||||||
childrenPool.Parent = content;
|
childrenPool.Parent = content;
|
||||||
|
RefreshLayout();
|
||||||
var layouts = GetChildrenLayout(content.transform.childCount);
|
|
||||||
for (int i = 0; i < layouts.Count; i++)
|
|
||||||
{
|
|
||||||
var trans = content.transform.GetChild(i) as RectTransform;
|
|
||||||
UpdateChildPivot(layouts[i], trans);
|
|
||||||
trans.anchoredPosition = layouts[i].position;
|
|
||||||
trans.SetDeltaSize(m_cellSize);
|
|
||||||
}
|
|
||||||
|
|
||||||
RefreshContentSizeByChildrenLayouts(layouts);
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
protected override void Awake()
|
protected override void Awake()
|
||||||
@@ -223,6 +215,16 @@ namespace XericUI.OverrideLayout
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected override void LateUpdate()
|
||||||
|
{
|
||||||
|
base.LateUpdate();
|
||||||
|
if (layoutDirty)
|
||||||
|
{
|
||||||
|
layoutDirty = false;
|
||||||
|
RefreshLayout();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private Vector3[] viewportVertex = new Vector3[4];
|
private Vector3[] viewportVertex = new Vector3[4];
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -299,15 +301,20 @@ namespace XericUI.OverrideLayout
|
|||||||
|
|
||||||
public void AddChildData(ScrollItemData Data)
|
public void AddChildData(ScrollItemData Data)
|
||||||
{
|
{
|
||||||
|
layoutDirty = true;
|
||||||
_childrenDatas.Add(Data);
|
_childrenDatas.Add(Data);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void RemoveChildData(int index)
|
public void RemoveChildData(int index)
|
||||||
{
|
{
|
||||||
|
layoutDirty = true;
|
||||||
|
_childrenDatas.RemoveAt(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void RemoveChildData(ScrollItemData index)
|
public void RemoveChildData(ScrollItemData index)
|
||||||
{
|
{
|
||||||
|
layoutDirty = true;
|
||||||
|
_childrenDatas.Remove(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ScrollItemData GetChildData(int index)
|
public ScrollItemData GetChildData(int index)
|
||||||
@@ -319,6 +326,20 @@ namespace XericUI.OverrideLayout
|
|||||||
|
|
||||||
#region 布局计算
|
#region 布局计算
|
||||||
|
|
||||||
|
private void RefreshLayout()
|
||||||
|
{
|
||||||
|
var layouts = GetChildrenLayout(content.transform.childCount);
|
||||||
|
for (int i = 0; i < layouts.Count; i++)
|
||||||
|
{
|
||||||
|
var trans = content.transform.GetChild(i) as RectTransform;
|
||||||
|
UpdateChildPivot(layouts[i], trans);
|
||||||
|
trans.anchoredPosition = layouts[i].position;
|
||||||
|
trans.SetDeltaSize(m_cellSize);
|
||||||
|
}
|
||||||
|
|
||||||
|
RefreshContentSizeByChildrenLayouts(layouts);
|
||||||
|
}
|
||||||
|
|
||||||
private void UpdateContentLayout(int axis, float overrideSize)
|
private void UpdateContentLayout(int axis, float overrideSize)
|
||||||
{
|
{
|
||||||
content.SetSizeWithCurrentAnchors((RectTransform.Axis)axis, overrideSize);
|
content.SetSizeWithCurrentAnchors((RectTransform.Axis)axis, overrideSize);
|
||||||
|
|||||||
Reference in New Issue
Block a user