ImportArtResTool.cs 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  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 = "Assets/Res/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[] ItemIconSrcPaths { get { return new string[] { ResRootPath + "icon/" }; } }
  24. public static string ItemIconTargetPath = $"{ResPathUtil.TEXTURE_DIR_PATH}/Icon/";
  25. public static string IconMd5FileSaveName = "IconMd5";
  26. private static string[] DressUpSrcPaths { get { return new string[] { ResRootPathDressUp + "suit/" }; } }
  27. public static string DressUpTargetPath = $"{ResPathUtil.TEXTURE_DIR_PATH}/DressUp/";
  28. public static string DressUpMd5FileSaveName = "DressUpMd5";
  29. private static string[] NpcHeadSrcPaths { get { return new string[] { ResRootPath + "npc/对战头像/" }; } }
  30. public static string NpcHeadTargetPath = $"{ResPathUtil.TEXTURE_DIR_PATH}/Npc/Head/";
  31. public static string HeadMd5FileSaveName = "HeadMd5";
  32. private static string[] NpcPicSrcPaths { get { return new string[] { ResRootPath + "npc/对战立绘/" }; } }
  33. public static string NpcPicTargetPath = $"{ResPathUtil.TEXTURE_DIR_PATH}/Npc/PicF/";
  34. public static string PicFMd5FileSaveName = "PicFMd5";
  35. private static string[] NpcPicSSrcPaths { get { return new string[] { ResRootPath + "npc/对话立绘/" }; } }
  36. public static string NpcPicSTargetPath = $"{ResPathUtil.TEXTURE_DIR_PATH}/Npc/PicS/";
  37. public static string PicSMd5FileSaveName = "PicSMd5";
  38. private static string[] BgSrcPaths { get { return new string[] { ResRootPathDressUp + "scene/" }; } }
  39. public static string BgTargetPath = $"{ResPathUtil.TEXTURE_DIR_PATH}/DressUp/";
  40. public static string BgMd5FileSaveName = "BgMd5";
  41. private static string[] CardBgSrcPaths { get { return new string[] { ResRootPath + "卡牌/pic/" }; } }
  42. public static string CardBgTargetPath = $"{ResPathUtil.TEXTURE_DIR_PATH}/Card/Bg/";
  43. public static string CardBgMd5FileSaveName = "CardBgMd5";
  44. private static string[] CardIconSrcPaths { get { return new string[] { ResRootPath + "卡牌/icon/" }; } }
  45. public static string CardIconTargetPath = $"{ResPathUtil.TEXTURE_DIR_PATH}/Card/Card/";
  46. public static string CardMd5FileSaveName = "CardMd5";
  47. private static string[] ActivitySrcPaths { get { return new string[] { ResRootPath + "activity/activity/" }; } }
  48. public static string ActivityTargetPath = $"{ResPathUtil.TEXTURE_DIR_PATH}/Activity/Activity/";
  49. public static string ActivityMd5FileSaveName = "ActivityMd5";
  50. private static string[] ActivityShow1SrcPaths { get { return new string[] { ResRootPath + "activity/show1/" }; } }
  51. public static string ActivityShow1TargetPath = $"{ResPathUtil.TEXTURE_DIR_PATH}/Activity/Show1/";
  52. public static string ActivityShow1Md5FileSaveName = "ActivityShow1Md5";
  53. private static string[] PhotoGraphBorderPaths { get { return new string[] { ResRootPath + "边框/" }; } }
  54. public static string PhotoGraphBorderTargetPath = $"{ResPathUtil.TEXTURE_DIR_PATH}/Photograph/border/";
  55. public static string PhotoGraphBorderMd5FileSaveName = "PhotoGraphBorderMd5";
  56. private static string[] ActivityShow2SrcPaths { get { return new string[] { ResRootPath + "activity/show2/" }; } }
  57. public static string ActivityShow2TargetPath = $"{ResPathUtil.TEXTURE_DIR_PATH}/Activity/Show2/";
  58. public static string ActivityShow2Md5FileSaveName = "ActivityShow2Md5";
  59. public static string[] DressUpAnimationSrcPaths { get { return new string[] { ResRootPathDressUp + $"ArtProject/{ResPathUtil.ANIMATION_DIR_PATH}/" }; } }
  60. public static string DressUpAnimationTargetPath = $"{ResPathUtil.ANIMATION_DIR_PATH}/";
  61. public static string[] EffectSrcPaths { get { return new string[] { ResRootPath + $"ArtProject/{ResPathUtil.EFFECT_DIR_PATH}/" }; } }
  62. public static string EffectTargetPath = $"{ResPathUtil.EFFECT_DIR_PATH}/";
  63. public static string[] MaterialSrcPaths { get { return new string[] { ResRootPath + $"ArtProject/{ResPathUtil.Material_DIR_PATH}/Effect/" }; } }
  64. public static string MaterialTargetPath = $"{ResPathUtil.Material_DIR_PATH}/Effect/";
  65. public static string EffectMaterialMd5FileSaveName = "EffectMaterialMd5";
  66. public static string[] TextureSrcPaths { get { return new string[] { ResRootPath + $"ArtProject/{ResPathUtil.Texture_DIR_PATH}/Effect/" }; } }
  67. public static string TextureTargetPath = $"{ResPathUtil.Texture_DIR_PATH}/Effect/";
  68. public static string EffectTextureMd5FileSaveName = "EffectTextureMd5";
  69. public static void Import()
  70. {
  71. var md5Path = ImportArtResTool.Md5FilePath;
  72. if (!Directory.Exists(md5Path))
  73. {
  74. Directory.CreateDirectory(md5Path);
  75. }
  76. //音乐
  77. EditorUtility.DisplayProgressBar("进度", "正在导入音乐", 1);
  78. ImportRes(MusicSrcPaths, MusicTargetPath, MusicMd5FileSaveName);
  79. //图鉴图标
  80. EditorUtility.DisplayProgressBar("进度", "正在导入图鉴图标", 1);
  81. ImportRes(FieldGuideIconSrcPaths, FieldGuideIconTargetPath, FieldGuideIconMd5FileSaveName);
  82. //物品图标
  83. EditorUtility.DisplayProgressBar("进度", "正在导入物品图标", 1);
  84. ImportRes(ItemIconSrcPaths, ItemIconTargetPath, IconMd5FileSaveName);
  85. // 换装部件
  86. EditorUtility.DisplayProgressBar("进度", "正在裁减换装部件", 1);
  87. ImportClipImage();
  88. //NPC头像
  89. EditorUtility.DisplayProgressBar("进度", "正在导入NPC头像", 1);
  90. ImportRes(NpcHeadSrcPaths, NpcHeadTargetPath, HeadMd5FileSaveName);
  91. //背景
  92. EditorUtility.DisplayProgressBar("进度", "正在导入背景图", 1);
  93. ImportRes(BgSrcPaths, BgTargetPath, BgMd5FileSaveName);
  94. // //卡牌背景
  95. // EditorUtility.DisplayProgressBar("进度", "正在导入卡牌背景", 1);
  96. // ImportRes(CardBgSrcPaths, CardBgTargetPath, CardBgMd5FileSaveName);
  97. //卡牌icon
  98. EditorUtility.DisplayProgressBar("进度", "正在导入卡牌图标", 1);
  99. ImportRes(CardIconSrcPaths, CardIconTargetPath, CardMd5FileSaveName);
  100. //活动宣传图
  101. EditorUtility.DisplayProgressBar("进度", "正在导入活动宣传图", 1);
  102. ImportRes(ActivitySrcPaths, ActivityTargetPath, ActivityMd5FileSaveName);
  103. //活动展示图1
  104. EditorUtility.DisplayProgressBar("进度", "正在导入活动展示图1", 1);
  105. ImportRes(ActivityShow1SrcPaths, ActivityShow1TargetPath, ActivityShow1Md5FileSaveName);
  106. //活动展示图2
  107. EditorUtility.DisplayProgressBar("进度", "正在导入活动展示图2", 1);
  108. ImportRes(ActivityShow2SrcPaths, ActivityShow2TargetPath, ActivityShow2Md5FileSaveName);
  109. //拍照边框
  110. EditorUtility.DisplayProgressBar("进度", "正在导入卡牌图标", 1);
  111. ImportRes(PhotoGraphBorderPaths, PhotoGraphBorderTargetPath, PhotoGraphBorderMd5FileSaveName);
  112. //清除冗余动画
  113. FileUtil.DeleteUnnecessaryAnimation(ImportArtResTool.DressUpAnimationTargetPath, ImportArtResTool.DressUpAnimationSrcPaths[0]);
  114. FileUtil.DeleteUnnecessaryAnimation(ImportArtResTool.EffectTargetPath, ImportArtResTool.EffectSrcPaths[0]);
  115. //动画
  116. EditorUtility.DisplayProgressBar("进度", "正在导入动作动画", 1);
  117. ImportFileAndDir(DressUpAnimationSrcPaths, DressUpAnimationTargetPath, new string[] { ".moc3" });
  118. //特效
  119. EditorUtility.DisplayProgressBar("进度", "正在导入特效动画", 1);
  120. ImportFileAndDir(EffectSrcPaths, EffectTargetPath);
  121. //材质
  122. EditorUtility.DisplayProgressBar("进度", "正在导入特效材质", 1);
  123. ImportRes(MaterialSrcPaths, MaterialTargetPath, EffectMaterialMd5FileSaveName);
  124. //图片
  125. EditorUtility.DisplayProgressBar("进度", "正在导入特效图片", 1);
  126. ImportRes(TextureSrcPaths, TextureTargetPath, EffectTextureMd5FileSaveName);
  127. //NPC对话立绘
  128. EditorUtility.DisplayProgressBar("进度", "正在导入NPC对话立绘", 1);
  129. List<string> files = ImportRes(NpcPicSSrcPaths, NpcPicSTargetPath, PicSMd5FileSaveName);
  130. //NPC对战立绘
  131. EditorUtility.DisplayProgressBar("进度", "正在导入NPC对战立绘", 1);
  132. files = ImportRes(NpcPicSrcPaths, NpcPicTargetPath, PicFMd5FileSaveName);
  133. if (files != null && files.Count > 0)
  134. {
  135. EditorUtility.DisplayDialog("提示", "有NPC立绘更新,需要设置坐标原点!", "OK", "");
  136. }
  137. EditorUtility.ClearProgressBar();
  138. AssetDatabase.Refresh();
  139. Debug.LogWarning("导入美术资源成功!");
  140. }
  141. public static List<string> ImportRes(string[] sourceDirs, string targetDir, string saveName)
  142. {
  143. List<string> files = null;
  144. if (!Directory.Exists(targetDir))
  145. {
  146. Directory.CreateDirectory(targetDir);
  147. }
  148. foreach (string dir in sourceDirs)
  149. {
  150. files = FileUtil.CopyFilesTo(dir, targetDir, saveName, new string[] { ".png", ".jpg", ".mp3", ".meta" }, ragule);
  151. foreach (var file in files)
  152. {
  153. Debug.LogFormat("更新{0}", file);
  154. }
  155. }
  156. return files;
  157. }
  158. public static void ImportClipImage()
  159. {
  160. ImportClip(DressUpSrcPaths, DressUpTargetPath);
  161. }
  162. public static void ImportClip(string[] sourceDirs, string targetDir)
  163. {
  164. //换装部件
  165. if (!Directory.Exists(targetDir))
  166. {
  167. Directory.CreateDirectory(targetDir);
  168. }
  169. Dictionary<string, string> sourceImageMD5 = new Dictionary<string, string>();
  170. sourceImageMD5 = ImagesClip.ReadSourceImagesMD5(DressUpMd5FileSaveName);
  171. foreach (string dir in sourceDirs)
  172. {
  173. GFGEditor.FileUtil.ForeachFileInDir(dir, null, (string file) =>
  174. {
  175. string fileName = Path.GetFileName(file);
  176. if (fileName == "saveMD5" || !FileUtil.CheckStringByRegular(fileName, ragule))
  177. {
  178. return;
  179. }
  180. if (!File.Exists(targetDir + fileName) || !sourceImageMD5.ContainsKey(file) || sourceImageMD5[file] != FileUtil.md5file(file))
  181. {
  182. sourceImageMD5[file] = FileUtil.md5file(file);
  183. ImagesClip.CutImageWhitePart(file, targetDir, fileName);
  184. }
  185. });
  186. }
  187. ImagesClip.WriteSourceImagesMD5(sourceImageMD5, DressUpMd5FileSaveName);
  188. AssetDatabase.Refresh();
  189. }
  190. public static List<string> ImportFileAndDir(string[] sourceDirs, string targetDir, string[] excludeExtentions = null)
  191. {
  192. List<string> files = null;
  193. if (!Directory.Exists(targetDir))
  194. {
  195. Directory.CreateDirectory(targetDir);
  196. }
  197. foreach (string dir in sourceDirs)
  198. {
  199. files = FileUtil.CopyDirsAndFilesInSubDirTo(dir, targetDir, excludeExtentions, ragule);
  200. foreach (var file in files)
  201. {
  202. Debug.LogFormat("更新{0}", file);
  203. }
  204. }
  205. return files;
  206. }
  207. }
  208. }