瀏覽代碼

打包目录调整

guodong 1 年之前
父節點
當前提交
42cee3547f

+ 1 - 1
GameClient/Assets/YooAsset/Editor/AssetBundleBuilder/AssetBundleBuilderWindow.cs

@@ -296,7 +296,7 @@ namespace YooAsset.Editor
 			{
 				EditorUtility.RevealInFinder(buildResult.OutputPackageDirectory);
 			}
-			AssetBundleHelper.OnPostExecuteBuild();
+			AssetBundleHelper.OnPostExecuteBuild(buildResult);
 		}
 
 		// 构建版本相关

+ 50 - 1
GameClient/Assets/YooAsset/Editor/GFGAsset/Collect/AssetBundleHelper.cs

@@ -2,6 +2,8 @@
 using System.Collections.Generic;
 using System.IO;
 using UnityEditor;
+using UnityEngine;
+using YooAsset.Editor;
 
 namespace GFGEditor
 {
@@ -104,7 +106,7 @@ namespace GFGEditor
             EditorUtility.ClearProgressBar();
         }
 
-        public static void OnPostExecuteBuild()
+        public static void OnPostExecuteBuild(BuildResult buildResult)
         {
             if(fileBundleDic != null)
             {
@@ -118,6 +120,13 @@ namespace GFGEditor
             }
             assetBundleCollector = null;
             _ruler = null;
+
+            int index = buildResult.OutputPackageDirectory.LastIndexOf("/");
+            string targetPath = buildResult.OutputPackageDirectory.Substring(0, index);
+            Debug.Log($"sourcePath {buildResult.OutputPackageDirectory}");
+            Debug.Log($"targetPath {targetPath}");
+            CopyFilesTo(buildResult.OutputPackageDirectory, targetPath);
+            Directory.Delete(buildResult.OutputPackageDirectory, true);
         }
 
         public static void CollectDynamicFile(string dirPath, string itemKey, string assetPath, bool autoMerge)
@@ -277,5 +286,45 @@ namespace GFGEditor
         {
             return excludeFileExtensions.Contains(extension);
         }
+
+        public static List<string> CopyFilesTo(string sourcePath, string targetPath, string[] includeExtensionNames = null)
+        {
+            if(!sourcePath.EndsWith("/"))
+            {
+                sourcePath += "/";
+            }
+            if (!targetPath.EndsWith("/"))
+            {
+                targetPath += "/";
+            }
+            List<string> result = new List<string>();
+            if (Directory.Exists(sourcePath))
+            {
+                var files = Directory.GetFiles(sourcePath);
+                var dirs = Directory.GetDirectories(sourcePath);
+                foreach (var dir in dirs)
+                {
+                    List<string> tempResult = CopyFilesTo(dir, targetPath, includeExtensionNames);
+                    result.AddRange(tempResult);
+                }
+
+                foreach (var file in files)
+                {
+                    var fileName = Path.GetFileName(file);
+                    string extensionName = Path.GetExtension(file);
+                    if (includeExtensionNames == null || Array.IndexOf(includeExtensionNames, extensionName) >= 0)
+                    {
+                        string targetFilePath = targetPath + fileName;
+                        if (!File.Exists(targetFilePath) || !Equals(file, targetFilePath))
+                        {
+                            File.Copy(file, targetFilePath, true);
+                            result.Add(file);
+                        }
+                    }
+                }
+            }
+            return result;
+        }
+
     }
 }