using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
namespace YooAsset.Editor
{
[CreateAssetMenu(fileName = "AssetBundleCollectorSetting", menuName = "YooAsset/Create AssetBundle Collector Settings")]
public class AssetBundleCollectorSetting : ScriptableObject
{
///
/// 显示包裹列表视图
///
public bool ShowPackageView = false;
///
/// 是否显示编辑器别名
///
public bool ShowEditorAlias = false;
///
/// 资源包名唯一化
///
public bool UniqueBundleName = false;
///
/// 包裹列表
///
public List Packages = new List();
///
/// 清空所有数据
///
public void ClearAll()
{
ShowPackageView = false;
UniqueBundleName = false;
ShowEditorAlias = false;
Packages.Clear();
}
///
/// 检测包裹配置错误
///
public void CheckPackageConfigError(string packageName)
{
var package = GetPackage(packageName);
package.CheckConfigError();
}
///
/// 检测所有配置错误
///
public void CheckAllPackageConfigError()
{
foreach (var package in Packages)
{
package.CheckConfigError();
}
}
///
/// 修复所有配置错误
///
public bool FixAllPackageConfigError()
{
bool isFixed = false;
foreach (var package in Packages)
{
if (package.FixConfigError())
{
isFixed = true;
}
}
return isFixed;
}
///
/// 获取所有的资源标签
///
public List GetPackageAllTags(string packageName)
{
var package = GetPackage(packageName);
return package.GetAllTags();
}
///
/// 获取包裹收集的资源文件
///
public CollectResult GetPackageAssets(EBuildMode buildMode, string packageName)
{
if (string.IsNullOrEmpty(packageName))
throw new Exception("Build package name is null or empty !");
// 检测配置合法性
var package = GetPackage(packageName);
package.CheckConfigError();
// 创建资源收集命令
IIgnoreRule ignoreRule = AssetBundleCollectorSettingData.GetIgnoreRuleInstance(package.IgnoreRuleName);
CollectCommand command = new CollectCommand(buildMode, packageName,
package.EnableAddressable,
package.LocationToLower,
package.IncludeAssetGUID,
package.AutoCollectShaders,
UniqueBundleName, ignoreRule);
// 获取收集的资源集合
CollectResult collectResult = new CollectResult(command);
collectResult.SetCollectAssets(package.GetAllCollectAssets(command));
return collectResult;
}
///
/// 获取包裹类
///
public AssetBundleCollectorPackage GetPackage(string packageName)
{
foreach (var package in Packages)
{
if (package.PackageName == packageName)
return package;
}
throw new Exception($"Not found package : {packageName}");
}
}
}