Files
MinFt/Client/Assets/Scripts/TablesEx/TbFishingEventCycleItemExtensions.cs
Liubing\LB 3d8d4d18f3 first commit
先修复一下,错误的场景

删除不必要的钓场资产

修复into场景

update:更新meta文件,修复报错

update:修复资源

修复第一章节建造

修复建造第三章

update:删除多余内容

update:更新README.md

update:还原图标

update:更新README

update:更新配置
2026-04-28 02:17:22 +08:00

74 lines
2.4 KiB
C#
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using System.Collections.Generic;
using System.Linq;
namespace cfg
{
/// <summary>
/// TbFishingEventCycleItem 的扩展方法
/// 提供通过物品ID反向查询活动配置的能力
/// </summary>
public static class TbFishingEventCycleItemExtensions
{
// 按物品ID索引的缓存用于反向查询
private static Dictionary<int, FishingEventCycleItem> _itemIdIndex;
private static readonly object _lock = new object();
/// <summary>
/// 初始化物品ID索引在 Tables 初始化后调用)
/// </summary>
public static void BuildItemIdIndex(this TbFishingEventCycleItem table)
{
lock (_lock)
{
if (_itemIdIndex != null) return; // 已经初始化过
_itemIdIndex = new Dictionary<int, FishingEventCycleItem>();
foreach (var item in table.DataList)
{
if (item.ItemId > 0)
{
// 如果有重复的 ItemId使用第一个找到的
if (!_itemIdIndex.ContainsKey(item.ItemId))
{
_itemIdIndex[item.ItemId] = item;
}
}
}
#if UNITY_EDITOR
UnityEngine.Debug.Log($"[TbFishingEventCycleItemExtensions] Built item ID index with {_itemIdIndex.Count} entries");
#endif
}
}
/// <summary>
/// 根据物品ID查找对应的活动周期配置
/// </summary>
/// <param name="table">配置表实例</param>
/// <param name="itemId">物品ID</param>
/// <returns>活动周期配置,如果未找到返回 null</returns>
public static FishingEventCycleItem FindByItemId(this TbFishingEventCycleItem table, int itemId)
{
// 确保索引已初始化
if (_itemIdIndex == null)
{
table.BuildItemIdIndex();
}
return _itemIdIndex.TryGetValue(itemId, out var config) ? config : null;
}
/// <summary>
/// 清空索引缓存(用于测试或重新加载配置时)
/// </summary>
public static void ClearItemIdIndex()
{
lock (_lock)
{
_itemIdIndex = null;
}
}
}
}