Browse Source

预置资源工具

guodong 1 năm trước cách đây
mục cha
commit
6a775706a9

+ 0 - 77
GameClient/Assets/Editor/BuildEditor/PreloadAssetHelper.cs

@@ -1,77 +0,0 @@
-using System.Collections.Generic;
-using YooAsset.Editor;
-using YooAsset;
-using GFGGame;
-using UnityEditor;
-using System.IO;
-using UnityEngine;
-
-namespace GFGEditor
-{
-    public class PreloadAssetHelper
-    {
-
-        public static void CopyPreloadAssets()
-        {
-            // 等待资源构建流程完成
-            //......
-            string selectedFile =  EditorUtility.OpenFilePanel("Select a file", "", "");
-
-            if(string.IsNullOrEmpty(selectedFile))
-            {
-                return;
-            }
-            int t = selectedFile.LastIndexOf("/");
-            string dirPath = selectedFile.Substring(0, t);
-            // 加载构建成功的资源清单对象
-            byte[] manifestBytes = FileUtility.ReadAllBytes(selectedFile);
-            PackageManifest manifest = ManifestTools.DeserializeFromBinary(manifestBytes);
-
-            // 查找所有需要打进首包资源的依赖AB
-            HashSet<PackageBundle> bundles = new HashSet<PackageBundle>();
-
-            AssetBundlePreloadFiles assetBundlePreloadFiles = AssetBundlePreloadFiles.GetData();
-
-            List<string> preloadFiles = new List<string>();
-            preloadFiles.AddRange(assetBundlePreloadFiles.PreloadFiles);
-
-
-            SqliteController.Instance.Init(false, null);
-            StoryDialogCfg[] dataArray = StoryDialogCfgArray.Instance.dataArray;
-            foreach(var cfg in dataArray)
-            {
-                if(!string.IsNullOrEmpty(cfg.bgRes))
-                {
-                    var resPath = ResPathUtil.GetSceneBgPath(cfg.bgRes);
-                    preloadFiles.Add(resPath);
-                }
-            }
-
-            foreach (var assetPath in preloadFiles)
-            {
-                if (manifest.TryGetPackageAsset(assetPath, out PackageAsset packageAsset))
-                {
-                    var packageBundle = manifest.BundleList[packageAsset.BundleID];
-                    if (bundles.Contains(packageBundle) == false)
-                    {
-                        bundles.Add(packageBundle);
-                        Debug.Log($"preload assetPath {assetPath}");
-                    }
-                }
-            }
-
-            // 拷贝所有首包文件
-            string root = $"{AssetBundleBuilderHelper.GetDefaultStreamingAssetsRoot()}/{VersionController.DefaultPackage}";
-            foreach (var packageBundle in bundles)
-            {
-                string destPath = $"{root}/{packageBundle.FileName}";
-                //...... //拷贝文件
-                string sourcePath = $"{dirPath}/{packageBundle.FileName}";
-                File.Copy(sourcePath, destPath, true);
-                //Debug.Log($"sourcePath { sourcePath}");
-                Debug.Log($"destPath { destPath}");
-            }
-        }
-
-    }
-}

+ 111 - 0
GameClient/Assets/Editor/BuildEditor/PresetAssetHelper.cs

@@ -0,0 +1,111 @@
+using System.Collections.Generic;
+using YooAsset.Editor;
+using YooAsset;
+using GFGGame;
+using UnityEditor;
+using System.IO;
+using UnityEngine;
+
+namespace GFGEditor
+{
+    public class PresetAssetHelper
+    {
+
+        public static void CopyPresetAssets()
+        {
+            // 等待资源构建流程完成
+            //......
+
+            //选择清单文件
+            string selectedFile =  EditorUtility.OpenFilePanel("Select a file", "", "");
+            if(string.IsNullOrEmpty(selectedFile))
+            {
+                return;
+            }
+            int t = selectedFile.LastIndexOf("/");
+            string dirPath = selectedFile.Substring(0, t);
+
+            //生成预制资源列表
+            AssetBundlePreloadFiles assetBundlePreloadFiles = AssetBundlePreloadFiles.GetData();
+
+            List<string> preloadFiles = new List<string>();
+            preloadFiles.AddRange(assetBundlePreloadFiles.PreloadFiles);
+
+
+            SqliteController.Instance.Init(false, null);
+            StoryDialogCfg[] dataArray = StoryDialogCfgArray.Instance.dataArray;
+            foreach (var cfg in dataArray)
+            {
+                if (!string.IsNullOrEmpty(cfg.bgRes))
+                {
+                    var resPath = ResPathUtil.GetSceneBgPath(cfg.bgRes);
+                    preloadFiles.Add(resPath);
+                }
+            }
+
+
+            // 加载构建成功的资源清单对象
+            byte[] manifestBytes = FileUtility.ReadAllBytes(selectedFile);
+            PackageManifest manifest = ManifestTools.DeserializeFromBinary(manifestBytes);
+
+            // 查找所有需要打进首包资源的依赖AB
+            HashSet<PackageBundle> bundles = new HashSet<PackageBundle>();
+            foreach (var assetPath in preloadFiles)
+            {
+                TryAdd(assetPath, manifest, bundles);
+            }
+            List<ItemCfg> dressUpItemlist = ItemCfgArray.Instance.GetCfgsByitemType(ConstItemType.DRESS_UP);
+            foreach(var dressUpCfg in dressUpItemlist)
+            {
+                if(dressUpCfg.loadType > 0)
+                {
+                    string assetPath = ResPathUtil.GetDressUpItemLayerRes(dressUpCfg, 1);
+                    TryAdd(assetPath, manifest, bundles); 
+                    assetPath = ResPathUtil.GetDressUpItemLayerRes(dressUpCfg, 2);
+                    TryAdd(assetPath, manifest, bundles);
+                    assetPath = ResPathUtil.GetDressUpItemLayerRes(dressUpCfg, 3);
+                    TryAdd(assetPath, manifest, bundles);
+                    assetPath = ResPathUtil.GetDressUpAnimationPath(dressUpCfg.res);
+                    TryAdd(assetPath, manifest, bundles);
+                    assetPath = ResPathUtil.GetDressUpEffectPath(dressUpCfg.res);
+                    TryAdd(assetPath, manifest, bundles);
+                }
+            }
+            string root = $"{AssetBundleBuilderHelper.GetDefaultStreamingAssetsRoot()}/{VersionController.DefaultPackage}";
+            // 拷贝指定动态加载文件
+            foreach (var packageBundle in bundles)
+            {
+                string destPath = $"{root}/{packageBundle.FileName}";
+                //...... //拷贝文件
+                string sourcePath = $"{dirPath}/{packageBundle.FileName}";
+                EditorTools.CopyFile(sourcePath, destPath, true);
+                //Debug.Log($"sourcePath { sourcePath}");
+                Debug.Log($"destPath { destPath}");
+            }
+            //拷贝指定标签的文件
+            string[] tags = { "preload"};
+            foreach (var packageBundle in manifest.BundleList)
+            {
+                if (packageBundle.HasTag(tags) == false)
+                    continue;
+                string sourcePath = $"{dirPath}/{packageBundle.FileName}";
+                string destPath = $"{root}/{packageBundle.FileName}";
+                EditorTools.CopyFile(sourcePath, destPath, true);
+                Debug.Log($"destPath { destPath}");
+            }
+        }
+
+        private static void TryAdd(string assetPath, PackageManifest manifest, HashSet<PackageBundle> bundles)
+        {
+            if (manifest.TryGetPackageAsset(assetPath, out PackageAsset packageAsset))
+            {
+                var packageBundle = manifest.BundleList[packageAsset.BundleID];
+                if (bundles.Contains(packageBundle) == false)
+                {
+                    bundles.Add(packageBundle);
+                    Debug.Log($"preload assetPath {assetPath}");
+                }
+            }
+        }
+    }
+}

+ 0 - 0
GameClient/Assets/Editor/BuildEditor/PreloadAssetHelper.cs.meta → GameClient/Assets/Editor/BuildEditor/PresetAssetHelper.cs.meta


+ 3 - 3
GameClient/Assets/Editor/ToolsMenu.cs

@@ -365,10 +365,10 @@ namespace GFGEditor
             BuildDllHelper.BuildHotUpdateDll();
         }
 
-        [MenuItem("Tools/Build/CopyPreloadAssets")]
-        public static void CopyPreloadAssets()
+        [MenuItem("Tools/Build/CopyPresetAssets")]
+        public static void CopyPresetAssets()
         {
-            PreloadAssetHelper.CopyPreloadAssets();
+            PresetAssetHelper.CopyPresetAssets();
         }
     }
 }