168 lines
3.9 KiB
C#
168 lines
3.9 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using MotionFramework;
|
|
using MotionFramework.Scripts.Runtime.Engine.Engine.Network.WebRequest;
|
|
using Newtonsoft.Json.Linq;
|
|
using UnityEngine;
|
|
|
|
public enum ToolsPackScene
|
|
{
|
|
工具间,
|
|
其他
|
|
}
|
|
|
|
/// <summary>
|
|
/// 工具包
|
|
/// </summary>
|
|
public class ToolsPackManager : ModuleSingleton<ToolsPackManager>, IModule
|
|
{
|
|
|
|
private Dictionary<string, GameObject> _toolsPack;
|
|
private Dictionary<string, Texture2D> _toolsPackWindowBtImage; //工具窗口下的按钮图集
|
|
private GameObject _toolsPackWindow;
|
|
private GameObject _toolsPackWindowBt;
|
|
private Transform _canvas;
|
|
|
|
private GameObject _toolsPackWindowTemp;
|
|
private ToolsPackScene _toolsPackScene;
|
|
|
|
public void OnCreate(object createParam)
|
|
{
|
|
_toolsPack = new Dictionary<string, 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, toolsGame);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 删除工具包
|
|
/// </summary>
|
|
/// <param name="toolsName"></param>
|
|
public void DeleteToolsPack(string toolsName)
|
|
{
|
|
_toolsPack.Remove(toolsName);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取所有工具包内容
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public List<string> GetToolsPack()
|
|
{
|
|
List<string> list = new List<string>();
|
|
|
|
foreach (var v in _toolsPack)
|
|
{
|
|
list.Add(v.Key);
|
|
}
|
|
|
|
return list;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 根据名字查询工具包内容
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public (string, GameObject) GetToolsPack(string toolsName)
|
|
{
|
|
GameObject game;
|
|
if (_toolsPack.TryGetValue(toolsName, out game))
|
|
{
|
|
return (toolsName, game);
|
|
}
|
|
|
|
return (toolsName, 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;
|
|
}
|
|
|
|
} |