ImportArtResTool.cs 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324
  1. using UnityEditor;
  2. using UnityEngine;
  3. using System.IO;
  4. using System;
  5. using System.Collections.Generic;
  6. using GFGGame;
  7. namespace GFGEditor
  8. {
  9. public class ImportArtResTool
  10. {
  11. public static string ResRootDirName = "正式资源";
  12. public static string ResRootDirNameDressUp = "正式资源";
  13. public static string ResRootPath { get { return $"../../../gfg/{ResRootDirName}/"; } }
  14. public static string ResRootPathDressUp { get { return $"../../../gfg/{ResRootDirNameDressUp}/"; } }
  15. public static string ragule = @"^[0-9a-zA-Z_.]{1,}$";
  16. public static string Md5FilePath = $"{ResPathUtil.RES_ROOT_DIR_PATH}/MD5";
  17. private static string[] FieldGuideIconSrcPaths { get { return new string[] { ResRootPath + "图鉴/" }; } }
  18. public static string FieldGuideIconTargetPath = $"{ResPathUtil.TEXTURE_DIR_PATH}/FieldGuide/Icon/";
  19. public static string FieldGuideIconMd5FileSaveName = "FieldGuideIconMd5";
  20. private static string[] MusicSrcPaths { get { return new string[] { ResRootPath + "music/" }; } }
  21. public static string MusicTargetPath = $"{ResPathUtil.MUSIC_DIR_PATH}/";
  22. public static string MusicMd5FileSaveName = "MusicMd5";
  23. private static string[] CardMusicSrcPaths { get { return new string[] { ResRootPath + "cardMusic/Card/" }; } }
  24. public static string CardMusicTargetPath = $"{ResPathUtil.SOUND_DIR_PATH}/Card/";
  25. public static string CardMusicMd5FileSaveName = "CardMusicMd5";
  26. private static string[] ItemIconSrcPaths { get { return new string[] { ResRootPath + "icon/" }; } }
  27. public static string ItemIconTargetPath = $"{ResPathUtil.TEXTURE_DIR_PATH}/Icon/";
  28. public static string IconMd5FileSaveName = "IconMd5";
  29. private static string[] DressUpSrcPaths { get { return new string[] { ResRootPathDressUp + "suit/" }; } }
  30. public static string DressUpTargetPath = $"{ResPathUtil.TEXTURE_DIR_PATH}/DressUp/";
  31. public static string DressUpMd5FileSaveName = "DressUpMd5";
  32. private static string[] NpcHeadSrcPaths { get { return new string[] { ResRootPath + "npc/对战头像/" }; } }
  33. public static string NpcHeadTargetPath = $"{ResPathUtil.TEXTURE_DIR_PATH}/Npc/Head/";
  34. public static string NPCHeadMd5FileSaveName = "NpcHeadMd5";
  35. private static string[] NpcPicSrcPaths { get { return new string[] { ResRootPath + "npc/对战立绘/" }; } }
  36. public static string NpcPicTargetPath = $"{ResPathUtil.TEXTURE_DIR_PATH}/Npc/PicF/";
  37. public static string PicFMd5FileSaveName = "PicFMd5";
  38. private static string[] NpcPicSSrcPaths { get { return new string[] { ResRootPath + "npc/对话立绘/" }; } }
  39. public static string NpcPicSTargetPath = $"{ResPathUtil.TEXTURE_DIR_PATH}/Npc/PicS/";
  40. public static string PicSMd5FileSaveName = "PicSMd5";
  41. public static string[] BgSrcPaths { get { return new string[] { ResRootPath + "scene/" }; } }
  42. public static string BgTargetPath = $"{ResPathUtil.TEXTURE_DIR_PATH}/DressUp/";
  43. public static string BgMd5FileSaveName = "BgMd5";
  44. private static string[] CardBgSrcPaths { get { return new string[] { ResRootPath + "卡牌/pic/" }; } }
  45. public static string CardBgTargetPath = $"{ResPathUtil.TEXTURE_DIR_PATH}/Card/Bg/";
  46. public static string CardBgMd5FileSaveName = "CardBgMd5";
  47. private static string[] CardIconSrcPaths { get { return new string[] { ResRootPath + "卡牌/icon/" }; } }
  48. public static string CardIconTargetPath = $"{ResPathUtil.TEXTURE_DIR_PATH}/Card/Card/";
  49. public static string CardMd5FileSaveName = "CardMd5";
  50. private static string[] CardSkillSrcPaths { get { return new string[] { ResRootPath + "卡牌/skill/" }; } }
  51. public static string CardSkillTargetPath = $"{ResPathUtil.TEXTURE_DIR_PATH}/Card/Skill/";
  52. public static string CardSkillMd5FileSaveName = "CardSkillMd5";
  53. private static string[] ActivitySrcPaths { get { return new string[] { ResRootPath + "activity/activity/" }; } }
  54. public static string ActivityTargetPath = $"{ResPathUtil.TEXTURE_DIR_PATH}/Activity/Activity/";
  55. public static string ActivityMd5FileSaveName = "ActivityMd5";
  56. private static string[] ActivityShow1SrcPaths { get { return new string[] { ResRootPath + "activity/show1/" }; } }
  57. public static string ActivityShow1TargetPath = $"{ResPathUtil.TEXTURE_DIR_PATH}/Activity/Show1/";
  58. public static string ActivityShow1Md5FileSaveName = "ActivityShow1Md5";
  59. private static string[] PhotoGraphBorderPaths { get { return new string[] { ResRootPath + "边框/" }; } }
  60. public static string PhotoGraphBorderTargetPath = $"{ResPathUtil.TEXTURE_DIR_PATH}/Photograph/border/";
  61. public static string PhotoGraphBorderMd5FileSaveName = "PhotoGraphBorderMd5";
  62. private static string[] UIBgSrcPaths { get { return new string[] { ResRootPath + "UI背景/" }; } }
  63. public static string UIBgTargetPath = $"{ResPathUtil.TEXTURE_DIR_PATH}/BgImg/";
  64. public static string UIBgMd5FileSaveName = "UIBgMd5";
  65. private static string[] ActivityShow2SrcPaths { get { return new string[] { ResRootPath + "activity/show2/" }; } }
  66. public static string ActivityShow2TargetPath = $"{ResPathUtil.TEXTURE_DIR_PATH}/Activity/Show2/";
  67. public static string ActivityShow2Md5FileSaveName = "ActivityShow2Md5";
  68. public static string[] DressUpAnimationSrcPaths { get { return new string[] { ResRootPathDressUp + $"ArtProject/{ResPathUtil.ANIMATION_DIR_PATH}/" }; } }
  69. public static string DressUpAnimationTargetPath = $"{ResPathUtil.ANIMATION_DIR_PATH}/";
  70. public static string[] EffectSrcPaths { get { return new string[] { ResRootPath + $"ArtProject/{ResPathUtil.EFFECT_DIR_PATH}/" }; } }
  71. public static string EffectTargetPath = $"{ResPathUtil.EFFECT_DIR_PATH}/";
  72. public static string[] MaterialSrcPaths { get { return new string[] { ResRootPath + $"ArtProject/{ResPathUtil.Material_DIR_PATH}/Effect/" }; } }
  73. public static string MaterialTargetPath = $"{ResPathUtil.Material_DIR_PATH}/Effect/";
  74. public static string EffectMaterialMd5FileSaveName = "EffectMaterialMd5";
  75. public static string[] ShaderSrcPaths { get { return new string[] { ResRootPath + $"ArtProject/{ResPathUtil.Shader_DIR_PATH}/" }; } }
  76. public static string ShaderTargetPath = $"{ResPathUtil.Shader_DIR_PATH}/";
  77. public static string ShaderMd5FileSaveName = "ShaderMd5";
  78. public static string[] ModelSrcPaths { get { return new string[] { ResRootPath + $"ArtProject/{ResPathUtil.Model_DIR_PATH}/" }; } }
  79. public static string ModelTargetPath = $"{ResPathUtil.Model_DIR_PATH}/";
  80. public static string ModelMd5FileSaveName = "ModelMd5";
  81. public static string[] TextureSrcPaths { get { return new string[] { ResRootPath + $"ArtProject/{ResPathUtil.TEXTURE_DIR_PATH}/Effect/" }; } }
  82. public static string TextureTargetPath = $"{ResPathUtil.TEXTURE_DIR_PATH}/Effect/";
  83. public static string EffectTextureMd5FileSaveName = "EffectTextureMd5";
  84. private static string[] TravelBgPaths { get { return new string[] { ResRootPath + "千山万水/背景/" }; } }
  85. public static string TravelBgTargetPath = $"{ResPathUtil.TEXTURE_DIR_PATH}/Travel/Bg/";
  86. public static string TravelBgMd5FileSaveName = "TravelBgMd5";
  87. private static string[] TravelRolePaths { get { return new string[] { ResRootPath + "千山万水/角色/" }; } }
  88. public static string TravelRoleTargetPath = $"{ResPathUtil.TEXTURE_DIR_PATH}/Travel/Role/";
  89. public static string TravelRoleMd5FileSaveName = "TravelRoleMd5";
  90. private static string[] HeadPaths { get { return new string[] { ResRootPath + "头像/头像/" }; } }
  91. public static string HeadTargetPath = $"{ResPathUtil.TEXTURE_DIR_PATH}/Head/Head/";
  92. public static string HeadMd5FileSaveName = "HeadMd5";
  93. private static string[] HeadBorderPaths { get { return new string[] { ResRootPath + "头像/头像框/" }; } }
  94. public static string HeadBorderTargetPath = $"{ResPathUtil.TEXTURE_DIR_PATH}/Head/HeadBorder/";
  95. public static string HeadBorderMd5FileSaveName = "HeadBorderMd5";
  96. private static string[] LeagueIconPaths { get { return new string[] { ResRootPath + "联盟徽章/" }; } }
  97. public static string LeagueIconTargetPath = $"{ResPathUtil.TEXTURE_DIR_PATH}/LeagueIcon/";
  98. public static string LeagueIconMd5FileSaveName = "LeagueIconMd5";
  99. public static void Import()
  100. {
  101. var md5Path = ImportArtResTool.Md5FilePath;
  102. if (!Directory.Exists(md5Path))
  103. {
  104. Directory.CreateDirectory(md5Path);
  105. }
  106. //音乐
  107. EditorUtility.DisplayProgressBar("进度", "正在导入音乐", 1);
  108. ImportRes(MusicSrcPaths, MusicTargetPath, MusicMd5FileSaveName);
  109. //卡牌音乐
  110. EditorUtility.DisplayProgressBar("进度", "正在导入卡牌音乐", 1);
  111. ImportRes(CardMusicSrcPaths, CardMusicTargetPath, CardMusicMd5FileSaveName);
  112. //图鉴图标
  113. EditorUtility.DisplayProgressBar("进度", "正在导入图鉴图标", 1);
  114. ImportRes(FieldGuideIconSrcPaths, FieldGuideIconTargetPath, FieldGuideIconMd5FileSaveName);
  115. //物品图标
  116. EditorUtility.DisplayProgressBar("进度", "正在导入物品图标", 1);
  117. ImportRes(ItemIconSrcPaths, ItemIconTargetPath, IconMd5FileSaveName);
  118. // 换装部件
  119. EditorUtility.DisplayProgressBar("进度", "正在裁减换装部件", 1);
  120. ImportClipImage();
  121. //NPC头像
  122. EditorUtility.DisplayProgressBar("进度", "正在导入NPC头像", 1);
  123. ImportRes(NpcHeadSrcPaths, NpcHeadTargetPath, NPCHeadMd5FileSaveName);
  124. //背景
  125. EditorUtility.DisplayProgressBar("进度", "正在导入背景图", 1);
  126. ImportRes(BgSrcPaths, BgTargetPath, BgMd5FileSaveName);
  127. //卡牌背景
  128. EditorUtility.DisplayProgressBar("进度", "正在导入卡牌背景", 1);
  129. ImportRes(CardBgSrcPaths, CardBgTargetPath, CardBgMd5FileSaveName);
  130. //卡牌icon
  131. EditorUtility.DisplayProgressBar("进度", "正在导入卡牌图标", 1);
  132. ImportRes(CardIconSrcPaths, CardIconTargetPath, CardMd5FileSaveName);
  133. //卡牌技能图标
  134. EditorUtility.DisplayProgressBar("进度", "正在导入卡牌技能图标", 1);
  135. ImportRes(CardSkillSrcPaths, CardSkillTargetPath, CardSkillMd5FileSaveName);
  136. //活动宣传图
  137. EditorUtility.DisplayProgressBar("进度", "正在导入活动宣传图", 1);
  138. ImportRes(ActivitySrcPaths, ActivityTargetPath, ActivityMd5FileSaveName);
  139. //活动展示图1
  140. EditorUtility.DisplayProgressBar("进度", "正在导入活动展示图1", 1);
  141. ImportRes(ActivityShow1SrcPaths, ActivityShow1TargetPath, ActivityShow1Md5FileSaveName);
  142. //活动展示图2
  143. EditorUtility.DisplayProgressBar("进度", "正在导入活动展示图2", 1);
  144. ImportRes(ActivityShow2SrcPaths, ActivityShow2TargetPath, ActivityShow2Md5FileSaveName);
  145. //拍照边框
  146. EditorUtility.DisplayProgressBar("进度", "正在导入卡牌图标", 1);
  147. ImportRes(PhotoGraphBorderPaths, PhotoGraphBorderTargetPath, PhotoGraphBorderMd5FileSaveName);
  148. //UI背景
  149. EditorUtility.DisplayProgressBar("进度", "正在导入UI背景", 1);
  150. ImportRes(UIBgSrcPaths, UIBgTargetPath, UIBgMd5FileSaveName);
  151. EditorUtility.DisplayProgressBar("进度", "正在导入千山万水背景", 1);
  152. ImportRes(TravelBgPaths, TravelBgTargetPath, TravelBgMd5FileSaveName);
  153. EditorUtility.DisplayProgressBar("进度", "正在导入千山万水角色资源", 1);
  154. ImportRes(TravelRolePaths, TravelRoleTargetPath, TravelRoleMd5FileSaveName);
  155. EditorUtility.DisplayProgressBar("进度", "正在导入玩家头像资源", 1);
  156. ImportRes(HeadPaths, HeadTargetPath, HeadMd5FileSaveName);
  157. EditorUtility.DisplayProgressBar("进度", "正在导入玩家头像框资源", 1);
  158. ImportRes(HeadBorderPaths, HeadBorderTargetPath, HeadBorderMd5FileSaveName);
  159. EditorUtility.DisplayProgressBar("进度", "正在导入联盟徽章资源", 1);
  160. ImportRes(LeagueIconPaths, LeagueIconTargetPath, LeagueIconMd5FileSaveName);
  161. //清除冗余动画
  162. FileUtil.DeleteUnnecessaryAnimation(ImportArtResTool.DressUpAnimationTargetPath, ImportArtResTool.DressUpAnimationSrcPaths[0]);
  163. FileUtil.DeleteUnnecessaryAnimation(ImportArtResTool.EffectTargetPath, ImportArtResTool.EffectSrcPaths[0]);
  164. //动画
  165. EditorUtility.DisplayProgressBar("进度", "正在导入动作动画", 1);
  166. ImportFileAndDir(DressUpAnimationSrcPaths, DressUpAnimationTargetPath, new string[] { ".moc3" });
  167. //特效
  168. EditorUtility.DisplayProgressBar("进度", "正在导入特效动画", 1);
  169. ImportFileAndDir(EffectSrcPaths, EffectTargetPath);
  170. //材质
  171. EditorUtility.DisplayProgressBar("进度", "正在导入特效材质", 1);
  172. ImportRes(MaterialSrcPaths, MaterialTargetPath, EffectMaterialMd5FileSaveName);
  173. //Shader
  174. EditorUtility.DisplayProgressBar("进度", "正在导入Shader", 1);
  175. ImportRes(ShaderSrcPaths, ShaderTargetPath, ShaderMd5FileSaveName);
  176. //model
  177. EditorUtility.DisplayProgressBar("进度", "正在导入Mhader", 1);
  178. ImportRes(ModelSrcPaths, ModelTargetPath, ModelMd5FileSaveName);
  179. //图片
  180. EditorUtility.DisplayProgressBar("进度", "正在导入特效图片", 1);
  181. ImportRes(TextureSrcPaths, TextureTargetPath, EffectTextureMd5FileSaveName);
  182. //NPC对话立绘
  183. EditorUtility.DisplayProgressBar("进度", "正在导入NPC对话立绘", 1);
  184. List<string> files = ImportRes(NpcPicSSrcPaths, NpcPicSTargetPath, PicSMd5FileSaveName);
  185. //NPC对战立绘
  186. EditorUtility.DisplayProgressBar("进度", "正在导入NPC对战立绘", 1);
  187. files = ImportRes(NpcPicSrcPaths, NpcPicTargetPath, PicFMd5FileSaveName);
  188. if (files != null && files.Count > 0)
  189. {
  190. EditorUtility.DisplayDialog("提示", "有NPC立绘更新,需要设置坐标原点!", "OK", "");
  191. }
  192. EditorUtility.ClearProgressBar();
  193. AssetDatabase.Refresh();
  194. Debug.LogWarning("导入美术资源成功!");
  195. }
  196. public static List<string> ImportRes(string[] sourceDirs, string targetDir, string saveName)
  197. {
  198. List<string> files = null;
  199. if (!Directory.Exists(targetDir))
  200. {
  201. Directory.CreateDirectory(targetDir);
  202. }
  203. foreach (string dir in sourceDirs)
  204. {
  205. files = FileUtil.CopyFilesTo(dir, targetDir, saveName, new string[] { ".png", ".jpg", ".mp3", ".meta", ".mat", ".shader", ".tga", ".FBX", ".max" }, ragule);
  206. foreach (var file in files)
  207. {
  208. Debug.LogFormat("更新{0}", file);
  209. }
  210. }
  211. return files;
  212. }
  213. public static void ImportClipImage()
  214. {
  215. ImportClip(DressUpSrcPaths, DressUpTargetPath);
  216. }
  217. public static void ImportClip(string[] sourceDirs, string targetDir)
  218. {
  219. //换装部件
  220. if (!Directory.Exists(targetDir))
  221. {
  222. Directory.CreateDirectory(targetDir);
  223. }
  224. Dictionary<string, string> sourceImageMD5 = new Dictionary<string, string>();
  225. sourceImageMD5 = ImagesClip.ReadSourceImagesMD5(DressUpMd5FileSaveName);
  226. foreach (string dir in sourceDirs)
  227. {
  228. GFGEditor.FileUtil.ForeachFileInDir(dir, null, (string file) =>
  229. {
  230. string fileName = Path.GetFileName(file);
  231. if (fileName == "saveMD5" || !FileUtil.CheckStringByRegular(fileName, ragule))
  232. {
  233. return;
  234. }
  235. if (!File.Exists(targetDir + fileName) || !sourceImageMD5.ContainsKey(file) || sourceImageMD5[file] != FileUtil.md5file(file))
  236. {
  237. sourceImageMD5[file] = FileUtil.md5file(file);
  238. ImagesClip.CutImageWhitePart(file, targetDir, fileName);
  239. }
  240. });
  241. }
  242. ImagesClip.WriteSourceImagesMD5(sourceImageMD5, DressUpMd5FileSaveName);
  243. AssetDatabase.Refresh();
  244. }
  245. public static List<string> ImportFileAndDir(string[] sourceDirs, string targetDir, string[] excludeExtentions = null)
  246. {
  247. List<string> files = null;
  248. if (!Directory.Exists(targetDir))
  249. {
  250. Directory.CreateDirectory(targetDir);
  251. }
  252. foreach (string dir in sourceDirs)
  253. {
  254. files = FileUtil.CopyDirsAndFilesInSubDirTo(dir, targetDir, excludeExtentions, ragule);
  255. foreach (var file in files)
  256. {
  257. Debug.LogFormat("更新{0}", file);
  258. }
  259. }
  260. return files;
  261. }
  262. }
  263. }