| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200 |
- using System;
- using System.Linq;
- using System.Collections.Generic;
- namespace YooAsset
- {
- [Serializable]
- internal class PackageBundle
- {
- /// <summary>
- /// 资源包名称
- /// </summary>
- public string BundleName;
- /// <summary>
- /// Unity引擎生成的CRC
- /// </summary>
- public uint UnityCRC;
- /// <summary>
- /// 文件哈希值
- /// </summary>
- public string FileHash;
- /// <summary>
- /// 文件校验码
- /// </summary>
- public string FileCRC;
- /// <summary>
- /// 文件大小(字节数)
- /// </summary>
- public long FileSize;
- /// <summary>
- /// 文件是否加密
- /// </summary>
- public bool Encrypted;
- /// <summary>
- /// 资源包的分类标签
- /// </summary>
- public string[] Tags;
- /// <summary>
- /// 依赖的资源包ID集合
- /// 注意:引擎层构建查询结果
- /// </summary>
- public int[] DependBundleIDs;
- /// <summary>
- /// 资源包GUID
- /// </summary>
- public string BundleGUID
- {
- get { return FileHash; }
- }
- /// <summary>
- /// 资源包类型
- /// </summary>
- public int BundleType
- {
- get
- {
- return _bundleType;
- }
- }
- private int _bundleType;
- /// <summary>
- /// 文件名称
- /// </summary>
- public string FileName
- {
- get
- {
- if (string.IsNullOrEmpty(_fileName))
- throw new Exception("Should never get here !");
- return _fileName;
- }
- }
- private string _fileName;
- /// <summary>
- /// 文件后缀名
- /// </summary>
- public string FileExtension
- {
- get
- {
- if (string.IsNullOrEmpty(_fileExtension))
- throw new Exception("Should never get here !");
- return _fileExtension;
- }
- }
- private string _fileExtension;
- /// <summary>
- /// 包含的主资源集合
- /// </summary>
- [NonSerialized]
- public readonly List<PackageAsset> IncludeMainAssets = new List<PackageAsset>(10);
- /// <summary>
- /// 引用该资源包的资源包列表
- /// 说明:谁引用了该资源包
- /// </summary>
- [NonSerialized]
- public readonly List<int> ReferenceBundleIDs = new List<int>(10);
- private readonly HashSet<int> _referenceBundleIDs = new HashSet<int>();
- public PackageBundle()
- {
- }
- /// <summary>
- /// 初始化资源包
- /// </summary>
- public void InitBundle(PackageManifest manifest)
- {
- _mainfest = manifest;
- _bundleType = manifest.BuildBundleType;
- _fileExtension = ManifestTools.GetRemoteBundleFileExtension(BundleName);
- _fileName = ManifestTools.GetRemoteBundleFileName(manifest.OutputNameStyle, BundleName, _fileExtension, FileHash);
- }
- /// <summary>
- /// 添加引用该资源包的资源包ID
- /// 说明:谁引用了该资源包
- /// </summary>
- public void AddReferenceBundleID(int bundleID)
- {
- if (_referenceBundleIDs.Contains(bundleID) == false)
- {
- _referenceBundleIDs.Add(bundleID);
- ReferenceBundleIDs.Add(bundleID);
- }
- }
- /// <summary>
- /// 是否包含Tag
- /// </summary>
- 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;
- }
- /// <summary>
- /// 是否包含任意Tags
- /// </summary>
- public bool HasAnyTags()
- {
- if (Tags != null && Tags.Length > 0)
- return true;
- else
- return false;
- }
- /// <summary>
- /// 检测资源包文件内容是否相同
- /// </summary>
- public bool Equals(PackageBundle otherBundle)
- {
- if (FileHash == otherBundle.FileHash)
- return true;
- return false;
- }
- #region 调试信息
- private PackageManifest _mainfest;
- private List<string> _debugReferenceBundles;
- public List<string> GetDebugReferenceBundles()
- {
- if (_debugReferenceBundles == null)
- {
- _debugReferenceBundles = new List<string>(ReferenceBundleIDs.Count);
- foreach (int bundleID in ReferenceBundleIDs)
- {
- var packageBundle = _mainfest.BundleList[bundleID];
- _debugReferenceBundles.Add(packageBundle.BundleName);
- }
- }
- return _debugReferenceBundles;
- }
- #endregion
- }
- }
|