using System.Collections; using System.Collections.Generic; using System.IO; using UnityEngine; public class ToolConfigProxy : DataProxy { List m_ToolConfigInfos; Dictionary m_DicToolSprites; /// /// 默认工具信息表加载路径 /// string m_ToolConfigPath; public override void OnRegister() { base.OnRegister(); m_DicToolSprites = new Dictionary(); m_ToolConfigPath = Path.Combine(GlobalConfig.toolConfigTablePath, "工具信息表.xlsx"); m_ToolConfigInfos = ExcelHelper.ReadInfoFromExcel(m_ToolConfigPath, 1); } public override void OnRemove() { base.OnRemove(); m_ToolConfigInfos.Clear(); } /// /// 获取所有的工具类型 /// /// public List GetAllToolTypeOfToolConfig() { List list = new List(); foreach (var item in m_ToolConfigInfos) { if (!list.Contains(item.toolType)) { list.Add(item.toolType); } } return list; } /// /// 获取所有工具名称 /// /// public List GetAllToolCofigInfoName() { List list = new List(); // if (m_ToolConfigInfos == null) m_ToolConfigInfos = ExcelHelper.ReadInfoFromExcel(m_ToolConfigPath, 1); m_ToolConfigInfos = ExcelHelper.ReadInfoFromExcel(m_ToolConfigPath, 1); m_ToolConfigInfos.ForEach(t => list.Add(t.toolName)); return list; } /// /// 获取所有工具信息 /// /// public List GetAllToolConfigInfos() { if (m_ToolConfigInfos == null) m_ToolConfigInfos = ExcelHelper.ReadInfoFromExcel(m_ToolConfigPath, 1); return m_ToolConfigInfos; } /// /// 获取所有工具通过工具类型 /// /// /// public List GetToolConfigInfosByToolType(string toolType) { List tmpList = new List(); if (m_ToolConfigInfos != null) tmpList = m_ToolConfigInfos.FindAll(tool => tool.toolType == toolType); return tmpList; } /// /// 获取所有工具根据工具类型和工具名称 /// /// /// /// public List GetToolConfigInfosByToolTypeAndName(string toolType,string toolName) { List toolConfigInfos = new List(); if (string.IsNullOrEmpty(toolName) && !string.IsNullOrEmpty(toolType)) { toolConfigInfos = GetToolConfigInfosByToolType(toolType); } else if (string.IsNullOrEmpty(toolType) && !string.IsNullOrEmpty(toolName)) { toolConfigInfos = GetToolConfigInfosByToolNameSearch(toolName); } else if (!string.IsNullOrEmpty(toolName) && !string.IsNullOrEmpty(toolType)) { toolConfigInfos = m_ToolConfigInfos.FindAll(tool => tool.toolType == toolType && tool.toolName.Contains(toolName)); } else { toolConfigInfos = GetAllToolConfigInfos(); } return toolConfigInfos; } /// /// 获取所有工具更具工具名的模糊搜索 /// /// /// public List GetToolConfigInfosByToolNameSearch(string searchStr) { List tmpList = new List(); if (m_ToolConfigInfos != null) tmpList = m_ToolConfigInfos.FindAll(tool => tool.toolName.Contains(searchStr)); return tmpList; } /// /// 通过ID获取工具配置信息 /// /// /// public ToolConfigInfo GetTooConfigInfoById(int _id) { if (m_ToolConfigInfos == null) m_ToolConfigInfos = ExcelHelper.ReadInfoFromExcel(m_ToolConfigPath, 1); return m_ToolConfigInfos.Find(t => t.id == _id.ToString()); } /// /// 通过工具名称获取工具配置信息 /// /// /// public ToolConfigInfo GetTooConfigInfoByToolName(string _toolName) { if (m_ToolConfigInfos == null) m_ToolConfigInfos = ExcelHelper.ReadInfoFromExcel(m_ToolConfigPath, 1); return m_ToolConfigInfos.Find(t => t.toolName == _toolName); } /// /// 根据工具名查找工具精灵 /// /// /// public Sprite GetSpriteByToolName(string toolName) { Sprite sprite = null; if (m_DicToolSprites.TryGetValue(toolName,out sprite)) { return sprite; } else { string tmpPath = "Config/工具配置/工具配置图片/" + toolName; sprite = LoadHelper.LoadSpriteFromStreamming(tmpPath); if (sprite != null) { m_DicToolSprites.Add(toolName, sprite); } } return sprite; } }