修复循环列表主动GetItemByIndex和GetItemList的问题

修复循环列表主动GetItemByIndex和GetItemList的问题
This commit is contained in:
ALEXTANG
2023-10-26 13:12:35 +08:00
parent 119d9683ad
commit 6992d12c6c
6 changed files with 159 additions and 11 deletions

View File

@@ -277,7 +277,7 @@ namespace GameLogic
item.SetSelected(false);
}
item = GetItem(m_selectIndex) as IListSelectItem;
item = GetItem(selectIndex) as IListSelectItem;
if (item != null)
{
item.SetSelected(true);

View File

@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using TEngine;
using UnityEngine;
namespace GameLogic
@@ -17,7 +18,7 @@ namespace GameLogic
/// <summary>
/// Item字典
/// </summary>
private Dictionary<int, TItem> m_itemCache = new Dictionary<int, TItem>();
private GameFrameworkDictionary<int, TItem> m_itemCache = new GameFrameworkDictionary<int, TItem>();
/// <summary>
/// 计算偏差后的ItemList
@@ -163,9 +164,19 @@ namespace GameLogic
m_items.Clear();
for (int i = 0; i < m_itemCache.Count; i++)
{
m_items.Add(m_itemCache[i]);
m_items.Add(m_itemCache.GetValueByIndex(i));
}
return m_items;
}
/// <summary>
/// 获取Item。
/// </summary>
/// <param name="index">索引。</param>
/// <returns>TItem。</returns>
public TItem GetItemByIndex(int index)
{
return m_itemCache.GetValueByIndex(index);
}
}
}

View File

@@ -8,7 +8,7 @@ namespace GameLogic
{
public LoopListView LoopRectView { private set; get; }
private Dictionary<int, T> m_itemCache = new Dictionary<int, T>();
private GameFrameworkDictionary<int, T> m_itemCache = new GameFrameworkDictionary<int, T>();
public override void BindMemberProperty()
{
@@ -71,9 +71,8 @@ namespace GameLogic
List<T> list = new List<T>();
for (int i = 0; i < m_itemCache.Count; i++)
{
list.Add(m_itemCache[i]);
list.Add(m_itemCache.GetValueByIndex(i));
}
return list;
}
@@ -85,11 +84,11 @@ namespace GameLogic
/// <summary>
/// 获取Item。
/// </summary>
/// <param name="index"></param>
/// <returns></returns>
/// <param name="index">索引。</param>
/// <returns>TItem。</returns>
public T GetItemByIndex(int index)
{
return m_itemCache[index];
return m_itemCache.GetValueByIndex(index);
}
}
}

View File

@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using TEngine;
using UnityEngine;
namespace GameLogic
@@ -16,8 +17,9 @@ namespace GameLogic
/// <summary>
/// Item字典
/// <remarks>Key => GameObjectHashCode | Value => TItem.</remarks>
/// </summary>
private Dictionary<int, TItem> m_itemCache = new Dictionary<int, TItem>();
private GameFrameworkDictionary<int, TItem> m_itemCache = new GameFrameworkDictionary<int, TItem>();
/// <summary>
/// 计算偏差后的ItemList
@@ -159,7 +161,10 @@ namespace GameLogic
public List<TItem> GetItemList()
{
m_items.Clear();
m_items.AddRange(m_itemCache.Values);
for (int i = 0; i < m_itemCache.Count; i++)
{
m_items.Add(m_itemCache.GetValueByIndex(i));
}
return m_items;
}
@@ -171,5 +176,15 @@ namespace GameLogic
{
return LoopRectView.GetItemStartIndex();
}
/// <summary>
/// 获取Item。
/// </summary>
/// <param name="index">索引。</param>
/// <returns>TItem。</returns>
public TItem GetItemByIndex(int index)
{
return m_itemCache.GetValueByIndex(index);
}
}
}