219 lines
5.6 KiB
C#
219 lines
5.6 KiB
C#
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
|
|
{
|
|
工具间,
|
|
其他
|
|
}
|
|
|
|
/// <summary>
|
|
/// 工具包
|
|
/// </summary>
|
|
public class ToolsPackManager : ModuleSingleton<ToolsPackManager>, IModule
|
|
{
|
|
private Dictionary<string, List<GameObject>> _toolsPack;
|
|
private Dictionary<string, Texture2D> _toolsPackWindowBtImage; //工具窗口下的按钮图集
|
|
private List<GameObject> _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<string, List<GameObject>>();
|
|
_toolsPackWindowItemBts = new List<GameObject>();
|
|
//加载工具窗口按钮
|
|
_toolsPackWindowBt = Resources.Load<GameObject>("Prefabs/Window/ToolsPack/ToolsPackWindowItemBt");
|
|
//加载工具窗口
|
|
_toolsPackWindow = Resources.Load<GameObject>("Prefabs/Window/ToolsPack/ToolsPackWindow");
|
|
|
|
// 从Resources/ToolsPack文件夹加载所有Texture2D资源
|
|
Texture2D[] loadedTextures = Resources.LoadAll<Texture2D>("ToolsPack/UI");
|
|
// 初始化List
|
|
_toolsPackWindowBtImage = new Dictionary<string, Texture2D>();
|
|
|
|
// 将加载的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()
|
|
{
|
|
}
|
|
|
|
/// <summary>
|
|
/// 添加到工具包
|
|
/// </summary>
|
|
/// <param name="toolsName"></param>
|
|
/// <param name="toolsGame"></param>
|
|
public void AddToolsPack(string toolsName, GameObject toolsGame)
|
|
{
|
|
if (!_toolsPack.ContainsKey(toolsName))
|
|
{
|
|
_toolsPack.Add(toolsName, new List<GameObject>() { toolsGame });
|
|
}
|
|
else
|
|
{
|
|
_toolsPack[toolsName].Add(toolsGame);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 删除工具包
|
|
/// </summary>
|
|
/// <param name="toolsName"></param>
|
|
public void DeleteToolsPack(string toolsName)
|
|
{
|
|
_toolsPack.Remove(toolsName);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取所有工具包内容
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public Dictionary<string, List<GameObject>> GetToolsPack()
|
|
{
|
|
|
|
|
|
return _toolsPack;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 根据名字查询工具包内容
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public GameObject GetToolsPack(string toolsName,int index)
|
|
{
|
|
List<GameObject> 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<string> list = MotionEngine.GetModule<DataConfigManager>().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);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
} |