修改unity的资源打包逻辑
parent
a69cfc43dd
commit
eea0b0ca83
|
|
@ -1,6 +1,7 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 3f1ca26670fc7465ea399367ef61f8e1
|
||||
TextScriptImporter:
|
||||
guid: d0e56056744c24b1e80b40d8fda28606
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
|
|
@ -1 +0,0 @@
|
|||
项目AB资源软链接文件夹(和资源工程文件夹名称保持一致)
|
||||
|
|
@ -42,24 +42,25 @@ public static class BuildBundlesHelper
|
|||
[MenuItem("Tools/TestBuildBundles")]
|
||||
public static void TestBuildBundles()
|
||||
{
|
||||
|
||||
Debug.LogWarning("MakeAtlas Start ==================");
|
||||
MakeAtlas();
|
||||
AssetDatabase.Refresh();
|
||||
Debug.LogWarning("MakeAtlas End ==================");
|
||||
|
||||
|
||||
Debug.LogWarning("Create YooAsset Package Start ==========");
|
||||
CreateYooAssetPackage();
|
||||
AssetDatabase.Refresh();
|
||||
Debug.LogWarning("Create YooAsset Package End ==========");
|
||||
|
||||
|
||||
Debug.LogWarning("BuildBundles Start ==================");
|
||||
AssetBundleCollectorSetting setting = AssetDatabase.LoadAssetAtPath<AssetBundleCollectorSetting>("Assets/AssetBundleCollectorSetting.asset");
|
||||
AssetBundleCollectorSetting setting =
|
||||
AssetDatabase.LoadAssetAtPath<AssetBundleCollectorSetting>("Assets/AssetBundleCollectorSetting.asset");
|
||||
if (setting == null)
|
||||
{
|
||||
Debug.LogError("不存在的AssetBundleCollectorSetting.asset");
|
||||
return;
|
||||
}
|
||||
|
||||
var bundleBuilder = new AssetBundleBuilder();
|
||||
BuildParameters buildParameters = GetParametersFromParams(BuildTarget.Android, "1.0.0");
|
||||
string outputDir = $"{buildParameters.BuildOutputRoot}/{buildParameters.BuildTarget.ToString()}";
|
||||
|
|
@ -70,12 +71,13 @@ public static class BuildBundlesHelper
|
|||
for (int i = 0; i < setting.Packages.Count; i++)
|
||||
{
|
||||
var package = setting.Packages[i];
|
||||
if(package.PackageName == "DefaultPackage")
|
||||
if (package.PackageName == "DefaultPackage")
|
||||
continue;
|
||||
|
||||
buildParameters.PackageName = package.PackageName;
|
||||
bundleBuilder.Run(buildParameters);
|
||||
}
|
||||
|
||||
Debug.LogWarning("BuildBundles End ==================");
|
||||
}
|
||||
|
||||
|
|
@ -85,19 +87,21 @@ public static class BuildBundlesHelper
|
|||
MakeAtlas();
|
||||
AssetDatabase.Refresh();
|
||||
Debug.LogWarning("MakeAtlas End ==================");
|
||||
|
||||
|
||||
Debug.LogWarning("Create YooAsset Package Start ==========");
|
||||
CreateYooAssetPackage();
|
||||
AssetDatabase.Refresh();
|
||||
Debug.LogWarning("Create YooAsset Package End ==========");
|
||||
|
||||
|
||||
Debug.LogWarning("BuildBundles Start ==================");
|
||||
AssetBundleCollectorSetting setting = AssetDatabase.LoadAssetAtPath<AssetBundleCollectorSetting>("Assets/AssetBundleCollectorSetting.asset");
|
||||
AssetBundleCollectorSetting setting =
|
||||
AssetDatabase.LoadAssetAtPath<AssetBundleCollectorSetting>("Assets/AssetBundleCollectorSetting.asset");
|
||||
if (setting == null)
|
||||
{
|
||||
Debug.LogError("不存在的AssetBundleCollectorSetting.asset");
|
||||
return;
|
||||
}
|
||||
|
||||
BuildParams bp = BuildParamsHelper.GetBuildParams();
|
||||
bp.Description();
|
||||
var bundleBuilder = new AssetBundleBuilder();
|
||||
|
|
@ -111,113 +115,70 @@ public static class BuildBundlesHelper
|
|||
Debug.LogError($"不支持的平台:{bp.Platform}");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
string outputDir = $"{buildParameters.BuildOutputRoot}/{buildParameters.BuildTarget.ToString()}";
|
||||
Debug.LogError($"bundle资源输出目录:{outputDir}");
|
||||
if (Directory.Exists(outputDir))
|
||||
Directory.Delete(outputDir, true);
|
||||
|
||||
|
||||
for (int i = 0; i < setting.Packages.Count; i++)
|
||||
{
|
||||
var package = setting.Packages[i];
|
||||
if(package.PackageName == "DefaultPackage")
|
||||
if (package.PackageName == "DefaultPackage")
|
||||
continue;
|
||||
|
||||
buildParameters.PackageName = package.PackageName;
|
||||
bundleBuilder.Run(buildParameters);
|
||||
}
|
||||
|
||||
Debug.LogWarning("BuildBundles End ==================> exe");
|
||||
}
|
||||
|
||||
#region 创建图集
|
||||
|
||||
|
||||
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;
|
||||
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);
|
||||
}
|
||||
Debug.LogError($"不存在的目录:{dir}");
|
||||
}
|
||||
|
||||
MakeAtlas(dir);
|
||||
}
|
||||
|
||||
private static void MakeItemAtlas(string dirPath, string levelName)
|
||||
|
||||
private static void MakeAtlas(string dirPath)
|
||||
{
|
||||
string[] allPics = Directory.GetFiles(dirPath, "*.png", SearchOption.TopDirectoryOnly);
|
||||
if (allPics.Length == 0)
|
||||
{
|
||||
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}");
|
||||
Debug.LogError($"不存在的图:{dirPath}");
|
||||
return;
|
||||
}
|
||||
|
||||
List<Sprite> sprites = new List<Sprite>();
|
||||
foreach (var picPath in allPics)
|
||||
{
|
||||
if(picPath.EndsWith(".meta"))
|
||||
if (picPath.EndsWith(".meta"))
|
||||
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);
|
||||
if (sprite != null)
|
||||
{
|
||||
sprites.Add(sprite);
|
||||
}
|
||||
sprites.Add(sprite);
|
||||
}
|
||||
}
|
||||
AtlasUtils.CreateAtlas($"{levelName}_atlasLevel", sprites, levelDir);
|
||||
|
||||
Debug.LogError(sprites.Count);
|
||||
AtlasUtils.CreateAtlas($"profile", sprites, dirPath);
|
||||
}
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
private static void CreateYooAssetPackage()
|
||||
{
|
||||
AssetBundleCollectorSetting setting = AssetDatabase.LoadAssetAtPath<AssetBundleCollectorSetting>("Assets/AssetBundleCollectorSetting.asset");
|
||||
AssetBundleCollectorSetting setting =
|
||||
AssetDatabase.LoadAssetAtPath<AssetBundleCollectorSetting>("Assets/AssetBundleCollectorSetting.asset");
|
||||
if (setting == null)
|
||||
{
|
||||
Debug.LogError("不存在的AssetBundleCollectorSetting.asset");
|
||||
|
|
@ -227,101 +188,48 @@ public static class BuildBundlesHelper
|
|||
//重置配置
|
||||
for (int i = 0; i < setting.Packages.Count; i++)
|
||||
{
|
||||
if(setting.Packages[i].PackageName == "DefaultPackage")
|
||||
if (setting.Packages[i].PackageName == "DefaultPackage")
|
||||
continue;
|
||||
|
||||
|
||||
setting.Packages.RemoveAt(i);
|
||||
i--;
|
||||
}
|
||||
|
||||
Debug.Log($"packge count:{setting.Packages.Count}");
|
||||
|
||||
|
||||
//创建关卡资源package
|
||||
for (int i = 0; i < (int)GamePlay.end; i++)
|
||||
string dir = $"Assets/AssetRaw/UIRaw";
|
||||
if (!AssetDatabase.IsValidFolder(dir))
|
||||
{
|
||||
GamePlay playType = (GamePlay)i;
|
||||
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);
|
||||
}
|
||||
Debug.LogError($"不存在的目录:{dir}");
|
||||
}
|
||||
|
||||
//创建关卡缩略图package
|
||||
for (int i = 0; i < (int)GamePlay.end; i++)
|
||||
{
|
||||
GamePlay playType = (GamePlay)i;
|
||||
string dir = $"Assets/AssetRaw/UIRaw/Raw/Thum/{playType.ToString()}";
|
||||
if (!AssetDatabase.IsValidFolder(dir))
|
||||
{
|
||||
Debug.LogError($"不存在的目录:{dir}");
|
||||
continue;
|
||||
}
|
||||
|
||||
var thumFiles = Directory.GetFiles(dir);
|
||||
foreach (var thumFile in thumFiles)
|
||||
{
|
||||
if(thumFile.EndsWith(".meta"))
|
||||
continue;
|
||||
|
||||
string levelName = Path.GetFileNameWithoutExtension(thumFile);
|
||||
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 = 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);
|
||||
}
|
||||
}
|
||||
|
||||
var levelName = "ProfilesFeature";
|
||||
|
||||
AssetBundleCollectorPackage package = new AssetBundleCollectorPackage();
|
||||
package.PackageName = levelName;
|
||||
package.PackageDesc = $"profile玩法资源包";
|
||||
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 = dir;
|
||||
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);
|
||||
|
||||
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