mirror of
https://github.com/tuyoogame/YooAsset.git
synced 2026-05-23 17:20:12 +00:00
Update AssetBundleBuilder
This commit is contained in:
@@ -1,102 +0,0 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace YooAsset.Editor
|
||||
{
|
||||
/// <summary>
|
||||
/// 构建的资源信息类
|
||||
/// </summary>
|
||||
[Serializable]
|
||||
public class BuildAssetInfo
|
||||
{
|
||||
/// <summary>
|
||||
/// 资源路径
|
||||
/// </summary>
|
||||
public string AssetPath;
|
||||
|
||||
/// <summary>
|
||||
/// 资源包完整名称
|
||||
/// </summary>
|
||||
public string BundleName;
|
||||
|
||||
/// <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;
|
||||
|
||||
|
||||
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(BundleName) == false)
|
||||
throw new System.Exception("Should never get here !");
|
||||
|
||||
BundleName = AssetBundleBuilderHelper.MakeBundleName(bundleLabel, 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 bool BundleNameIsValid()
|
||||
{
|
||||
if (string.IsNullOrEmpty(BundleName))
|
||||
return false;
|
||||
else
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,130 +0,0 @@
|
||||
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;
|
||||
|
||||
/// <summary>
|
||||
/// 包含的资源列表
|
||||
/// </summary>
|
||||
public 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 bundleName)
|
||||
{
|
||||
BundleName = bundleName;
|
||||
}
|
||||
|
||||
/// <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[] 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -19,7 +19,7 @@ namespace YooAsset.Editor
|
||||
/// <summary>
|
||||
/// 资源包列表
|
||||
/// </summary>
|
||||
public List<BuildBundleInfo> BundleInfos;
|
||||
public List<ReportBundleInfo> BundleInfos;
|
||||
|
||||
/// <summary>
|
||||
/// 冗余的资源列表
|
||||
@@ -35,5 +35,14 @@ namespace YooAsset.Editor
|
||||
string json = JsonUtility.ToJson(buildReport, true);
|
||||
FileUtility.CreateFile(savePath, json);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 反序列化
|
||||
/// </summary>
|
||||
public static BuildReport Deserialize(string jsonData)
|
||||
{
|
||||
BuildReport report = JsonUtility.FromJson<BuildReport>(jsonData);
|
||||
return report;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace YooAsset.Editor
|
||||
{
|
||||
[Serializable]
|
||||
public class ReportAssetInfo
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 447008dd110b8d746aafbe88c78bee5d
|
||||
guid: 3ef16d696d8ffbd488c27e539f1966ad
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
@@ -0,0 +1,12 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace YooAsset.Editor
|
||||
{
|
||||
[Serializable]
|
||||
public class ReportBundleInfo
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 826a9d7b4de0eba40b5c39b33747c011
|
||||
guid: 26aa55851e9252b4ab0655ee60526cb0
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
Reference in New Issue
Block a user