using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Security.Cryptography;
using DefaultNamespace;
using MotionFramework;
using MotionFramework.Scripts.Runtime.Engine.Engine.Network.WebRequest;
using Newtonsoft.Json.Linq;
using Unity.VisualScripting;
using UnityEngine;
public enum ToolsPackScene
{
工具间,
其他
}
///
/// 工具包
///
public class ToolsPackManager : ModuleSingleton, IModule
{
private Dictionary> _toolsPack;
private Dictionary _toolsPackWindowBtImage; //工具窗口下的按钮图集
private List _toolsPackWindowItemBts; //工具窗口下创建的按钮集合,点击按钮的X用来删除和新增
private GameObject _toolsPackWindow;
private GameObject _toolsPackWindowBt;
private Transform _canvas;
private GameObject _toolsPackWindowTemp;
private ToolsPackScene _toolsPackScene;
public void OnCreate(object createParam)
{
_toolsPack = new Dictionary>();
_toolsPackWindowItemBts = new List();
//加载工具窗口按钮
_toolsPackWindowBt = Resources.Load("Prefabs/Window/ToolsPack/ToolsPackWindowItemBt");
//加载工具窗口
_toolsPackWindow = Resources.Load("Prefabs/Window/ToolsPack/ToolsPackWindow");
// 从Resources/ToolsPack文件夹加载所有Texture2D资源
Texture2D[] loadedTextures = Resources.LoadAll("ToolsPack/UI");
// 初始化List
_toolsPackWindowBtImage = new Dictionary();
// 将加载的Texture2D添加到List中
foreach (Texture2D texture in loadedTextures)
{
_toolsPackWindowBtImage.Add(texture.name, texture);
}
Debug.Log("已添加工具包模块");
}
public void OnUpdate()
{
}
public void OnDestroy()
{
_toolsPack.Clear();
}
public void OnGUI()
{
}
///
/// 添加到工具包
///
///
///
public void AddToolsPack(string toolsName, GameObject toolsGame)
{
if (!_toolsPack.ContainsKey(toolsName))
{
_toolsPack.Add(toolsName, new List() { toolsGame });
}
else
{
_toolsPack[toolsName].Add(toolsGame);
}
}
///
/// 删除工具包
///
///
public void DeleteToolsPack(string toolsName)
{
_toolsPack.Remove(toolsName);
}
///
/// 获取所有工具包内容
///
///
public Dictionary> GetToolsPack()
{
return _toolsPack;
}
///
/// 根据名字查询工具包内容
///
///
public GameObject GetToolsPack(string toolsName,int index)
{
List game;
if (_toolsPack.TryGetValue(toolsName, out game))
{
for (int i = 0; i < game.Count; i++)
{
if (i == index)
{
return (game[i]);
}
}
}
return null;
}
public Texture2D GetToolsPackWindowBtImage(string gName)
{
Texture2D tex;
if (_toolsPackWindowBtImage.TryGetValue(gName, out tex))
{
return tex;
}
return null;
}
public GameObject GetToolsPackWindow()
{
return _toolsPackWindow;
}
public GameObject GetToolsPackWindowBt()
{
return _toolsPackWindowBt;
}
public GameObject GetToolsPackWindowTemp()
{
return _toolsPackWindowTemp;
}
public void SetToolsPackWindowTemp(GameObject win)
{
_toolsPackWindowTemp = win;
}
public Transform GetCanvas()
{
if (_canvas == null)
{
_canvas = GameObject.Find("UICanvas").transform;
}
return _canvas;
}
public ToolsPackScene GetToolsPackScene()
{
return _toolsPackScene;
}
public void SetToolsPackScene(ToolsPackScene toolsPackScene)
{
_toolsPackScene = toolsPackScene;
}
public void AddToolsPackWindowItemBts(GameObject toolGame)
{
_toolsPackWindowItemBts.Add(toolGame);
}
public void ClearToolsPackWindowItemBts()
{
_toolsPackWindowItemBts.Clear();
}
public void DeleteToolsPackWindowItemBts(string toolName)
{
List list = MotionEngine.GetModule().GetToolsPackData(toolName);
if (list != null)
{
for (int i = 0; i < _toolsPackWindowItemBts.Count; i++)
{
for (int j = 0; j < list.Count; j++)
{
if (_toolsPackWindowItemBts[i].name == list[j])
{
GameObject g = _toolsPackWindowItemBts[i];
_toolsPackWindowItemBts.Remove(g);
UnityEngine.Object.Destroy(g);
}
}
}
}
else
{
for (int i = 0; i < _toolsPackWindowItemBts.Count; i++)
{
if (_toolsPackWindowItemBts[i].name == toolName)
{
GameObject g = _toolsPackWindowItemBts[i];
_toolsPackWindowItemBts.Remove(g);
UnityEngine.Object.Destroy(g);
}
}
}
}
}