修复表格的刷新工作流程,优化表格的操作,优化表格的序列化工作。
This commit is contained in:
@@ -20,16 +20,23 @@ namespace XericUI.XTable.Core
|
||||
#region 属性
|
||||
|
||||
/// <summary>块内列数(默认 <see cref="DefaultBlockSize"/>)</summary>
|
||||
public int BlockSizeX { get; private set; }
|
||||
[field: SerializeField] public int BlockSizeX { get; private set; }
|
||||
|
||||
/// <summary>块内行数(默认 <see cref="DefaultBlockSize"/>)</summary>
|
||||
public int BlockSizeY { get; private set; }
|
||||
[field: SerializeField] public int BlockSizeY { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// 块字典——key = Z 曲线索引(ulong),value = 数据块。
|
||||
/// 具有哈希表性质,按需创建,键不连续(离散存储)。
|
||||
/// 注意:Dictionary 不被 Unity 序列化器原生支持,通过 <see cref="m_BlockKeys"/> / <see cref="m_BlockValues"/> 代理序列化。
|
||||
/// </summary>
|
||||
public Dictionary<ulong, XTableBlock> BlockMap { get; private set; }
|
||||
[NonSerialized] public Dictionary<ulong, XTableBlock> BlockMap;
|
||||
|
||||
// ── Dictionary 序列化代理 ──
|
||||
// Unity 无法直接序列化 Dictionary<ulong, XTableBlock>,
|
||||
// 使用两个平行列表在 OnBeforeSerialize/OnAfterDeserialize 中转换。
|
||||
[SerializeField] private List<ulong> m_BlockKeys = new List<ulong>();
|
||||
[SerializeField] private List<XTableBlock> m_BlockValues = new List<XTableBlock>();
|
||||
|
||||
/// <summary>
|
||||
/// 获取或创建单元格——如果单元格不存在则自动创建空数据。
|
||||
@@ -74,13 +81,36 @@ namespace XericUI.XTable.Core
|
||||
|
||||
#region 序列化回调
|
||||
|
||||
public void OnBeforeSerialize() { }
|
||||
public void OnBeforeSerialize()
|
||||
{
|
||||
// Dictionary → 平行列表
|
||||
m_BlockKeys.Clear();
|
||||
m_BlockValues.Clear();
|
||||
if (BlockMap != null)
|
||||
{
|
||||
foreach (var kv in BlockMap)
|
||||
{
|
||||
m_BlockKeys.Add(kv.Key);
|
||||
m_BlockValues.Add(kv.Value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void OnAfterDeserialize()
|
||||
{
|
||||
if (BlockSizeX <= 0) BlockSizeX = DefaultBlockSize;
|
||||
if (BlockSizeY <= 0) BlockSizeY = DefaultBlockSize;
|
||||
if (BlockMap == null) BlockMap = new Dictionary<ulong, XTableBlock>();
|
||||
|
||||
// 平行列表 → Dictionary
|
||||
BlockMap = new Dictionary<ulong, XTableBlock>();
|
||||
int count = System.Math.Min(
|
||||
m_BlockKeys?.Count ?? 0,
|
||||
m_BlockValues?.Count ?? 0);
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
if (m_BlockValues[i] != null)
|
||||
BlockMap[m_BlockKeys[i]] = m_BlockValues[i];
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
using UnityEngine;
|
||||
|
||||
namespace XericUI.XTable.Core
|
||||
{
|
||||
/// <summary>
|
||||
@@ -8,7 +10,7 @@ namespace XericUI.XTable.Core
|
||||
/// 同一类型支持本地块内引用和跨块引用,通过 <see cref="IsCrossBlock"/> 区分。
|
||||
/// </summary>
|
||||
[Serializable]
|
||||
public class XTableMergeDescriptor
|
||||
public class XTableMergeDescriptor : ISerializationCallbackReceiver
|
||||
{
|
||||
/// <summary>合并区域在本地块内的起始行</summary>
|
||||
public int LocalStartRow;
|
||||
@@ -37,8 +39,12 @@ namespace XericUI.XTable.Core
|
||||
/// <summary>源单元格在块内的列号(跨块时=源块的列、本地时=本块的列)</summary>
|
||||
public int SourceLocalCol;
|
||||
|
||||
/// <summary>本块内被合并的 (row, col) 集合,查询时快速判断是否需要重定向</summary>
|
||||
public HashSet<(int row, int col)> MergedCellSet;
|
||||
/// <summary>本块内被合并的 (row, col) 集合——不参与序列化,通过代理列表同步</summary>
|
||||
[NonSerialized] public HashSet<(int row, int col)> MergedCellSet;
|
||||
|
||||
// ── HashSet 序列化代理 ──
|
||||
[SerializeField] private List<int> m_MergedRowList = new List<int>();
|
||||
[SerializeField] private List<int> m_MergedColList = new List<int>();
|
||||
|
||||
public XTableMergeDescriptor()
|
||||
{
|
||||
@@ -63,5 +69,37 @@ namespace XericUI.XTable.Core
|
||||
targetRow = SourceLocalRow;
|
||||
targetCol = SourceLocalCol;
|
||||
}
|
||||
|
||||
#region 序列化回调
|
||||
|
||||
public void OnBeforeSerialize()
|
||||
{
|
||||
// HashSet<(int,int)> → 两个平行列表
|
||||
m_MergedRowList.Clear();
|
||||
m_MergedColList.Clear();
|
||||
if (MergedCellSet != null)
|
||||
{
|
||||
foreach (var (row, col) in MergedCellSet)
|
||||
{
|
||||
m_MergedRowList.Add(row);
|
||||
m_MergedColList.Add(col);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void OnAfterDeserialize()
|
||||
{
|
||||
// 两个平行列表 → HashSet<(int,int)>
|
||||
MergedCellSet = new HashSet<(int, int)>();
|
||||
int count = System.Math.Min(
|
||||
m_MergedRowList?.Count ?? 0,
|
||||
m_MergedColList?.Count ?? 0);
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
MergedCellSet.Add((m_MergedRowList[i], m_MergedColList[i]));
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -39,6 +39,9 @@ namespace XericUI.XTable.Rendering.Elements
|
||||
private Transform m_Parent;
|
||||
private Transform m_PoolRoot;
|
||||
|
||||
/// <summary>池根节点(所有回收对象均挂在此节点下,节点本身处于 inactive)</summary>
|
||||
public Transform PoolRoot => m_PoolRoot;
|
||||
|
||||
private Stack<PooledImage> m_ImagePool = new Stack<PooledImage>();
|
||||
private Stack<PooledText> m_TextPool = new Stack<PooledText>();
|
||||
private List<PooledImage> m_ActiveImages = new List<PooledImage>();
|
||||
|
||||
Reference in New Issue
Block a user