private static void GroupImportTexture() { var path = AssetDatabase.GetAssetPath(Selection.activeObject); if (!string.IsNullOrEmpty(path)) { var table = CsvHelper.ReadCSV(path, System.Text.Encoding.GetEncoding("gb2312")); TextureInfoTable infoTable = new TextureInfoTable(); infoTable.LoadFromCsvTable(table); if (infoTable != null) { var spriteFolder = EditorUtility.OpenFolderPanel("请选择需要批量导入信息的图片根目录!", System.IO.Path.GetDirectoryName(path), ""); if (!string.IsNullOrEmpty(spriteFolder)) { spriteFolder = spriteFolder.Replace("\\", "/"); if (spriteFolder.StartsWith(Application.dataPath)) { spriteFolder = spriteFolder.Replace(Application.dataPath, "Assets"); for (int i = 0; i < infoTable.textureInfos.Count; i++) { var textureInfo = infoTable.textureInfos[i]; var fullPath = spriteFolder + "/" + textureInfo.texturePath; var texture = AssetDatabase.LoadAssetAtPath <Texture>(fullPath); if (texture != null && textureInfo != null) { SetTextureResourceDic(fullPath, textureInfo); } } AssetDatabase.Refresh(ImportAssetOptions.ForceUpdate); } } } } }
public static void LoadFromCsvTable(this TextureInfoTable infoTable, CsvTable table) { var columsCount = table.Columns.Count; if (columsCount >= 3) { if (table.Rows != null && table.Columns != null) { if (infoTable.textureInfos == null) { infoTable.textureInfos = new List <TextureInfo>(); } else { infoTable.textureInfos.Clear(); } for (int i = 0; i < table.Rows.Count; i++) { var textureInfo = new TextureInfo(); textureInfo.texturePath = table[0, i]; textureInfo.type = (TextureImporterType)System.Enum.Parse(typeof(TextureImporterType), table[1, i]); textureInfo.resourceDic = ParamAnalysisTool.ToDictionary(table[2, i]); if (columsCount > 3) { textureInfo.spritesheetList = ParamAnalysisTool.ToDictionaryArray(table[3, i]); } infoTable.textureInfos.Add(textureInfo); } } } else { Debug.LogError("csv文档参数不足3个,请检查"); } }