102 lines
3.9 KiB
C#
102 lines
3.9 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using JD.Core.ProjectManaging;
|
|
using NUnit.Framework;
|
|
using Packager.Parameters;
|
|
|
|
namespace Packager.Tasks
|
|
{
|
|
/// <summary>
|
|
/// Assign ZipAssestListWithBundleName to true when the assets list and the bundle name has to be tied together before the execution starts
|
|
/// </summary>
|
|
[DisplayName(@"Build Bundle")]
|
|
public class BundlingTask : AssetCookerTask
|
|
{
|
|
[Input("Asset Files List", IOCardinality.Multi, IOType.File)]
|
|
public ReferenceList AssetsList { get; set; }
|
|
|
|
[Input("Remove Asset Files List", IOCardinality.Multi, IOType.File, Flags = InputFlags.Optional)]
|
|
public ReferenceList RemoveAssetsList { get; set; }
|
|
|
|
[Input("Bundle Name", IOCardinality.Single, IOType.String)]
|
|
public ReferenceList BundleName { get; set; }
|
|
|
|
[Input("Suffix", IOCardinality.Single, IOType.String, Flags = InputFlags.Optional)]
|
|
public SingleReference Suffix { get; set; }
|
|
|
|
[Input("Zip AssestList and BundleName ", IOCardinality.Multi, IOType.String, Flags = InputFlags.Optional)]
|
|
public SingleReference ZipAssestListWithBundleName { get; set; }
|
|
|
|
private bool _zipAssestListWithBundleName;
|
|
|
|
[Output(nameof(BundlePaths), IOType.File)]
|
|
public ReferenceList BundlePaths = new ReferenceList();
|
|
|
|
public BundlingTask()
|
|
{
|
|
AssetsList = new ReferenceList();
|
|
RemoveAssetsList = new ReferenceList();
|
|
BundleName = new ReferenceList();
|
|
Suffix = new SingleReference();
|
|
ZipAssestListWithBundleName = new SingleReference();
|
|
|
|
Unique = true;
|
|
CookList = true;
|
|
Hidden = true;
|
|
}
|
|
|
|
protected override void StartInternal(BuildConfiguration profile, cookerWrapper cooker)
|
|
{
|
|
MergeList = CreateMergeFile(AssetsList);
|
|
ExcludeFiles = CreateMergeFile(RemoveAssetsList);
|
|
_zipAssestListWithBundleName = string.Compare(ZipAssestListWithBundleName.Value, "true", StringComparison.CurrentCultureIgnoreCase) == 0;
|
|
|
|
if (BundleName.Count > 0)
|
|
{
|
|
if (!_zipAssestListWithBundleName)
|
|
{
|
|
foreach (var name in BundleName)
|
|
{
|
|
RunAssetCooker(profile, name);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (AssetsList.Count != BundleName.Count)
|
|
{
|
|
Logger.LogWarning($"The '{nameof(AssetsList)}' collection contains {AssetsList.Count} items, " +
|
|
$"but the '{nameof(BundleName)}' collection contains {BundleName.Count} items. " +
|
|
$"{Math.Abs(AssetsList.Count - BundleName.Count)} items will be ignored.");
|
|
}
|
|
|
|
var assetsAndBundles = AssetsList.Zip(BundleName,(assetName, bundleName) => new {AssetName = assetName, BundleName = bundleName});
|
|
foreach (var element in assetsAndBundles)
|
|
{
|
|
MergeList = CreateMergeFile(new List<string> {element.AssetName});
|
|
RunAssetCooker(profile, element.BundleName);
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
Start(profile);
|
|
}
|
|
}
|
|
|
|
protected void RunAssetCooker(BuildConfiguration profile, string bundleName)
|
|
{
|
|
string suffix = "";
|
|
|
|
if (!string.IsNullOrEmpty(Suffix.Value))
|
|
suffix = "_" + Suffix.Value;
|
|
|
|
BundleFile = Path.Combine(TaskOutputFolder, bundleName);
|
|
BundleFile += suffix;
|
|
Start(profile);
|
|
BundlePaths.Add($"{BundleFile}_{profile.PlatformList[0]}.ipk");
|
|
}
|
|
}
|
|
}
|