保存Item时带上路径

This commit is contained in:
zhang hongbo 2026-02-10 18:32:13 +08:00
parent dc5e458475
commit a3945d6aa5
2 changed files with 36 additions and 2 deletions

View File

@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: 5706044f5f8a1d9469a0d192ad6a6da8
guid: 9d4c2e3c55b93e940bdd8c2cdc1605bf
folderAsset: yes
DefaultImporter:
externalObjects: {}

View File

@ -1624,6 +1624,31 @@ namespace DesignTools
currentPage = totalPages - 1;
}
/// <summary>
/// 根据Res字段获取完整资源路径
/// </summary>
private string GetFullResourcePath(string res)
{
if (string.IsNullOrEmpty(res)) return "";
string[] parts = res.Split(',');
if (parts.Length < 2) return "";
if (!int.TryParse(parts[0], out int tableId)) return "";
if (!int.TryParse(parts[1], out int itemId)) return "";
if (itemId < 0) return ""; // 未选择Item
var table = allArtTables.FirstOrDefault(x => x.TableId == tableId);
if (table == null) return "";
var item = table.Items.FirstOrDefault(x => x.Id == itemId);
if (item == null) return "";
if (item.Sprite == null) return "";
return AssetDatabase.GetAssetPath(item.Sprite);
}
/// <summary>
/// 保存数据到Excel
/// </summary>
@ -1671,7 +1696,7 @@ namespace DesignTools
var worksheet = package.Workbook.Worksheets[ITEM_SHEET_NAME];
// 找到列索引
int idCol = -1, nameCol = -1, iTypeCol = -1, effectCol = -1, resCol = -1;
int idCol = -1, nameCol = -1, iTypeCol = -1, effectCol = -1, resCol = -1, fullResourcePathCol = -1;
int columnCount = worksheet.Dimension.Columns;
for (int col = 1; col <= columnCount; col++)
@ -1682,6 +1707,7 @@ namespace DesignTools
else if (header == "IType") iTypeCol = col;
else if (header == "Effect") effectCol = col;
else if (header == "Res") resCol = col;
else if (header == "FullResourcePath") fullResourcePathCol = col;
}
// 创建Id到行号的映射读取现有数据
@ -1729,6 +1755,13 @@ namespace DesignTools
{
worksheet.Cells[targetRow, resCol].Value = item.Res;
}
// 写入完整资源路径
if (fullResourcePathCol > 0)
{
string fullPath = GetFullResourcePath(item.Res);
worksheet.Cells[targetRow, fullResourcePathCol].Value = fullPath;
}
}
// 删除已不存在的数据行(只清空我们管理的列)
@ -1746,6 +1779,7 @@ namespace DesignTools
worksheet.Cells[row, iTypeCol].Value = null;
if (effectCol > 0) worksheet.Cells[row, effectCol].Value = null;
if (resCol > 0) worksheet.Cells[row, resCol].Value = null;
if (fullResourcePathCol > 0) worksheet.Cells[row, fullResourcePathCol].Value = null;
}
}
}