IPackRule.cs 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. 
  2. namespace YooAsset.Editor
  3. {
  4. public struct PackRuleData
  5. {
  6. public string AssetPath;
  7. public string CollectPath;
  8. public string GroupName;
  9. public string UserData;
  10. public PackRuleData(string assetPath)
  11. {
  12. AssetPath = assetPath;
  13. CollectPath = string.Empty;
  14. GroupName = string.Empty;
  15. UserData = string.Empty;
  16. }
  17. public PackRuleData(string assetPath, string collectPath, string groupName, string userData)
  18. {
  19. AssetPath = assetPath;
  20. CollectPath = collectPath;
  21. GroupName = groupName;
  22. UserData = userData;
  23. }
  24. }
  25. public struct PackRuleResult
  26. {
  27. private readonly string _bundleName;
  28. private readonly string _bundleExtension;
  29. public PackRuleResult(string bundleName, string bundleExtension)
  30. {
  31. _bundleName = bundleName;
  32. _bundleExtension = bundleExtension;
  33. }
  34. /// <summary>
  35. /// 获取主资源包全名称
  36. /// </summary>
  37. public string GetMainBundleName(string packageName, bool uniqueBundleName)
  38. {
  39. string fullName;
  40. string bundleName = EditorTools.GetRegularPath(_bundleName).Replace('/', '_').Replace('.', '_').ToLower();
  41. if (uniqueBundleName)
  42. fullName = $"{packageName}_{bundleName}.{_bundleExtension}";
  43. else
  44. fullName = $"{bundleName}.{_bundleExtension}";
  45. return fullName.ToLower();
  46. }
  47. /// <summary>
  48. /// 获取共享资源包全名称
  49. /// </summary>
  50. public string GetShareBundleName(string packageName, bool uniqueBundleName)
  51. {
  52. // 注意:冗余的共享资源包名返回空
  53. if (string.IsNullOrEmpty(_bundleName) && string.IsNullOrEmpty(_bundleExtension))
  54. return string.Empty;
  55. string fullName;
  56. string bundleName = EditorTools.GetRegularPath(_bundleName).Replace('/', '_').Replace('.', '_').ToLower();
  57. if (uniqueBundleName)
  58. fullName = $"{packageName}_share_{bundleName}.{_bundleExtension}";
  59. else
  60. fullName = $"share_{bundleName}.{_bundleExtension}";
  61. return fullName.ToLower();
  62. }
  63. }
  64. /// <summary>
  65. /// 资源打包规则接口
  66. /// </summary>
  67. public interface IPackRule
  68. {
  69. /// <summary>
  70. /// 获取打包规则结果
  71. /// </summary>
  72. PackRuleResult GetPackRuleResult(PackRuleData data);
  73. /// <summary>
  74. /// 是否为原生文件打包规则
  75. /// </summary>
  76. bool IsRawFilePackRule();
  77. }
  78. }