mirror of https://github.com/tuyoogame/YooAsset
parent
d2b38cbc1b
commit
b0ce14dc0e
|
@ -254,6 +254,29 @@ namespace YooAsset
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public virtual byte[] ReadFileData(PackageBundle bundle)
|
||||||
|
{
|
||||||
|
if (NeedUnpack(bundle))
|
||||||
|
return _unpackFileSystem.ReadFileData(bundle);
|
||||||
|
|
||||||
|
if (Exists(bundle) == false)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
string filePath = GetBuildinFileLoadPath(bundle);
|
||||||
|
return FileUtility.ReadAllBytes(filePath);
|
||||||
|
}
|
||||||
|
public virtual string ReadFileText(PackageBundle bundle)
|
||||||
|
{
|
||||||
|
if (NeedUnpack(bundle))
|
||||||
|
return _unpackFileSystem.ReadFileText(bundle);
|
||||||
|
|
||||||
|
if (Exists(bundle) == false)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
string filePath = GetBuildinFileLoadPath(bundle);
|
||||||
|
return FileUtility.ReadAllText(filePath);
|
||||||
|
}
|
||||||
|
|
||||||
#region 内部方法
|
#region 内部方法
|
||||||
protected string GetDefaultRoot()
|
protected string GetDefaultRoot()
|
||||||
{
|
{
|
||||||
|
|
|
@ -111,7 +111,6 @@ namespace YooAsset
|
||||||
{
|
{
|
||||||
None,
|
None,
|
||||||
LoadBuildinRawBundle,
|
LoadBuildinRawBundle,
|
||||||
CheckLoadBuildinResult,
|
|
||||||
Done,
|
Done,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -139,32 +138,17 @@ namespace YooAsset
|
||||||
if (_steps == ESteps.LoadBuildinRawBundle)
|
if (_steps == ESteps.LoadBuildinRawBundle)
|
||||||
{
|
{
|
||||||
string filePath = _fileSystem.GetBuildinFileLoadPath(_bundle);
|
string filePath = _fileSystem.GetBuildinFileLoadPath(_bundle);
|
||||||
Result = filePath;
|
if (File.Exists(filePath))
|
||||||
_steps = ESteps.CheckLoadBuildinResult;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (_steps == ESteps.CheckLoadBuildinResult)
|
|
||||||
{
|
|
||||||
if (Result != null)
|
|
||||||
{
|
{
|
||||||
string filePath = Result as string;
|
_steps = ESteps.Done;
|
||||||
if (File.Exists(filePath))
|
Result = new RawBundle(_fileSystem, _bundle, filePath);
|
||||||
{
|
Status = EOperationStatus.Succeed;
|
||||||
_steps = ESteps.Done;
|
|
||||||
Status = EOperationStatus.Succeed;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
_steps = ESteps.Done;
|
|
||||||
Status = EOperationStatus.Failed;
|
|
||||||
Error = $"Can not found buildin raw bundle file : {filePath}";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
_steps = ESteps.Done;
|
_steps = ESteps.Done;
|
||||||
Status = EOperationStatus.Failed;
|
Status = EOperationStatus.Failed;
|
||||||
Error = $"Failed to load buildin raw bundle file : {_bundle.BundleName}";
|
Error = $"Can not found buildin raw bundle file : {filePath}";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -303,6 +303,23 @@ namespace YooAsset
|
||||||
return Exists(bundle) == false;
|
return Exists(bundle) == false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public virtual byte[] ReadFileData(PackageBundle bundle)
|
||||||
|
{
|
||||||
|
if (Exists(bundle) == false)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
string filePath = GetCacheFileLoadPath(bundle);
|
||||||
|
return FileUtility.ReadAllBytes(filePath);
|
||||||
|
}
|
||||||
|
public virtual string ReadFileText(PackageBundle bundle)
|
||||||
|
{
|
||||||
|
if (Exists(bundle) == false)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
string filePath = GetCacheFileLoadPath(bundle);
|
||||||
|
return FileUtility.ReadAllText(filePath);
|
||||||
|
}
|
||||||
|
|
||||||
#region 内部方法
|
#region 内部方法
|
||||||
private readonly BufferWriter _sharedBuffer = new BufferWriter(1024);
|
private readonly BufferWriter _sharedBuffer = new BufferWriter(1024);
|
||||||
public void WriteInfoFile(string filePath, string dataFileCRC, long dataFileSize)
|
public void WriteInfoFile(string filePath, string dataFileCRC, long dataFileSize)
|
||||||
|
@ -368,7 +385,7 @@ namespace YooAsset
|
||||||
}
|
}
|
||||||
return filePath;
|
return filePath;
|
||||||
}
|
}
|
||||||
public string GetFileLoadPath(PackageBundle bundle)
|
public string GetCacheFileLoadPath(PackageBundle bundle)
|
||||||
{
|
{
|
||||||
return GetDataFilePath(bundle);
|
return GetDataFilePath(bundle);
|
||||||
}
|
}
|
||||||
|
|
|
@ -78,7 +78,7 @@ namespace YooAsset
|
||||||
|
|
||||||
if (_steps == ESteps.LoadAssetBundle)
|
if (_steps == ESteps.LoadAssetBundle)
|
||||||
{
|
{
|
||||||
string filePath = _fileSystem.GetFileLoadPath(_bundle);
|
string filePath = _fileSystem.GetCacheFileLoadPath(_bundle);
|
||||||
if (_isWaitForAsyncComplete)
|
if (_isWaitForAsyncComplete)
|
||||||
{
|
{
|
||||||
Result = AssetBundle.LoadFromFile(filePath);
|
Result = AssetBundle.LoadFromFile(filePath);
|
||||||
|
@ -122,7 +122,7 @@ namespace YooAsset
|
||||||
{
|
{
|
||||||
// 注意:在安卓移动平台,华为和三星真机上有极小概率加载资源包失败。
|
// 注意:在安卓移动平台,华为和三星真机上有极小概率加载资源包失败。
|
||||||
// 说明:大多数情况在首次安装下载资源到沙盒内,游戏过程中切换到后台再回到游戏内有很大概率触发!
|
// 说明:大多数情况在首次安装下载资源到沙盒内,游戏过程中切换到后台再回到游戏内有很大概率触发!
|
||||||
string filePath = _fileSystem.GetFileLoadPath(_bundle);
|
string filePath = _fileSystem.GetCacheFileLoadPath(_bundle);
|
||||||
byte[] fileData = FileUtility.ReadAllBytes(filePath);
|
byte[] fileData = FileUtility.ReadAllBytes(filePath);
|
||||||
if (fileData != null && fileData.Length > 0)
|
if (fileData != null && fileData.Length > 0)
|
||||||
{
|
{
|
||||||
|
@ -165,7 +165,7 @@ namespace YooAsset
|
||||||
|
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
if(_downloadFileOp != null)
|
if (_downloadFileOp != null)
|
||||||
_downloadFileOp.WaitForAsyncComplete();
|
_downloadFileOp.WaitForAsyncComplete();
|
||||||
|
|
||||||
if (ExecuteWhileDone())
|
if (ExecuteWhileDone())
|
||||||
|
@ -195,8 +195,7 @@ namespace YooAsset
|
||||||
None,
|
None,
|
||||||
CheckExist,
|
CheckExist,
|
||||||
DownloadFile,
|
DownloadFile,
|
||||||
LoadRawBundle,
|
LoadCacheRawBundle,
|
||||||
CheckResult,
|
|
||||||
Done,
|
Done,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -226,7 +225,7 @@ namespace YooAsset
|
||||||
{
|
{
|
||||||
DownloadProgress = 1f;
|
DownloadProgress = 1f;
|
||||||
DownloadedBytes = _bundle.FileSize;
|
DownloadedBytes = _bundle.FileSize;
|
||||||
_steps = ESteps.LoadRawBundle;
|
_steps = ESteps.LoadCacheRawBundle;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -249,7 +248,7 @@ namespace YooAsset
|
||||||
|
|
||||||
if (_downloadFileOp.Status == EOperationStatus.Succeed)
|
if (_downloadFileOp.Status == EOperationStatus.Succeed)
|
||||||
{
|
{
|
||||||
_steps = ESteps.LoadRawBundle;
|
_steps = ESteps.LoadCacheRawBundle;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -259,35 +258,20 @@ namespace YooAsset
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_steps == ESteps.LoadRawBundle)
|
if (_steps == ESteps.LoadCacheRawBundle)
|
||||||
{
|
{
|
||||||
string filePath = _fileSystem.GetFileLoadPath(_bundle);
|
string filePath = _fileSystem.GetCacheFileLoadPath(_bundle);
|
||||||
Result = filePath;
|
if (File.Exists(filePath))
|
||||||
_steps = ESteps.CheckResult;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (_steps == ESteps.CheckResult)
|
|
||||||
{
|
|
||||||
if (Result != null)
|
|
||||||
{
|
{
|
||||||
string filePath = Result as string;
|
_steps = ESteps.Done;
|
||||||
if (File.Exists(filePath))
|
Result = new RawBundle(_fileSystem, _bundle, filePath);
|
||||||
{
|
Status = EOperationStatus.Succeed;
|
||||||
_steps = ESteps.Done;
|
|
||||||
Status = EOperationStatus.Succeed;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
_steps = ESteps.Done;
|
|
||||||
Status = EOperationStatus.Failed;
|
|
||||||
Error = $"Can not found cache raw bundle file : {filePath}";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
_steps = ESteps.Done;
|
_steps = ESteps.Done;
|
||||||
Status = EOperationStatus.Failed;
|
Status = EOperationStatus.Failed;
|
||||||
Error = $"Failed to load cache raw bundle file : {_bundle.BundleName}";
|
Error = $"Can not found cache raw bundle file : {filePath}";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -135,6 +135,15 @@ namespace YooAsset
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public virtual byte[] ReadFileData(PackageBundle bundle)
|
||||||
|
{
|
||||||
|
throw new System.NotImplementedException();
|
||||||
|
}
|
||||||
|
public virtual string ReadFileText(PackageBundle bundle)
|
||||||
|
{
|
||||||
|
throw new System.NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
#region 内部方法
|
#region 内部方法
|
||||||
protected string GetDefaultRoot()
|
protected string GetDefaultRoot()
|
||||||
{
|
{
|
||||||
|
|
|
@ -157,6 +157,15 @@ namespace YooAsset
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public virtual byte[] ReadFileData(PackageBundle bundle)
|
||||||
|
{
|
||||||
|
throw new System.NotImplementedException();
|
||||||
|
}
|
||||||
|
public virtual string ReadFileText(PackageBundle bundle)
|
||||||
|
{
|
||||||
|
throw new System.NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
#region 内部方法
|
#region 内部方法
|
||||||
protected string GetDefaultWebRoot()
|
protected string GetDefaultWebRoot()
|
||||||
{
|
{
|
||||||
|
|
|
@ -100,5 +100,16 @@ namespace YooAsset
|
||||||
/// 是否需要导入
|
/// 是否需要导入
|
||||||
/// </summary>
|
/// </summary>
|
||||||
bool NeedImport(PackageBundle bundle);
|
bool NeedImport(PackageBundle bundle);
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 读取文件二进制数据
|
||||||
|
/// </summary>
|
||||||
|
byte[] ReadFileData(PackageBundle bundle);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 读取文件文本数据
|
||||||
|
/// </summary>
|
||||||
|
string ReadFileText(PackageBundle bundle);
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -72,8 +72,7 @@ namespace YooAsset
|
||||||
{
|
{
|
||||||
if (IsValidWithWarning == false)
|
if (IsValidWithWarning == false)
|
||||||
return null;
|
return null;
|
||||||
string filePath = Provider.RawFilePath;
|
return Provider.RawBundleObject.ReadFileData();
|
||||||
return FileUtility.ReadAllBytes(filePath);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -83,8 +82,7 @@ namespace YooAsset
|
||||||
{
|
{
|
||||||
if (IsValidWithWarning == false)
|
if (IsValidWithWarning == false)
|
||||||
return null;
|
return null;
|
||||||
string filePath = Provider.RawFilePath;
|
return Provider.RawBundleObject.ReadFileText();
|
||||||
return FileUtility.ReadAllText(filePath);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -94,7 +92,7 @@ namespace YooAsset
|
||||||
{
|
{
|
||||||
if (IsValidWithWarning == false)
|
if (IsValidWithWarning == false)
|
||||||
return string.Empty;
|
return string.Empty;
|
||||||
return Provider.RawFilePath;
|
return Provider.RawBundleObject.GetFilePath();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -45,7 +45,7 @@ namespace YooAsset
|
||||||
public long DownloadedBytes { set; get; } = 0;
|
public long DownloadedBytes { set; get; } = 0;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 下载结果
|
/// 加载结果
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public object Result { set; get; }
|
public object Result { set; get; }
|
||||||
|
|
||||||
|
|
|
@ -32,7 +32,7 @@ namespace YooAsset
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (LoadBundleFileOp.Result is string == false)
|
if (LoadBundleFileOp.Result is RawBundle == false)
|
||||||
{
|
{
|
||||||
string error = "Try load AssetBundle file using load raw file method !";
|
string error = "Try load AssetBundle file using load raw file method !";
|
||||||
InvokeCompletion(error, EOperationStatus.Failed);
|
InvokeCompletion(error, EOperationStatus.Failed);
|
||||||
|
@ -45,7 +45,7 @@ namespace YooAsset
|
||||||
// 2. 检测加载结果
|
// 2. 检测加载结果
|
||||||
if (_steps == ESteps.Checking)
|
if (_steps == ESteps.Checking)
|
||||||
{
|
{
|
||||||
RawFilePath = LoadBundleFileOp.Result as string;
|
RawBundleObject = LoadBundleFileOp.Result as RawBundle;
|
||||||
InvokeCompletion(string.Empty, EOperationStatus.Succeed);
|
InvokeCompletion(string.Empty, EOperationStatus.Succeed);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -53,7 +53,7 @@ namespace YooAsset
|
||||||
// 2. 检测加载结果
|
// 2. 检测加载结果
|
||||||
if (_steps == ESteps.Checking)
|
if (_steps == ESteps.Checking)
|
||||||
{
|
{
|
||||||
RawFilePath = MainAssetInfo.AssetPath;
|
RawBundleObject = new RawBundle(null, null, MainAssetInfo.AssetPath);
|
||||||
InvokeCompletion(string.Empty, EOperationStatus.Succeed);
|
InvokeCompletion(string.Empty, EOperationStatus.Succeed);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -46,16 +46,16 @@ namespace YooAsset
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public UnityEngine.SceneManagement.Scene SceneObject { protected set; get; }
|
public UnityEngine.SceneManagement.Scene SceneObject { protected set; get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 获取的原生对象
|
||||||
|
/// </summary>
|
||||||
|
public RawBundle RawBundleObject { protected set; get; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 加载的场景名称
|
/// 加载的场景名称
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string SceneName { protected set; get; }
|
public string SceneName { protected set; get; }
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 原生文件路径
|
|
||||||
/// </summary>
|
|
||||||
public string RawFilePath { protected set; get; }
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 引用计数
|
/// 引用计数
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
|
@ -0,0 +1,36 @@
|
||||||
|
|
||||||
|
namespace YooAsset
|
||||||
|
{
|
||||||
|
internal class RawBundle
|
||||||
|
{
|
||||||
|
private readonly IFileSystem _fileSystem;
|
||||||
|
private readonly PackageBundle _packageBundle;
|
||||||
|
private readonly string _filePath;
|
||||||
|
|
||||||
|
internal RawBundle(IFileSystem fileSystem, PackageBundle packageBundle, string filePath)
|
||||||
|
{
|
||||||
|
_fileSystem = fileSystem;
|
||||||
|
_packageBundle = packageBundle;
|
||||||
|
_filePath = filePath;
|
||||||
|
}
|
||||||
|
|
||||||
|
public string GetFilePath()
|
||||||
|
{
|
||||||
|
return _filePath;
|
||||||
|
}
|
||||||
|
public byte[] ReadFileData()
|
||||||
|
{
|
||||||
|
if (_fileSystem != null)
|
||||||
|
return _fileSystem.ReadFileData(_packageBundle);
|
||||||
|
else
|
||||||
|
return FileUtility.ReadAllBytes(_filePath);
|
||||||
|
}
|
||||||
|
public string ReadFileText()
|
||||||
|
{
|
||||||
|
if (_fileSystem != null)
|
||||||
|
return _fileSystem.ReadFileText(_packageBundle);
|
||||||
|
else
|
||||||
|
return FileUtility.ReadAllText(_filePath);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,11 @@
|
||||||
|
fileFormatVersion: 2
|
||||||
|
guid: c6e71c986d2a8c74d981deeed7b5a8ef
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
|
@ -121,7 +121,7 @@ namespace YooAsset
|
||||||
public static string ReadAllText(string filePath)
|
public static string ReadAllText(string filePath)
|
||||||
{
|
{
|
||||||
if (File.Exists(filePath) == false)
|
if (File.Exists(filePath) == false)
|
||||||
return string.Empty;
|
return null;
|
||||||
return File.ReadAllText(filePath, Encoding.UTF8);
|
return File.ReadAllText(filePath, Encoding.UTF8);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue