修改unity的资源打包逻辑
parent
a69cfc43dd
commit
eea0b0ca83
|
|
@ -1,6 +1,7 @@
|
||||||
fileFormatVersion: 2
|
fileFormatVersion: 2
|
||||||
guid: 3f1ca26670fc7465ea399367ef61f8e1
|
guid: d0e56056744c24b1e80b40d8fda28606
|
||||||
TextScriptImporter:
|
folderAsset: yes
|
||||||
|
DefaultImporter:
|
||||||
externalObjects: {}
|
externalObjects: {}
|
||||||
userData:
|
userData:
|
||||||
assetBundleName:
|
assetBundleName:
|
||||||
|
|
@ -1 +0,0 @@
|
||||||
项目AB资源软链接文件夹(和资源工程文件夹名称保持一致)
|
|
||||||
|
|
@ -42,24 +42,25 @@ public static class BuildBundlesHelper
|
||||||
[MenuItem("Tools/TestBuildBundles")]
|
[MenuItem("Tools/TestBuildBundles")]
|
||||||
public static void TestBuildBundles()
|
public static void TestBuildBundles()
|
||||||
{
|
{
|
||||||
|
|
||||||
Debug.LogWarning("MakeAtlas Start ==================");
|
Debug.LogWarning("MakeAtlas Start ==================");
|
||||||
MakeAtlas();
|
MakeAtlas();
|
||||||
AssetDatabase.Refresh();
|
AssetDatabase.Refresh();
|
||||||
Debug.LogWarning("MakeAtlas End ==================");
|
Debug.LogWarning("MakeAtlas End ==================");
|
||||||
|
|
||||||
Debug.LogWarning("Create YooAsset Package Start ==========");
|
Debug.LogWarning("Create YooAsset Package Start ==========");
|
||||||
CreateYooAssetPackage();
|
CreateYooAssetPackage();
|
||||||
AssetDatabase.Refresh();
|
AssetDatabase.Refresh();
|
||||||
Debug.LogWarning("Create YooAsset Package End ==========");
|
Debug.LogWarning("Create YooAsset Package End ==========");
|
||||||
|
|
||||||
Debug.LogWarning("BuildBundles Start ==================");
|
Debug.LogWarning("BuildBundles Start ==================");
|
||||||
AssetBundleCollectorSetting setting = AssetDatabase.LoadAssetAtPath<AssetBundleCollectorSetting>("Assets/AssetBundleCollectorSetting.asset");
|
AssetBundleCollectorSetting setting =
|
||||||
|
AssetDatabase.LoadAssetAtPath<AssetBundleCollectorSetting>("Assets/AssetBundleCollectorSetting.asset");
|
||||||
if (setting == null)
|
if (setting == null)
|
||||||
{
|
{
|
||||||
Debug.LogError("不存在的AssetBundleCollectorSetting.asset");
|
Debug.LogError("不存在的AssetBundleCollectorSetting.asset");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var bundleBuilder = new AssetBundleBuilder();
|
var bundleBuilder = new AssetBundleBuilder();
|
||||||
BuildParameters buildParameters = GetParametersFromParams(BuildTarget.Android, "1.0.0");
|
BuildParameters buildParameters = GetParametersFromParams(BuildTarget.Android, "1.0.0");
|
||||||
string outputDir = $"{buildParameters.BuildOutputRoot}/{buildParameters.BuildTarget.ToString()}";
|
string outputDir = $"{buildParameters.BuildOutputRoot}/{buildParameters.BuildTarget.ToString()}";
|
||||||
|
|
@ -70,12 +71,13 @@ public static class BuildBundlesHelper
|
||||||
for (int i = 0; i < setting.Packages.Count; i++)
|
for (int i = 0; i < setting.Packages.Count; i++)
|
||||||
{
|
{
|
||||||
var package = setting.Packages[i];
|
var package = setting.Packages[i];
|
||||||
if(package.PackageName == "DefaultPackage")
|
if (package.PackageName == "DefaultPackage")
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
buildParameters.PackageName = package.PackageName;
|
buildParameters.PackageName = package.PackageName;
|
||||||
bundleBuilder.Run(buildParameters);
|
bundleBuilder.Run(buildParameters);
|
||||||
}
|
}
|
||||||
|
|
||||||
Debug.LogWarning("BuildBundles End ==================");
|
Debug.LogWarning("BuildBundles End ==================");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -85,19 +87,21 @@ public static class BuildBundlesHelper
|
||||||
MakeAtlas();
|
MakeAtlas();
|
||||||
AssetDatabase.Refresh();
|
AssetDatabase.Refresh();
|
||||||
Debug.LogWarning("MakeAtlas End ==================");
|
Debug.LogWarning("MakeAtlas End ==================");
|
||||||
|
|
||||||
Debug.LogWarning("Create YooAsset Package Start ==========");
|
Debug.LogWarning("Create YooAsset Package Start ==========");
|
||||||
CreateYooAssetPackage();
|
CreateYooAssetPackage();
|
||||||
AssetDatabase.Refresh();
|
AssetDatabase.Refresh();
|
||||||
Debug.LogWarning("Create YooAsset Package End ==========");
|
Debug.LogWarning("Create YooAsset Package End ==========");
|
||||||
|
|
||||||
Debug.LogWarning("BuildBundles Start ==================");
|
Debug.LogWarning("BuildBundles Start ==================");
|
||||||
AssetBundleCollectorSetting setting = AssetDatabase.LoadAssetAtPath<AssetBundleCollectorSetting>("Assets/AssetBundleCollectorSetting.asset");
|
AssetBundleCollectorSetting setting =
|
||||||
|
AssetDatabase.LoadAssetAtPath<AssetBundleCollectorSetting>("Assets/AssetBundleCollectorSetting.asset");
|
||||||
if (setting == null)
|
if (setting == null)
|
||||||
{
|
{
|
||||||
Debug.LogError("不存在的AssetBundleCollectorSetting.asset");
|
Debug.LogError("不存在的AssetBundleCollectorSetting.asset");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
BuildParams bp = BuildParamsHelper.GetBuildParams();
|
BuildParams bp = BuildParamsHelper.GetBuildParams();
|
||||||
bp.Description();
|
bp.Description();
|
||||||
var bundleBuilder = new AssetBundleBuilder();
|
var bundleBuilder = new AssetBundleBuilder();
|
||||||
|
|
@ -111,113 +115,70 @@ public static class BuildBundlesHelper
|
||||||
Debug.LogError($"不支持的平台:{bp.Platform}");
|
Debug.LogError($"不支持的平台:{bp.Platform}");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
string outputDir = $"{buildParameters.BuildOutputRoot}/{buildParameters.BuildTarget.ToString()}";
|
string outputDir = $"{buildParameters.BuildOutputRoot}/{buildParameters.BuildTarget.ToString()}";
|
||||||
Debug.LogError($"bundle资源输出目录:{outputDir}");
|
Debug.LogError($"bundle资源输出目录:{outputDir}");
|
||||||
if (Directory.Exists(outputDir))
|
if (Directory.Exists(outputDir))
|
||||||
Directory.Delete(outputDir, true);
|
Directory.Delete(outputDir, true);
|
||||||
|
|
||||||
for (int i = 0; i < setting.Packages.Count; i++)
|
for (int i = 0; i < setting.Packages.Count; i++)
|
||||||
{
|
{
|
||||||
var package = setting.Packages[i];
|
var package = setting.Packages[i];
|
||||||
if(package.PackageName == "DefaultPackage")
|
if (package.PackageName == "DefaultPackage")
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
buildParameters.PackageName = package.PackageName;
|
buildParameters.PackageName = package.PackageName;
|
||||||
bundleBuilder.Run(buildParameters);
|
bundleBuilder.Run(buildParameters);
|
||||||
}
|
}
|
||||||
|
|
||||||
Debug.LogWarning("BuildBundles End ==================> exe");
|
Debug.LogWarning("BuildBundles End ==================> exe");
|
||||||
}
|
}
|
||||||
|
|
||||||
#region 创建图集
|
#region 创建图集
|
||||||
|
|
||||||
private static void MakeAtlas()
|
private static void MakeAtlas()
|
||||||
{
|
{
|
||||||
for (int i = 0; i < (int)GamePlay.end; i++)
|
string dir = $"Assets/AssetRaw/UIRaw";
|
||||||
|
if (!AssetDatabase.IsValidFolder(dir))
|
||||||
{
|
{
|
||||||
GamePlay playType = (GamePlay)i;
|
Debug.LogError($"不存在的目录:{dir}");
|
||||||
string dir = $"Assets/AssetRaw/UIRaw/Raw/Level/{playType.ToString()}";
|
|
||||||
if (!AssetDatabase.IsValidFolder(dir))
|
|
||||||
{
|
|
||||||
Debug.LogError($"不存在的目录:{dir}");
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
var playTypeAllLevelDirs = AssetDatabase.GetSubFolders(dir);
|
|
||||||
foreach (var levelDir in playTypeAllLevelDirs)
|
|
||||||
{
|
|
||||||
string levelName = levelDir.Substring(levelDir.LastIndexOf('/') + 1);
|
|
||||||
MakeLevelAtlas(levelDir, levelName);
|
|
||||||
string itemDirPath = $"{levelDir}/titem";
|
|
||||||
if (!AssetDatabase.IsValidFolder(itemDirPath))
|
|
||||||
{
|
|
||||||
Debug.LogError($"不存在的道具图:{itemDirPath}");
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
MakeItemAtlas(itemDirPath, levelName);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
MakeAtlas(dir);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void MakeItemAtlas(string dirPath, string levelName)
|
private static void MakeAtlas(string dirPath)
|
||||||
{
|
{
|
||||||
string[] allPics = Directory.GetFiles(dirPath, "*.png", SearchOption.TopDirectoryOnly);
|
string[] allPics = Directory.GetFiles(dirPath, "*.png", SearchOption.TopDirectoryOnly);
|
||||||
if (allPics.Length == 0)
|
if (allPics.Length == 0)
|
||||||
{
|
{
|
||||||
Debug.LogError($"不存在的道具图:{dirPath}");
|
Debug.LogError($"不存在的图:{dirPath}");
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
List<Sprite> sprites = new List<Sprite>();
|
|
||||||
foreach (var picPath in allPics)
|
|
||||||
{
|
|
||||||
if(picPath.EndsWith(".meta"))
|
|
||||||
continue;
|
|
||||||
|
|
||||||
if (picPath.Contains("_titem_"))
|
|
||||||
{
|
|
||||||
var sprite = AssetDatabase.LoadAssetAtPath<Sprite>(picPath);
|
|
||||||
if (sprite != null)
|
|
||||||
{
|
|
||||||
sprites.Add(sprite);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
AtlasUtils.CreateAtlas($"{levelName}_atlasItem", sprites, dirPath);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void MakeLevelAtlas(string levelDir, string levelName)
|
|
||||||
{
|
|
||||||
string[] allPics = Directory.GetFiles(levelDir, "*.png", SearchOption.TopDirectoryOnly);
|
|
||||||
if (allPics.Length == 0)
|
|
||||||
{
|
|
||||||
Debug.LogError($"不存在的关卡图:{levelDir}");
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
List<Sprite> sprites = new List<Sprite>();
|
List<Sprite> sprites = new List<Sprite>();
|
||||||
foreach (var picPath in allPics)
|
foreach (var picPath in allPics)
|
||||||
{
|
{
|
||||||
if(picPath.EndsWith(".meta"))
|
if (picPath.EndsWith(".meta"))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (picPath.Contains("_tfull_") || picPath.Contains("_tmask_") || picPath.Contains("_tlight_") || picPath.Contains("_tshadow_"))
|
var sprite = AssetDatabase.LoadAssetAtPath<Sprite>(picPath);
|
||||||
|
if (sprite != null)
|
||||||
{
|
{
|
||||||
var sprite = AssetDatabase.LoadAssetAtPath<Sprite>(picPath);
|
sprites.Add(sprite);
|
||||||
if (sprite != null)
|
|
||||||
{
|
|
||||||
sprites.Add(sprite);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
AtlasUtils.CreateAtlas($"{levelName}_atlasLevel", sprites, levelDir);
|
|
||||||
|
Debug.LogError(sprites.Count);
|
||||||
|
AtlasUtils.CreateAtlas($"profile", sprites, dirPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
private static void CreateYooAssetPackage()
|
private static void CreateYooAssetPackage()
|
||||||
{
|
{
|
||||||
AssetBundleCollectorSetting setting = AssetDatabase.LoadAssetAtPath<AssetBundleCollectorSetting>("Assets/AssetBundleCollectorSetting.asset");
|
AssetBundleCollectorSetting setting =
|
||||||
|
AssetDatabase.LoadAssetAtPath<AssetBundleCollectorSetting>("Assets/AssetBundleCollectorSetting.asset");
|
||||||
if (setting == null)
|
if (setting == null)
|
||||||
{
|
{
|
||||||
Debug.LogError("不存在的AssetBundleCollectorSetting.asset");
|
Debug.LogError("不存在的AssetBundleCollectorSetting.asset");
|
||||||
|
|
@ -227,101 +188,48 @@ public static class BuildBundlesHelper
|
||||||
//重置配置
|
//重置配置
|
||||||
for (int i = 0; i < setting.Packages.Count; i++)
|
for (int i = 0; i < setting.Packages.Count; i++)
|
||||||
{
|
{
|
||||||
if(setting.Packages[i].PackageName == "DefaultPackage")
|
if (setting.Packages[i].PackageName == "DefaultPackage")
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
setting.Packages.RemoveAt(i);
|
setting.Packages.RemoveAt(i);
|
||||||
i--;
|
i--;
|
||||||
}
|
}
|
||||||
|
|
||||||
Debug.Log($"packge count:{setting.Packages.Count}");
|
Debug.Log($"packge count:{setting.Packages.Count}");
|
||||||
|
|
||||||
//创建关卡资源package
|
//创建关卡资源package
|
||||||
for (int i = 0; i < (int)GamePlay.end; i++)
|
string dir = $"Assets/AssetRaw/UIRaw";
|
||||||
|
if (!AssetDatabase.IsValidFolder(dir))
|
||||||
{
|
{
|
||||||
GamePlay playType = (GamePlay)i;
|
Debug.LogError($"不存在的目录:{dir}");
|
||||||
string dir = $"Assets/AssetRaw/UIRaw/Raw/Level/{playType.ToString()}";
|
|
||||||
if (!AssetDatabase.IsValidFolder(dir))
|
|
||||||
{
|
|
||||||
Debug.LogError($"不存在的目录:{dir}");
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
var playTypeAllLevelDirs = AssetDatabase.GetSubFolders(dir);
|
|
||||||
foreach (var levelDir in playTypeAllLevelDirs)
|
|
||||||
{
|
|
||||||
string levelName = levelDir.Substring(levelDir.LastIndexOf('/') + 1);
|
|
||||||
AssetBundleCollectorPackage package = new AssetBundleCollectorPackage();
|
|
||||||
package.PackageName = levelName;
|
|
||||||
package.PackageDesc = $"{levelName}关卡资源包";
|
|
||||||
package.Groups = new List<AssetBundleCollectorGroup>();
|
|
||||||
|
|
||||||
AssetBundleCollectorGroup group = new AssetBundleCollectorGroup();
|
|
||||||
group.GroupName = "default";
|
|
||||||
group.AssetTags = levelName;
|
|
||||||
group.ActiveRuleName = "EnableGroup";
|
|
||||||
group.Collectors = new List<AssetBundleCollector>();
|
|
||||||
|
|
||||||
AssetBundleCollector collector = new AssetBundleCollector();
|
|
||||||
collector.CollectPath = levelDir;
|
|
||||||
collector.CollectorGUID = AssetDatabase.AssetPathToGUID(collector.CollectPath);
|
|
||||||
collector.CollectorType = ECollectorType.MainAssetCollector;
|
|
||||||
collector.AddressRuleName = nameof(AddressByFileName);
|
|
||||||
collector.PackRuleName = nameof(PackCollector);
|
|
||||||
collector.FilterRuleName = nameof(CollectAll);
|
|
||||||
collector.AssetTags = levelName;
|
|
||||||
|
|
||||||
group.Collectors.Add(collector);
|
|
||||||
package.Groups.Add(group);
|
|
||||||
|
|
||||||
setting.Packages.Add(package);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
var levelName = "ProfilesFeature";
|
||||||
//创建关卡缩略图package
|
|
||||||
for (int i = 0; i < (int)GamePlay.end; i++)
|
AssetBundleCollectorPackage package = new AssetBundleCollectorPackage();
|
||||||
{
|
package.PackageName = levelName;
|
||||||
GamePlay playType = (GamePlay)i;
|
package.PackageDesc = $"profile玩法资源包";
|
||||||
string dir = $"Assets/AssetRaw/UIRaw/Raw/Thum/{playType.ToString()}";
|
package.Groups = new List<AssetBundleCollectorGroup>();
|
||||||
if (!AssetDatabase.IsValidFolder(dir))
|
|
||||||
{
|
AssetBundleCollectorGroup group = new AssetBundleCollectorGroup();
|
||||||
Debug.LogError($"不存在的目录:{dir}");
|
group.GroupName = "default";
|
||||||
continue;
|
group.AssetTags = levelName;
|
||||||
}
|
group.ActiveRuleName = "EnableGroup";
|
||||||
|
group.Collectors = new List<AssetBundleCollector>();
|
||||||
var thumFiles = Directory.GetFiles(dir);
|
|
||||||
foreach (var thumFile in thumFiles)
|
AssetBundleCollector collector = new AssetBundleCollector();
|
||||||
{
|
collector.CollectPath = dir;
|
||||||
if(thumFile.EndsWith(".meta"))
|
collector.CollectorGUID = AssetDatabase.AssetPathToGUID(collector.CollectPath);
|
||||||
continue;
|
collector.CollectorType = ECollectorType.MainAssetCollector;
|
||||||
|
collector.AddressRuleName = nameof(AddressByFileName);
|
||||||
string levelName = Path.GetFileNameWithoutExtension(thumFile);
|
collector.PackRuleName = nameof(PackCollector);
|
||||||
AssetBundleCollectorPackage package = new AssetBundleCollectorPackage();
|
collector.FilterRuleName = nameof(CollectAll);
|
||||||
package.PackageName = levelName;
|
collector.AssetTags = levelName;
|
||||||
package.PackageDesc = $"{levelName}缩略图资源包";
|
|
||||||
package.Groups = new List<AssetBundleCollectorGroup>();
|
group.Collectors.Add(collector);
|
||||||
|
package.Groups.Add(group);
|
||||||
AssetBundleCollectorGroup group = new AssetBundleCollectorGroup();
|
|
||||||
group.GroupName = "default";
|
setting.Packages.Add(package);
|
||||||
group.AssetTags = levelName;
|
|
||||||
group.ActiveRuleName = "EnableGroup";
|
|
||||||
group.Collectors = new List<AssetBundleCollector>();
|
|
||||||
|
|
||||||
AssetBundleCollector collector = new AssetBundleCollector();
|
|
||||||
collector.CollectPath = thumFile;
|
|
||||||
collector.CollectorGUID = AssetDatabase.AssetPathToGUID(collector.CollectPath);
|
|
||||||
collector.CollectorType = ECollectorType.MainAssetCollector;
|
|
||||||
collector.AddressRuleName = nameof(AddressByFileName);
|
|
||||||
collector.PackRuleName = nameof(PackDirectory);
|
|
||||||
collector.FilterRuleName = nameof(CollectAll);
|
|
||||||
collector.AssetTags = levelName;
|
|
||||||
|
|
||||||
group.Collectors.Add(collector);
|
|
||||||
package.Groups.Add(group);
|
|
||||||
|
|
||||||
setting.Packages.Add(package);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
AssetDatabase.SaveAssetIfDirty(setting);
|
AssetDatabase.SaveAssetIfDirty(setting);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1,14 +0,0 @@
|
||||||
public enum GamePlay
|
|
||||||
{
|
|
||||||
main = 0, //主玩法
|
|
||||||
// thesmiths = 0, //史密斯一家
|
|
||||||
// retrocharm, //复古魅力
|
|
||||||
// animalparty, //动物派对
|
|
||||||
// trackhunt, //踪迹追寻
|
|
||||||
// doodledelight, //快乐涂鸦
|
|
||||||
// mysterymeow, //神秘猫咪
|
|
||||||
// tidyup, //整理房间
|
|
||||||
// colorfun, //填色乐趣
|
|
||||||
|
|
||||||
end, //始终放在最后
|
|
||||||
}
|
|
||||||
|
|
@ -1,3 +0,0 @@
|
||||||
fileFormatVersion: 2
|
|
||||||
guid: 2090a55aac6a473cb00da44087c5e38d
|
|
||||||
timeCreated: 1703643978
|
|
||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue