From 145ca936e7c45e4b336bd4869f8621e55a0ee3af Mon Sep 17 00:00:00 2001 From: hevinci Date: Fri, 17 Feb 2023 18:44:19 +0800 Subject: [PATCH] update sample --- .../Scripts/Editor/CustomPackRule.cs | 41 ++++++++++++++++++- 1 file changed, 39 insertions(+), 2 deletions(-) diff --git a/Assets/YooAsset/Samples~/Extension Sample/Scripts/Editor/CustomPackRule.cs b/Assets/YooAsset/Samples~/Extension Sample/Scripts/Editor/CustomPackRule.cs index 653df5a..ebd7a3c 100644 --- a/Assets/YooAsset/Samples~/Extension Sample/Scripts/Editor/CustomPackRule.cs +++ b/Assets/YooAsset/Samples~/Extension Sample/Scripts/Editor/CustomPackRule.cs @@ -10,7 +10,7 @@ public class PackEffectTexture : IPackRule { private const string PackDirectory = "Assets/Effect/Textures/"; - string IPackRule.GetBundleName(PackRuleData data) + PackRuleResult IPackRule.GetPackRuleResult(PackRuleData data) { string assetPath = data.AssetPath; if (assetPath.StartsWith(PackDirectory) == false) @@ -18,6 +18,43 @@ public class PackEffectTexture : IPackRule string assetName = Path.GetFileName(assetPath).ToLower(); string firstChar = assetName.Substring(0, 1); - return $"{PackDirectory}effect_texture_{firstChar}"; + string bundleName = $"{PackDirectory}effect_texture_{firstChar}"; + var packRuleResult = new PackRuleResult(bundleName, DefaultPackRule.AssetBundleFileExtension); + return packRuleResult; + } + + bool IPackRule.IsRawFilePackRule() + { + return false; + } +} + +[DisplayName("打包视频(自定义)")] +public class PackVideo : IPackRule +{ + public PackRuleResult GetPackRuleResult(PackRuleData data) + { + string bundleName = RemoveExtension(data.AssetPath); + string fileExtension = Path.GetExtension(data.AssetPath); + fileExtension = fileExtension.Remove(0, 1); + PackRuleResult result = new PackRuleResult(bundleName, fileExtension); + return result; + } + + bool IPackRule.IsRawFilePackRule() + { + return true; + } + + private string RemoveExtension(string str) + { + if (string.IsNullOrEmpty(str)) + return str; + + int index = str.LastIndexOf("."); + if (index == -1) + return str; + else + return str.Remove(index); //"assets/config/test.unity3d" --> "assets/config/test" } } \ No newline at end of file