ShanxiKnowledgeBase/SXElectricityInformationAcq.../Assets/Scripts/ToolsPack/ToolsPackWindowManager.cs

65 lines
2.3 KiB
C#

using System;
using System.Collections.Generic;
using DefaultNamespace;
using MotionFramework;
using UnityEngine;
using UnityEngine.Serialization;
namespace ToolsPack
{
/// <summary>
/// 工具窗口管理器
/// </summary>
public class ToolsPackWindowManager : MonoBehaviour
{
private Dictionary<string, List<GameObject>> _toolsNames;
[SerializeField] private Transform content;
public void OnEnable()
{
int count = content.childCount;
for (int i = 0; i < count; i++)
{
Destroy(content.GetChild(i).gameObject);
}
MotionEngine.GetModule<ToolsPackManager>().ClearToolsPackWindowItemBts();
//初始化工具集
_toolsNames = MotionEngine.GetModule<ToolsPackManager>().GetToolsPack();
GameObject bt = MotionEngine.GetModule<ToolsPackManager>().GetToolsPackWindowBt();
foreach (var v in _toolsNames)
{
List<string> li = MotionEngine.GetModule<DataConfigManager>().GetToolsPackData(v.Key);
if (li == null)
{
ToolsPackWindowItemBtComponent btComponent = Instantiate(bt, content, false).GetComponent<ToolsPackWindowItemBtComponent>();
btComponent.name = v.Key;
btComponent.Init(v.Key, v.Key, 0);
MotionEngine.GetModule<ToolsPackManager>().AddToolsPackWindowItemBts(btComponent.gameObject);
}
else
{
int index = 0;
foreach (var lis in v.Value)
{
foreach (var to in li)
{
ToolsPackWindowItemBtComponent btComponent = Instantiate(bt, content, false).GetComponent<ToolsPackWindowItemBtComponent>();
btComponent.name = to;
btComponent.Init(to,v.Key,index);
MotionEngine.GetModule<ToolsPackManager>().AddToolsPackWindowItemBts(btComponent.gameObject);
}
index++;
}
}
}
}
}
}