using System;
using System.Linq;
using System.Collections.Generic;
namespace YooAsset
{
[Serializable]
internal class PackageBundle
{
///
/// 资源包名称
///
public string BundleName;
///
/// Unity引擎生成的CRC
///
public uint UnityCRC;
///
/// 文件哈希值
///
public string FileHash;
///
/// 文件校验码
///
public string FileCRC;
///
/// 文件大小(字节数)
///
public long FileSize;
///
/// 文件是否加密
///
public bool Encrypted;
///
/// 资源包的分类标签
///
public string[] Tags;
///
/// 依赖的资源包ID集合
///
public int[] DependIDs;
///
/// 资源包GUID
///
public string BundleGUID
{
get { return FileHash; }
}
///
/// 资源包类型
///
private int _bundleType;
public int BundleType
{
get
{
return _bundleType;
}
}
///
/// 文件名称
///
private string _fileName;
public string FileName
{
get
{
if (string.IsNullOrEmpty(_fileName))
throw new Exception("Should never get here !");
return _fileName;
}
}
///
/// 文件后缀名
///
private string _fileExtension;
public string FileExtension
{
get
{
if (string.IsNullOrEmpty(_fileExtension))
throw new Exception("Should never get here !");
return _fileExtension;
}
}
///
/// 包含的主资源集合
///
[NonSerialized]
public readonly List IncludeMainAssets = new List(10);
public PackageBundle()
{
}
///
/// 初始化资源包
///
public void InitBundle(PackageManifest manifest)
{
_bundleType = manifest.BuildBundleType;
_fileExtension = ManifestTools.GetRemoteBundleFileExtension(BundleName);
_fileName = ManifestTools.GetRemoteBundleFileName(manifest.OutputNameStyle, BundleName, _fileExtension, FileHash);
}
///
/// 是否包含Tag
///
public bool HasTag(string[] tags)
{
if (tags == null || tags.Length == 0)
return false;
if (Tags == null || Tags.Length == 0)
return false;
foreach (var tag in tags)
{
if (Tags.Contains(tag))
return true;
}
return false;
}
///
/// 是否包含任意Tags
///
public bool HasAnyTags()
{
if (Tags != null && Tags.Length > 0)
return true;
else
return false;
}
///
/// 检测资源包文件内容是否相同
///
public bool Equals(PackageBundle otherBundle)
{
if (FileHash == otherBundle.FileHash)
return true;
return false;
}
}
}