mirror of
https://github.com/tuyoogame/YooAsset.git
synced 2026-05-23 09:10:11 +00:00
Update AssetBundleBuilder
This commit is contained in:
@@ -0,0 +1,119 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace YooAsset.Editor
|
||||
{
|
||||
/// <summary>
|
||||
/// 构建的资源信息类
|
||||
/// </summary>
|
||||
[Serializable]
|
||||
public class BuildAssetInfo
|
||||
{
|
||||
/// <summary>
|
||||
/// 资源路径
|
||||
/// </summary>
|
||||
public string AssetPath { private set; get; }
|
||||
|
||||
/// <summary>
|
||||
/// 资源包标签
|
||||
/// </summary>
|
||||
public string BundleLabel { private set; get; }
|
||||
|
||||
/// <summary>
|
||||
/// 资源包文件格式
|
||||
/// </summary>
|
||||
public string BundleVariant { private set; get; }
|
||||
|
||||
/// <summary>
|
||||
/// 是否为原生资源
|
||||
/// </summary>
|
||||
public bool IsRawAsset = false;
|
||||
|
||||
/// <summary>
|
||||
/// 是否为主动收集资源
|
||||
/// </summary>
|
||||
public bool IsCollectAsset = false;
|
||||
|
||||
/// <summary>
|
||||
/// 资源标记列表
|
||||
/// </summary>
|
||||
public List<string> AssetTags = new List<string>();
|
||||
|
||||
/// <summary>
|
||||
/// 被依赖次数
|
||||
/// </summary>
|
||||
public int DependCount = 0;
|
||||
|
||||
/// <summary>
|
||||
/// 依赖的所有资源信息
|
||||
/// 注意:包括零依赖资源(零依赖资源的资源包名无效)
|
||||
/// </summary>
|
||||
public List<BuildAssetInfo> AllDependAssetInfos { private set; get; } = null;
|
||||
|
||||
|
||||
public BuildAssetInfo(string assetPath)
|
||||
{
|
||||
AssetPath = assetPath;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 设置所有依赖的资源
|
||||
/// </summary>
|
||||
public void SetAllDependAssetInfos(List<BuildAssetInfo> dependAssetInfos)
|
||||
{
|
||||
if (AllDependAssetInfos != null)
|
||||
throw new System.Exception("Should never get here !");
|
||||
|
||||
AllDependAssetInfos = dependAssetInfos;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 设置资源包的标签和文件格式
|
||||
/// </summary>
|
||||
public void SetBundleLabelAndVariant(string bundleLabel, string bundleVariant)
|
||||
{
|
||||
if (string.IsNullOrEmpty(BundleLabel) == false || string.IsNullOrEmpty(BundleVariant) == false)
|
||||
throw new System.Exception("Should never get here !");
|
||||
|
||||
BundleLabel = bundleLabel;
|
||||
BundleVariant = bundleVariant;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 添加资源标记
|
||||
/// </summary>
|
||||
public void AddAssetTags(List<string> tags)
|
||||
{
|
||||
foreach (var tag in tags)
|
||||
{
|
||||
if (AssetTags.Contains(tag) == false)
|
||||
{
|
||||
AssetTags.Add(tag);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取资源包的完整名称
|
||||
/// </summary>
|
||||
public string GetBundleName()
|
||||
{
|
||||
if (string.IsNullOrEmpty(BundleLabel) || string.IsNullOrEmpty(BundleVariant))
|
||||
throw new System.ArgumentNullException();
|
||||
|
||||
return AssetBundleBuilderHelper.MakeBundleName(BundleLabel, BundleVariant);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 检测资源包名是否有效
|
||||
/// </summary>
|
||||
public bool CheckBundleNameValid()
|
||||
{
|
||||
if (string.IsNullOrEmpty(BundleLabel) == false && string.IsNullOrEmpty(BundleVariant) == false)
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 447008dd110b8d746aafbe88c78bee5d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,150 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEditor;
|
||||
|
||||
namespace YooAsset.Editor
|
||||
{
|
||||
/// <summary>
|
||||
/// 构建的资源包信息类
|
||||
/// </summary>
|
||||
[Serializable]
|
||||
public class BuildBundleInfo
|
||||
{
|
||||
/// <summary>
|
||||
/// 资源包完整名称
|
||||
/// </summary>
|
||||
public string BundleName { private set; get; }
|
||||
|
||||
/// <summary>
|
||||
/// 资源包标签名
|
||||
/// </summary>
|
||||
public string BundleLabel { private set; get; }
|
||||
|
||||
/// <summary>
|
||||
/// 资源包文件格式
|
||||
/// </summary>
|
||||
public string BundleVariant { private set; get; }
|
||||
|
||||
/// <summary>
|
||||
/// 包含的资源列表
|
||||
/// </summary>
|
||||
public readonly List<BuildAssetInfo> Assets = new List<BuildAssetInfo>();
|
||||
|
||||
/// <summary>
|
||||
/// 是否为原生文件
|
||||
/// </summary>
|
||||
public bool IsRawFile
|
||||
{
|
||||
get
|
||||
{
|
||||
foreach (var asset in Assets)
|
||||
{
|
||||
if (asset.IsRawAsset)
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public BuildBundleInfo(string bundleLabel, string bundleVariant)
|
||||
{
|
||||
BundleLabel = bundleLabel;
|
||||
BundleVariant = bundleVariant;
|
||||
BundleName = AssetBundleBuilderHelper.MakeBundleName(bundleLabel, bundleVariant);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 是否包含指定资源
|
||||
/// </summary>
|
||||
public bool IsContainsAsset(string assetPath)
|
||||
{
|
||||
foreach (var assetInfo in Assets)
|
||||
{
|
||||
if (assetInfo.AssetPath == assetPath)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 添加一个打包资源
|
||||
/// </summary>
|
||||
public void PackAsset(BuildAssetInfo assetInfo)
|
||||
{
|
||||
if (IsContainsAsset(assetInfo.AssetPath))
|
||||
throw new System.Exception($"Asset is existed : {assetInfo.AssetPath}");
|
||||
|
||||
Assets.Add(assetInfo);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取文件的扩展名
|
||||
/// </summary>
|
||||
public string GetAppendExtension()
|
||||
{
|
||||
if (IsRawFile)
|
||||
return $".{ResourceSettingData.Setting.RawFileVariant}";
|
||||
else
|
||||
return $".{ResourceSettingData.Setting.AssetBundleFileVariant}";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取资源标记列表
|
||||
/// </summary>
|
||||
public string[] GetAssetTags()
|
||||
{
|
||||
List<string> result = new List<string>(Assets.Count);
|
||||
foreach (var assetInfo in Assets)
|
||||
{
|
||||
foreach (var assetTag in assetInfo.AssetTags)
|
||||
{
|
||||
if (result.Contains(assetTag) == false)
|
||||
result.Add(assetTag);
|
||||
}
|
||||
}
|
||||
return result.ToArray();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取主动收集的资源路径列表
|
||||
/// </summary>
|
||||
public string[] GetCollectAssetPaths()
|
||||
{
|
||||
return Assets.Where(t => t.IsCollectAsset).Select(t => t.AssetPath).ToArray();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取构建的资源路径列表
|
||||
/// </summary>
|
||||
public string[] GetBuildinAssetPaths()
|
||||
{
|
||||
return Assets.Select(t => t.AssetPath).ToArray();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取主动收集的资源信息列表
|
||||
/// </summary>
|
||||
public BuildAssetInfo[] GetCollectAssetInfos()
|
||||
{
|
||||
return Assets.Where(t => t.IsCollectAsset).ToArray();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 创建AssetBundleBuild类
|
||||
/// </summary>
|
||||
public UnityEditor.AssetBundleBuild CreatePipelineBuild()
|
||||
{
|
||||
// 注意:我们不在支持AssetBundle的变种机制
|
||||
AssetBundleBuild build = new AssetBundleBuild();
|
||||
build.assetBundleName = BundleName;
|
||||
build.assetBundleVariant = string.Empty;
|
||||
build.assetNames = GetBuildinAssetPaths();
|
||||
return build;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 826a9d7b4de0eba40b5c39b33747c011
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,17 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
/// <summary>
|
||||
/// 构建报告
|
||||
/// </summary>
|
||||
[Serializable]
|
||||
public class BuildReport
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0f35afda8a63f874fb78877d65dafdd2
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user