开发完成背包功能

This commit is contained in:
yzx 2024-06-05 10:49:21 +08:00
parent 9e2177f4fa
commit 287973be2a
2 changed files with 31 additions and 9 deletions

View File

@ -6,6 +6,7 @@ using DefaultNamespace;
using MotionFramework;
using MotionFramework.Scripts.Runtime.Engine.Engine.Network.WebRequest;
using Newtonsoft.Json.Linq;
using ToolsPack;
using Unity.VisualScripting;
using UnityEngine;
@ -87,9 +88,22 @@ public class ToolsPackManager : ModuleSingleton<ToolsPackManager>, IModule
/// 删除工具包
/// </summary>
/// <param name="toolsName"></param>
public void DeleteToolsPack(string toolsName)
public void DeleteToolsPack(string toolsName, int index)
{
_toolsPack.Remove(toolsName);
if (_toolsPack[toolsName].Count > 0)
{
for (int i = 0; i < _toolsPack[toolsName].Count; i++)
{
if (i == index)
{
_toolsPack[toolsName].RemoveAt(i);
}
}
}
else
{
_toolsPack.Remove(toolsName);
}
}
/// <summary>
@ -98,8 +112,6 @@ public class ToolsPackManager : ModuleSingleton<ToolsPackManager>, IModule
/// <returns></returns>
public Dictionary<string, List<GameObject>> GetToolsPack()
{
return _toolsPack;
}
@ -107,7 +119,7 @@ public class ToolsPackManager : ModuleSingleton<ToolsPackManager>, IModule
/// 根据名字查询工具包内容
/// </summary>
/// <returns></returns>
public GameObject GetToolsPack(string toolsName,int index)
public GameObject GetToolsPack(string toolsName, int index)
{
List<GameObject> game;
if (_toolsPack.TryGetValue(toolsName, out game))
@ -185,7 +197,12 @@ public class ToolsPackManager : ModuleSingleton<ToolsPackManager>, IModule
_toolsPackWindowItemBts.Clear();
}
public void DeleteToolsPackWindowItemBts(string toolName)
/// <summary>
/// 删除背包里的UI按钮
/// </summary>
/// <param name="toolName"></param>
/// <param name="index"></param>
public void DeleteToolsPackWindowItemBts(string toolName, int index)
{
List<string> list = MotionEngine.GetModule<DataConfigManager>().GetToolsPackData(toolName);
if (list != null)
@ -194,7 +211,7 @@ public class ToolsPackManager : ModuleSingleton<ToolsPackManager>, IModule
{
for (int j = 0; j < list.Count; j++)
{
if (_toolsPackWindowItemBts[i].name == list[j])
if (_toolsPackWindowItemBts[i].name == list[j] && _toolsPackWindowItemBts[i].GetComponent<ToolsPackWindowItemBtComponent>().GetIndex() == index)
{
GameObject g = _toolsPackWindowItemBts[i];
_toolsPackWindowItemBts.Remove(g);

View File

@ -22,8 +22,8 @@ namespace ToolsPack
{
GameObject toolsGame = MotionEngine.GetModule<ToolsPackManager>().GetToolsPack(btName,index);
toolsGame.SetActive(true);
MotionEngine.GetModule<ToolsPackManager>().DeleteToolsPack(btName);
MotionEngine.GetModule<ToolsPackManager>().DeleteToolsPackWindowItemBts(btName);
MotionEngine.GetModule<ToolsPackManager>().DeleteToolsPack(btName,index);
MotionEngine.GetModule<ToolsPackManager>().DeleteToolsPackWindowItemBts(btName,index);
});
}
@ -52,5 +52,10 @@ namespace ToolsPack
{
btNameText.gameObject.SetActive(false);
}
public int GetIndex()
{
return index;
}
}
}