当前位置:   article > 正文

[游戏开发][Unity]Assetbundle打包篇(2)打包资源配置篇_unity 资源文件打包

unity 资源文件打包

目录

打包与资源加载框架目录

正文

可视化配置的方式有很多种,Json、XML、以及Unity内置的ScriptableObject序列化

配置文件里要有哪些内容呢,很显然,最重要的就是目标文件路径,其次是权重类型,权重类型有:必要打包型、被引用打包型、忽略类型。为何会有忽略类型呢,是因为我们设置目标文件路径是个文件夹,同文件夹内可能有不想被打包的文件夹,因此,我们需要另开一条配置,把该子文件夹也设置进去,并且权重类型设置为:忽略类型即可。被引用打包型比较好理解,虽然该资源在目标文件路径中,如果最终统计该资源被引用的次数等于0,说明该资源不需要进包。

我选择的是使用 ScriptableObject,其可视化内容可以参考下图。

我安装了Odin Inspector插件所以Inspector面板是可以直接操作的,有需要自行安装

Unity2020以后不用装Odin,已经可以在Unity上编辑了。

CollectionSetting顾名思义就是收集配置,请注意还有一些比较特殊的配置


PackRule设置

PackRule看三个变量就知道是对文件夹是否收集的操作

  1. Collect必须收集该文件夹

  1. Ignore必须忽略该文件夹

  1. Passive 该文件夹被引用时收集


LabelRule

这里要重点强调一下这个规则的作用,我们测试项目中,所有的资源都在一个根目录下Assets/Works/Resource,看我时如何运用LabelRule规则对根目录下的子文件夹实现控制,如下图所示

首先,根目录Assets/Works/Resource设置为LabelByFilePath,意思是说,该目录下的每一个子文件夹内文件,都要单独打成一个AB包,那疑问就来了,每个文件一个AB包,肯定太碎了。

所以就有了第二步操作,第二个操作就是设置根目录的子文件夹类型Assets/Works/Resource/Sprite/BuffIcon 的LabelRule为LabelByFolderPath,意思是以文件夹路径打包。子路径的LabelRule可以覆盖根路径的LabelRule

还有一个重点提示的内容就是,有些文件我们想以文件夹打包,但是!部分子文件太大了,比如好几十M,因此还有个特殊选项LabelByFolderPathExceptBig,意思是,该文件夹还是打成一个整包,但是过大的文件,会根据自己的路径生成一个单独的AB包。

具体代码请看下面的第三个方法


EncryptRule加密规则

加密规则的作用是,AB包打出来后,使用我们规定的加密方式,对AB包数据进行处理,从而让外部的人无法查看包内容。这些加密方式都是自己定的,没有特定的规则

Quick模式:往AB包二进制数据前插一段数据,等将来读取的时候再把插入部分删掉。插入部分你可以自己定义,就算塞入一个数,也可以起到加密作用,只不过别人还是有办法破解,我的Quick模式是用该AB包的Hash生成了一个二进制key插进去,加载AB包时用Hash再算出来这个key,把这个key删掉读包。


BundlePos设置

buildin模式启动时要热更进APP,ingame模式比较特殊,边玩边下载。


CollectionSettingData脚本是用来管理使用CollectionSetting配置的脚本,该CollectionSettingData提供了4个基本的方法供搜集资源时使用。

下面是CollectionSettingData的全部代码,部分代码在下面单独讲解

  1. using System;
  2. using System.IO;
  3. using System.Collections.Generic;
  4. using UnityEngine;
  5. using UnityEditor;
  6. public static class CollectionSettingData
  7. {
  8. public static CollectionSetting Setting;
  9. private static long bigSizeMB = 1024;
  10. static CollectionSettingData()
  11. {
  12.     // 加载配置文件
  13.     Setting = AssetDatabase.LoadAssetAtPath<CollectionSetting>(EditorDefine.CollectorSettingFilePath);
  14.     if (Setting == null)
  15.     {
  16.         Debug.LogWarning($"Create new CollectionSetting.asset : {EditorDefine.CollectorSettingFilePath}");
  17.         Setting = ScriptableObject.CreateInstance<CollectionSetting>();
  18.         EditorTools.CreateFileDirectory(EditorDefine.CollectorSettingFilePath);
  19.         AssetDatabase.CreateAsset(Setting, EditorDefine.CollectorSettingFilePath);
  20.         AssetDatabase.SaveAssets();
  21.         AssetDatabase.Refresh();
  22.     }
  23.     else
  24.     {
  25.         Debug.Log("Load CollectionSetting.asset ok");
  26.     }
  27. }
  28. /// <summary>
  29. /// 存储文件
  30. /// </summary>
  31. public static void SaveFile()
  32. {
  33.     if (Setting != null)
  34.     {
  35.         EditorUtility.SetDirty(Setting);
  36.         AssetDatabase.SaveAssets();
  37.     }
  38. }
  39. /// <summary>
  40. /// 添加元素
  41. /// </summary>
  42. public static void AddElement(string folderPath)
  43. {
  44.     if (IsContainsElement(folderPath) == false)
  45.     {
  46.         CollectionSetting.Wrapper element = new CollectionSetting.Wrapper();
  47.         element.FolderPath = folderPath;
  48.         Setting.Elements.Add(element);
  49.         SaveFile();
  50.     }
  51. }
  52. /// <summary>
  53. /// 移除元素
  54. /// </summary>
  55. public static void RemoveElement(string folderPath)
  56. {
  57.     for (int i = 0; i < Setting.Elements.Count; i++)
  58.     {
  59.         if (Setting.Elements[i].FolderPath == folderPath)
  60.         {
  61.             Setting.Elements.RemoveAt(i);
  62.             break;
  63.         }
  64.     }
  65.     SaveFile();
  66. }
  67. public static void AddI18NDir(string folderPath)
  68. {
  69.     if(!Setting.I18nDirectories.Contains(folderPath))
  70. {
  71.         Setting.I18nDirectories.Add(folderPath);
  72.         SaveFile();
  73.     }
  74. }
  75. public static void RemoveI18NDir(string folderPath)
  76. {
  77.     for (int i = 0; i < Setting.I18nDirectories.Count; i++)
  78.     {
  79.         if (Setting.I18nDirectories[i] == folderPath)
  80.         {
  81.             Setting.I18nDirectories.RemoveAt(i);
  82.             break;
  83.         }
  84.     }
  85.     SaveFile();
  86. }
  87. public static void AddInGameDir(string folderPath)
  88. {
  89.     if (!Setting.InGames.Contains(folderPath))
  90. {
  91.         Setting.InGames.Add(folderPath);
  92.         SaveFile();
  93.     }
  94. }
  95. public static void RemoveInGameDir(string folderPath)
  96. {
  97.     for (int i = 0; i < Setting.InGames.Count; i++)
  98.     {
  99.         if (Setting.InGames[i] == folderPath)
  100.         {
  101.             Setting.InGames.RemoveAt(i);
  102.             break;
  103.         }
  104.     }
  105.     SaveFile();
  106. }
  107. /// <summary>
  108. /// 编辑元素
  109. /// </summary>
  110. public static void ModifyElement(string folderPath, CollectionSetting.EFolderPackRule packRule, CollectionSetting.EBundleLabelRule labelRule, EEncryptMethod encryptMethod, EAssetDeliveryMode deliveryMode, EBundlePos bundlePos)
  111. {
  112.     // 注意:这里强制修改忽略文件夹的命名规则为None
  113.     if (packRule == CollectionSetting.EFolderPackRule.Ignore)
  114.         labelRule = CollectionSetting.EBundleLabelRule.None;
  115.     else if (labelRule == CollectionSetting.EBundleLabelRule.None)
  116.         labelRule = CollectionSetting.EBundleLabelRule.LabelByFilePath;
  117.     for (int i = 0; i < Setting.Elements.Count; i++)
  118.     {
  119.         if (Setting.Elements[i].FolderPath == folderPath)
  120.         {
  121.             Setting.Elements[i].PackRule = packRule;
  122.             Setting.Elements[i].LabelRule = labelRule;
  123.             //Setting.Elements[i].EncryptRule = encryptMethod;
  124.             //Setting.Elements[i].DeliveryMode = deliveryMode;
  125.             Setting.Elements[i].BundlePos = bundlePos;
  126.             break;
  127.         }
  128.     }
  129.     SaveFile();
  130. }
  131. /// <summary>
  132. /// 是否包含元素
  133. /// </summary>
  134. public static bool IsContainsElement(string folderPath)
  135. {
  136.     for (int i = 0; i < Setting.Elements.Count; i++)
  137.         if (Setting.Elements[i].FolderPath == folderPath) return true;
  138.     return false;
  139. }
  140. public static CollectionSetting.Wrapper GetElement(string folderPath)
  141. {
  142.     for (int i = 0; i < Setting.Elements.Count; i++)
  143.         if (Setting.Elements[i].FolderPath == folderPath) return Setting.Elements[i];
  144.     return null;
  145. }
  146. /// <summary>
  147. /// 获取所有的打包路径
  148. /// </summary>
  149. public static List<string> GetAllCollectPath()
  150. {
  151.     List<string> result = new List<string>();
  152.     for (int i = 0; i < Setting.Elements.Count; i++)
  153.     {
  154.         CollectionSetting.Wrapper wrapper = Setting.Elements[i];
  155.         if (wrapper.PackRule == CollectionSetting.EFolderPackRule.Collect)
  156.             result.Add(wrapper.FolderPath);
  157.     }
  158.     return result;
  159. }
  160. /// <summary>
  161. /// 是否收集该资源
  162. /// </summary>
  163. public static bool IsCollectAsset(string assetPath)
  164. {
  165.     for (int i = 0; i < Setting.Elements.Count; i++)
  166.     {
  167.         CollectionSetting.Wrapper wrapper = Setting.Elements[i];
  168.         if (wrapper.PackRule == CollectionSetting.EFolderPackRule.Collect && assetPath.StartsWith(wrapper.FolderPath))
  169.             return true;
  170.     }
  171.     return false;
  172. }
  173. /// <summary>
  174. /// 是否忽略该资源
  175. /// </summary>
  176. public static bool IsIgnoreAsset(string assetPath)
  177. {
  178.     for (int i = 0; i < Setting.Elements.Count; i++)
  179.     {
  180.         CollectionSetting.Wrapper wrapper = Setting.Elements[i];
  181.         if (wrapper.PackRule == CollectionSetting.EFolderPackRule.Ignore && assetPath.StartsWith(wrapper.FolderPath))
  182.             return true;
  183.     }
  184.     //XML
  185.     //List<string> ignoreList = ConfigParser.GetIgnoreResList();
  186.     //foreach (string name in ignoreList)
  187.     //    if (assetPath.Contains(name)) return true;
  188.     return false;
  189. }
  190. private static bool IsSubPath(string folderA, string assetPath)
  191. {
  192.     if(assetPath.StartsWith(folderA))
  193.         return assetPath.Replace(folderA, "").StartsWith("/");
  194.     return false;
  195. }
  196. public static EEncryptMethod GetEncryptRule(string assetPath)
  197. {
  198.     // 注意:一个资源有可能被多个规则覆盖
  199.     List<CollectionSetting.Wrapper> filterWrappers = new List<CollectionSetting.Wrapper>();
  200.     for (int i = 0; i < Setting.Elements.Count; i++)
  201.     {
  202.         CollectionSetting.Wrapper wrapper = Setting.Elements[i];
  203.         if (IsSubPath(wrapper.FolderPath, assetPath))
  204.             filterWrappers.Add(wrapper);
  205.     }
  206.     // 我们使用路径最深层的规则
  207.     CollectionSetting.Wrapper findWrapper = null;
  208.     for (int i = 0; i < filterWrappers.Count; i++)
  209.     {
  210.         CollectionSetting.Wrapper wrapper = filterWrappers[i];
  211.         if (findWrapper == null)
  212.         {
  213.             findWrapper = wrapper;
  214.             continue;
  215.         }
  216.         if (wrapper.FolderPath.Length > findWrapper.FolderPath.Length)
  217.             findWrapper = wrapper;
  218.     }
  219.     // 如果没有找到命名规则
  220.     if (findWrapper == null) return EEncryptMethod.None;
  221.     return findWrapper.EncryptRule;
  222. }
  223. /// <summary>
  224. /// 获取资源的打包标签
  225. /// </summary>
  226. public static string GetAssetBundleLabel(string assetPath)
  227. {
  228.     // 注意:一个资源有可能被多个规则覆盖
  229.     List<CollectionSetting.Wrapper> filterWrappers = new List<CollectionSetting.Wrapper>();
  230.     for (int i = 0; i < Setting.Elements.Count; i++)
  231.     {
  232.         CollectionSetting.Wrapper wrapper = Setting.Elements[i];
  233.         if (IsSubPath(wrapper.FolderPath, assetPath))
  234.             filterWrappers.Add(wrapper);
  235. }
  236. // 我们使用路径最深层的规则
  237. CollectionSetting.Wrapper findWrapper = null;
  238.     for (int i = 0; i < filterWrappers.Count; i++)
  239.     {
  240.         CollectionSetting.Wrapper wrapper = filterWrappers[i];
  241.         if (findWrapper == null)
  242.         {
  243.             findWrapper = wrapper;
  244.             continue;
  245.         }
  246.         if (wrapper.FolderPath.Length > findWrapper.FolderPath.Length)
  247.             findWrapper = wrapper;
  248.     }
  249.     // 如果没有找到命名规则
  250.     if (findWrapper == null) return assetPath.Remove(assetPath.LastIndexOf("."));
  251.    
  252.     string labelName = "";
  253.     // 根据规则设置获取标签名称
  254.     if (findWrapper.LabelRule == CollectionSetting.EBundleLabelRule.None)
  255.     {
  256.         // 注意:如果依赖资源来自于忽略文件夹,那么会触发这个异常
  257.         throw new Exception($"CollectionSetting has depend asset in ignore folder : {findWrapper.FolderPath}, asset : {assetPath}");
  258.         // MotionLog.Log(ELogLevel.Log, $"CollectionSetting has depend asset in ignore folder : {findWrapper.FolderPath}, asset : {assetPath}");
  259.         // labelName = assetPath.Remove(assetPath.LastIndexOf("."));
  260.     }
  261.     else if (findWrapper.LabelRule == CollectionSetting.EBundleLabelRule.LabelByFileName)
  262.     {
  263.         labelName = Path.GetFileNameWithoutExtension(assetPath); // "C:\Demo\Assets\Config\test.txt" --> "test"
  264.     }
  265.     else if (findWrapper.LabelRule == CollectionSetting.EBundleLabelRule.LabelByFilePath)
  266.     {
  267.         labelName = assetPath.Remove(assetPath.LastIndexOf(".")); // "C:\Demo\Assets\Config\test.txt" --> "C:\Demo\Assets\Config\test"
  268.     }
  269.     else if (findWrapper.LabelRule == CollectionSetting.EBundleLabelRule.LabelByFolderName)
  270.     {
  271.         string temp = Path.GetDirectoryName(assetPath); // "C:\Demo\Assets\Config\test.txt" --> "C:\Demo\Assets\Config"
  272.         labelName = Path.GetFileName(temp); // "C:\Demo\Assets\Config" --> "Config"
  273.     }
  274.     else if (findWrapper.LabelRule == CollectionSetting.EBundleLabelRule.LabelByFolderPath)
  275.     {
  276.         labelName = Path.GetDirectoryName(assetPath); // "C:\Demo\Assets\Config\test.txt" --> "C:\Demo\Assets\Config"
  277.     }
  278.     else if (findWrapper.LabelRule == CollectionSetting.EBundleLabelRule.LabelByFolderPathExceptBig)
  279.     {
  280.         long sizeMB = EditorTools.GetFileSize(assetPath) / 1024;
  281.         if (sizeMB < bigSizeMB)
  282.             labelName = Path.GetDirectoryName(assetPath); // "C:\Demo\Assets\Config\test.txt" --> "C:\Demo\Assets\Config"
  283.         else
  284.             labelName = assetPath.Remove(assetPath.LastIndexOf(".")); // "C:\Demo\Assets\Config\test.txt" --> "C:\Demo\Assets\Config\test"
  285.     }
  286.     else if(findWrapper.LabelRule == CollectionSetting.EBundleLabelRule.LabelByRootFolderPath)
  287. {
  288.         labelName = findWrapper.FolderPath;
  289. }
  290.     else
  291.     {
  292.         throw new NotImplementedException($"{findWrapper.LabelRule}");
  293.     }
  294.     ApplyReplaceRules(ref labelName);
  295.     return labelName.Replace("\\", "/");
  296. }
  297. /// <summary>
  298. /// 获取资源的打包位置
  299. /// </summary>
  300. public static EBundlePos GetAssetBundlePos(string assetPath)
  301. {
  302.     // if (assetPath.Contains("Assets/WorksArt/Model/Live2D")
  303.     //     || assetPath.Contains("Assets/Works/Resource/Audio/live2D")
  304.     //     || assetPath.Contains("Assets/Works/Resource/Model/Live2D"))
  305.     // {
  306.     //     return EBundlePos.ingame;
  307.     // }
  308.     List<string> buildInList = ConfigParser.GetBuildInResList();
  309.     foreach(string path in Setting.InGames)
  310.     {
  311.         if (assetPath.Contains(path))
  312.         {
  313.             bool match = false;
  314.             foreach (string name in buildInList)
  315.             {
  316.                 if (assetPath.Contains(name))
  317.                 {
  318.                     match = true;
  319.                     break;
  320.                 }
  321.             }
  322.             if (match)
  323.                 break;
  324.             else
  325.                 return EBundlePos.ingame;
  326.         }
  327.     }
  328.     // 注意:一个资源有可能被多个规则覆盖
  329.     List<CollectionSetting.Wrapper> filterWrappers = new List<CollectionSetting.Wrapper>();
  330.     for (int i = 0; i < Setting.Elements.Count; i++)
  331.     {
  332.         CollectionSetting.Wrapper wrapper = Setting.Elements[i];
  333.         if(IsSubPath(wrapper.FolderPath, assetPath))
  334. {
  335.             filterWrappers.Add(wrapper);
  336.         }
  337. }
  338. // 我们使用路径最深层的规则
  339. CollectionSetting.Wrapper findWrapper = null;
  340.     for (int i = 0; i < filterWrappers.Count; i++)
  341.     {
  342.         CollectionSetting.Wrapper wrapper = filterWrappers[i];
  343.         if (findWrapper == null)
  344.         {
  345.             findWrapper = wrapper;
  346.             continue;
  347.         }
  348.         if (wrapper.FolderPath.Length > findWrapper.FolderPath.Length)
  349.             findWrapper = wrapper;
  350.     }
  351.     // 如果没有找到命名规则
  352.     if (findWrapper == null)
  353.     {
  354.         return EBundlePos.buildin;
  355.     }
  356.    
  357.     return findWrapper.BundlePos;
  358. }
  359. public static void ApplyReplaceRules(ref string name)
  360. {
  361.     if (name.Contains("TempLuaCode"))
  362.     {
  363.         name = name.Replace("TempLuaCode", "Lua");
  364.     }
  365.     if (name.Contains("Resource_min"))
  366.     {
  367.         name = name.Replace("Resource_min", "Resource");
  368.     }
  369. }
  370. }

2:获取所有资源配置信息,是一个很重要的接口,代码在上面也有

  1. public static List<string> GetAllCollectPath()
  2. {
  3. List<string> result = new List<string>();
  4. for (int i = 0; i < Setting.Elements.Count; i++)
  5. {
  6. CollectionSetting.Wrapper wrapper = Setting.Elements[i];
  7. if (wrapper.PackRule == CollectionSetting.EFolderPackRule.Collect)
  8. result.Add(wrapper.FolderPath);
  9. }
  10. return result;
  11. }

3:获取该资源目录的AssetbundleLabel,不知道AssetbundleLabel的小伙伴,看下图

  1. /// <summary>
  2. /// 获取资源的打包标签
  3. /// </summary>
  4. public static string GetAssetBundleLabel(string assetPath)
  5. {
  6. // 注意:一个资源有可能被多个规则覆盖
  7. List<CollectionSetting.Wrapper> filterWrappers = new List<CollectionSetting.Wrapper>();
  8. for (int i = 0; i < Setting.Elements.Count; i++)
  9. {
  10. CollectionSetting.Wrapper wrapper = Setting.Elements[i];
  11. if (IsSubPath(wrapper.FolderPath, assetPath))
  12. filterWrappers.Add(wrapper);
  13. }
  14. // 我们使用路径最深层的规则
  15. CollectionSetting.Wrapper findWrapper = null;
  16. for (int i = 0; i < filterWrappers.Count; i++)
  17. {
  18. CollectionSetting.Wrapper wrapper = filterWrappers[i];
  19. if (findWrapper == null)
  20. {
  21. findWrapper = wrapper;
  22. continue;
  23. }
  24. if (wrapper.FolderPath.Length > findWrapper.FolderPath.Length)
  25. findWrapper = wrapper;
  26. }
  27. // 如果没有找到命名规则
  28. if (findWrapper == null) return assetPath.Remove(assetPath.LastIndexOf("."));
  29. string labelName = "";
  30. // 根据规则设置获取标签名称
  31. if (findWrapper.LabelRule == CollectionSetting.EBundleLabelRule.None)
  32. {
  33. // 注意:如果依赖资源来自于忽略文件夹,那么会触发这个异常
  34. throw new Exception($"CollectionSetting has depend asset in ignore folder : {findWrapper.FolderPath}, asset : {assetPath}");
  35. // MotionLog.Log(ELogLevel.Log, $"CollectionSetting has depend asset in ignore folder : {findWrapper.FolderPath}, asset : {assetPath}");
  36. // labelName = assetPath.Remove(assetPath.LastIndexOf("."));
  37. }
  38. else if (findWrapper.LabelRule == CollectionSetting.EBundleLabelRule.LabelByFileName)
  39. {
  40. labelName = Path.GetFileNameWithoutExtension(assetPath); // "C:\Demo\Assets\Config\test.txt" --> "test"
  41. }
  42. else if (findWrapper.LabelRule == CollectionSetting.EBundleLabelRule.LabelByFilePath)
  43. {
  44. labelName = assetPath.Remove(assetPath.LastIndexOf(".")); // "C:\Demo\Assets\Config\test.txt" --> "C:\Demo\Assets\Config\test"
  45. }
  46. else if (findWrapper.LabelRule == CollectionSetting.EBundleLabelRule.LabelByFolderName)
  47. {
  48. string temp = Path.GetDirectoryName(assetPath); // "C:\Demo\Assets\Config\test.txt" --> "C:\Demo\Assets\Config"
  49. labelName = Path.GetFileName(temp); // "C:\Demo\Assets\Config" --> "Config"
  50. }
  51. else if (findWrapper.LabelRule == CollectionSetting.EBundleLabelRule.LabelByFolderPath)
  52. {
  53. labelName = Path.GetDirectoryName(assetPath); // "C:\Demo\Assets\Config\test.txt" --> "C:\Demo\Assets\Config"
  54. }
  55. else if (findWrapper.LabelRule == CollectionSetting.EBundleLabelRule.LabelByFolderPathExceptBig)
  56. {
  57. long sizeMB = EditorTools.GetFileSize(assetPath) / 1024;
  58. if (sizeMB < bigSizeMB)
  59. labelName = Path.GetDirectoryName(assetPath); // "C:\Demo\Assets\Config\test.txt" --> "C:\Demo\Assets\Config"
  60. else
  61. labelName = assetPath.Remove(assetPath.LastIndexOf(".")); // "C:\Demo\Assets\Config\test.txt" --> "C:\Demo\Assets\Config\test"
  62. }
  63. else if(findWrapper.LabelRule == CollectionSetting.EBundleLabelRule.LabelByRootFolderPath)
  64. {
  65. labelName = findWrapper.FolderPath;
  66. }
  67. else
  68. {
  69. throw new NotImplementedException($"{findWrapper.LabelRule}");
  70. }
  71. ApplyReplaceRules(ref labelName);
  72. return labelName.Replace("\\", "/");
  73. }

4:获取该资源的BundlePos,BundlePos是什么,前文已经介绍了

  1. public static EBundlePos GetAssetBundlePos(string assetPath)
  2. {
  3. // if (assetPath.Contains("Assets/WorksArt/Model/Live2D")
  4. // || assetPath.Contains("Assets/Works/Resource/Audio/live2D")
  5. // || assetPath.Contains("Assets/Works/Resource/Model/Live2D"))
  6. // {
  7. // return EBundlePos.ingame;
  8. // }
  9. List<string> buildInList = ConfigParser.GetBuildInResList();
  10. foreach(string path in Setting.InGames)
  11. {
  12. if (assetPath.Contains(path))
  13. {
  14. bool match = false;
  15. foreach (string name in buildInList)
  16. {
  17. if (assetPath.Contains(name))
  18. {
  19. match = true;
  20. break;
  21. }
  22. }
  23. if (match)
  24. break;
  25. else
  26. return EBundlePos.ingame;
  27. }
  28. }
  29. // 注意:一个资源有可能被多个规则覆盖
  30. List<CollectionSetting.Wrapper> filterWrappers = new List<CollectionSetting.Wrapper>();
  31. for (int i = 0; i < Setting.Elements.Count; i++)
  32. {
  33. CollectionSetting.Wrapper wrapper = Setting.Elements[i];
  34. if(IsSubPath(wrapper.FolderPath, assetPath))
  35. {
  36. filterWrappers.Add(wrapper);
  37. }
  38. }
  39. // 我们使用路径最深层的规则
  40. CollectionSetting.Wrapper findWrapper = null;
  41. for (int i = 0; i < filterWrappers.Count; i++)
  42. {
  43. CollectionSetting.Wrapper wrapper = filterWrappers[i];
  44. if (findWrapper == null)
  45. {
  46. findWrapper = wrapper;
  47. continue;
  48. }
  49. if (wrapper.FolderPath.Length > findWrapper.FolderPath.Length)
  50. findWrapper = wrapper;
  51. }
  52. // 如果没有找到命名规则
  53. if (findWrapper == null)
  54. {
  55. return EBundlePos.buildin;
  56. }
  57. return findWrapper.BundlePos;
  58. }

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/IT小白/article/detail/82238
推荐阅读
相关标签
  

闽ICP备14008679号