mirror of https://github.com/tuyoogame/YooAsset
Compare commits
8 Commits
a58e5aceac
...
0dd97e9004
Author | SHA1 | Date |
---|---|---|
absences | 0dd97e9004 | |
何冠峰 | d890ccd5e6 | |
何冠峰 | e76a782a80 | |
何冠峰 | 0f7c5b2564 | |
何冠峰 | fcf0f34d5a | |
何冠峰 | acf2301028 | |
absences | 008a3e1893 | |
unknown | fa572e6ae1 |
|
@ -272,19 +272,43 @@ namespace YooAsset.Editor
|
|||
}
|
||||
private List<AssetInfo> GetAllDependencies(CollectCommand command, string mainAssetPath)
|
||||
{
|
||||
string[] depends = AssetDatabase.GetDependencies(mainAssetPath, true);
|
||||
List<AssetInfo> result = new List<AssetInfo>(depends.Length);
|
||||
foreach (string assetPath in depends)
|
||||
List<AssetInfo> dependencies = new List<AssetInfo>();
|
||||
HashSet<AssetStamp> m_AssetStamps = new HashSet<AssetStamp>();
|
||||
void GetDependRecursive(string assetPath)
|
||||
{
|
||||
// 注意:排除主资源对象
|
||||
if (assetPath == mainAssetPath)
|
||||
string[] depends = AssetDatabase.GetDependencies(assetPath, false);
|
||||
|
||||
foreach (string dependPath in depends)
|
||||
{
|
||||
// 注意:排除资源自身
|
||||
if (dependPath == assetPath)
|
||||
continue;
|
||||
//排除主资源
|
||||
if (dependPath == mainAssetPath)
|
||||
continue;
|
||||
|
||||
AssetInfo assetInfo = new AssetInfo(assetPath);
|
||||
if (command.IgnoreRule.IsIgnore(assetInfo) == false)
|
||||
result.Add(assetInfo);
|
||||
var stamp = new AssetStamp(mainAssetPath, dependPath);
|
||||
|
||||
//主资源对于一个资源只有一个依赖
|
||||
if (m_AssetStamps.Contains(stamp))
|
||||
continue;
|
||||
m_AssetStamps.Add(stamp);
|
||||
|
||||
AssetInfo assetInfo = new AssetInfo(dependPath);
|
||||
|
||||
//根据忽略规则排除
|
||||
if (command.IgnoreRule.IsIgnore(assetInfo))
|
||||
continue;
|
||||
|
||||
dependencies.Add(assetInfo);
|
||||
|
||||
GetDependRecursive(dependPath);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
GetDependRecursive(mainAssetPath);
|
||||
|
||||
return dependencies;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,33 @@
|
|||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace YooAsset.Editor
|
||||
{
|
||||
[StructLayout(LayoutKind.Auto)]
|
||||
internal struct AssetStamp
|
||||
{
|
||||
private readonly string m_AssetName;
|
||||
private readonly string m_DependAssetPath;
|
||||
|
||||
public AssetStamp(string assetName, string dependencyAssetName)
|
||||
{
|
||||
m_AssetName = assetName;
|
||||
m_DependAssetPath = dependencyAssetName;
|
||||
}
|
||||
|
||||
public string AssetName
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_AssetName;
|
||||
}
|
||||
}
|
||||
|
||||
public string DependAssetPath
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_DependAssetPath;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -94,6 +94,9 @@ namespace YooAsset
|
|||
// 等待验证完成
|
||||
if (_steps == ESteps.CheckVerifyTempFile)
|
||||
{
|
||||
if (IsWaitForAsyncComplete)
|
||||
_verifyOperation.WaitForAsyncComplete();
|
||||
|
||||
if (_verifyOperation.IsDone == false)
|
||||
return;
|
||||
|
||||
|
@ -154,9 +157,6 @@ namespace YooAsset
|
|||
|
||||
while (true)
|
||||
{
|
||||
if (_verifyOperation != null)
|
||||
_verifyOperation.WaitForAsyncComplete();
|
||||
|
||||
// 注意:如果是导入或解压本地文件,执行等待完毕
|
||||
if (isReuqestLocalFile)
|
||||
{
|
||||
|
@ -305,6 +305,9 @@ namespace YooAsset
|
|||
// 等待验证完成
|
||||
if (_steps == ESteps.CheckVerifyTempFile)
|
||||
{
|
||||
if (IsWaitForAsyncComplete)
|
||||
_verifyOperation.WaitForAsyncComplete();
|
||||
|
||||
if (_verifyOperation.IsDone == false)
|
||||
return;
|
||||
|
||||
|
@ -364,9 +367,6 @@ namespace YooAsset
|
|||
|
||||
while (true)
|
||||
{
|
||||
if (_verifyOperation != null)
|
||||
_verifyOperation.WaitForAsyncComplete();
|
||||
|
||||
// 注意:如果是导入或解压本地文件,执行等待完毕
|
||||
if (isReuqestLocalFile)
|
||||
{
|
||||
|
|
|
@ -58,6 +58,9 @@ namespace YooAsset
|
|||
_downloadFileOp = _fileSystem.DownloadFileAsync(_bundle, downloadParam);
|
||||
}
|
||||
|
||||
if (IsWaitForAsyncComplete)
|
||||
_downloadFileOp.WaitForAsyncComplete();
|
||||
|
||||
DownloadProgress = _downloadFileOp.DownloadProgress;
|
||||
DownloadedBytes = _downloadFileOp.DownloadedBytes;
|
||||
if (_downloadFileOp.IsDone == false)
|
||||
|
@ -198,9 +201,6 @@ namespace YooAsset
|
|||
{
|
||||
while (true)
|
||||
{
|
||||
if (_downloadFileOp != null)
|
||||
_downloadFileOp.WaitForAsyncComplete();
|
||||
|
||||
if (ExecuteWhileDone())
|
||||
{
|
||||
if (_downloadFileOp != null && _downloadFileOp.Status == EOperationStatus.Failed)
|
||||
|
@ -274,6 +274,9 @@ namespace YooAsset
|
|||
_downloadFileOp = _fileSystem.DownloadFileAsync(_bundle, downloadParam);
|
||||
}
|
||||
|
||||
if (IsWaitForAsyncComplete)
|
||||
_downloadFileOp.WaitForAsyncComplete();
|
||||
|
||||
DownloadProgress = _downloadFileOp.DownloadProgress;
|
||||
DownloadedBytes = _downloadFileOp.DownloadedBytes;
|
||||
if (_downloadFileOp.IsDone == false)
|
||||
|
@ -313,9 +316,6 @@ namespace YooAsset
|
|||
{
|
||||
while (true)
|
||||
{
|
||||
if (_downloadFileOp != null)
|
||||
_downloadFileOp.WaitForAsyncComplete();
|
||||
|
||||
if (ExecuteWhileDone())
|
||||
{
|
||||
if (_downloadFileOp != null && _downloadFileOp.Status == EOperationStatus.Failed)
|
||||
|
|
|
@ -36,6 +36,17 @@ namespace YooAsset
|
|||
}
|
||||
}
|
||||
|
||||
#region 自定义参数
|
||||
/// <summary>
|
||||
/// 异步模拟加载最小帧数
|
||||
/// </summary>
|
||||
public int _asyncSimulateMinFrame = 1;
|
||||
|
||||
/// <summary>
|
||||
/// 异步模拟加载最大帧数
|
||||
/// </summary>
|
||||
public int _asyncSimulateMaxFrame = 1;
|
||||
#endregion
|
||||
|
||||
public DefaultEditorFileSystem()
|
||||
{
|
||||
|
@ -85,9 +96,20 @@ namespace YooAsset
|
|||
}
|
||||
|
||||
public virtual void SetParameter(string name, object value)
|
||||
{
|
||||
if (name == FileSystemParametersDefine.ASYNC_SIMULATE_MIN_FRAME)
|
||||
{
|
||||
_asyncSimulateMinFrame = (int)value;
|
||||
}
|
||||
else if (name == FileSystemParametersDefine.ASYNC_SIMULATE_MAX_FRAME)
|
||||
{
|
||||
_asyncSimulateMaxFrame = (int)value;
|
||||
}
|
||||
else
|
||||
{
|
||||
YooLogger.Warning($"Invalid parameter : {name}");
|
||||
}
|
||||
}
|
||||
public virtual void OnCreate(string packageName, string rootDirectory)
|
||||
{
|
||||
PackageName = packageName;
|
||||
|
@ -148,6 +170,15 @@ namespace YooAsset
|
|||
string fileName = YooAssetSettingsData.GetManifestBinaryFileName(PackageName, packageVersion);
|
||||
return PathUtility.Combine(FileRoot, fileName);
|
||||
}
|
||||
public int GetAsyncSimulateFrame()
|
||||
{
|
||||
if (_asyncSimulateMinFrame > _asyncSimulateMaxFrame)
|
||||
{
|
||||
_asyncSimulateMinFrame = _asyncSimulateMaxFrame;
|
||||
}
|
||||
|
||||
return UnityEngine.Random.Range(_asyncSimulateMinFrame, _asyncSimulateMaxFrame + 1);
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
|
@ -3,8 +3,19 @@ namespace YooAsset
|
|||
{
|
||||
internal class DEFSLoadBundleOperation : FSLoadBundleOperation
|
||||
{
|
||||
protected enum ESteps
|
||||
{
|
||||
None,
|
||||
DownloadFile,
|
||||
LoadAssetBundle,
|
||||
CheckResult,
|
||||
Done,
|
||||
}
|
||||
|
||||
private readonly DefaultEditorFileSystem _fileSystem;
|
||||
private readonly PackageBundle _bundle;
|
||||
private int _asyncSimulateFrame;
|
||||
private ESteps _steps = ESteps.None;
|
||||
|
||||
internal DEFSLoadBundleOperation(DefaultEditorFileSystem fileSystem, PackageBundle bundle)
|
||||
{
|
||||
|
@ -13,15 +24,53 @@ namespace YooAsset
|
|||
}
|
||||
internal override void InternalOnStart()
|
||||
{
|
||||
DownloadProgress = 1f;
|
||||
DownloadedBytes = _bundle.FileSize;
|
||||
Status = EOperationStatus.Succeed;
|
||||
_steps = ESteps.DownloadFile;
|
||||
}
|
||||
internal override void InternalOnUpdate()
|
||||
{
|
||||
if (_steps == ESteps.None || _steps == ESteps.Done)
|
||||
return;
|
||||
|
||||
if (_steps == ESteps.DownloadFile)
|
||||
{
|
||||
_asyncSimulateFrame = _fileSystem.GetAsyncSimulateFrame();
|
||||
DownloadProgress = 1f;
|
||||
DownloadedBytes = _bundle.FileSize;
|
||||
_steps = ESteps.LoadAssetBundle;
|
||||
}
|
||||
|
||||
if (_steps == ESteps.LoadAssetBundle)
|
||||
{
|
||||
if (IsWaitForAsyncComplete)
|
||||
{
|
||||
_steps = ESteps.CheckResult;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (_asyncSimulateFrame <= 0)
|
||||
_steps = ESteps.CheckResult;
|
||||
else
|
||||
_asyncSimulateFrame--;
|
||||
}
|
||||
}
|
||||
|
||||
if (_steps == ESteps.CheckResult)
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Result = new VirtualBundle(_fileSystem, _bundle);
|
||||
Status = EOperationStatus.Succeed;
|
||||
}
|
||||
}
|
||||
internal override void InternalWaitForAsyncComplete()
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
if (ExecuteWhileDone())
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
public override void AbortDownloadOperation()
|
||||
{
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
|
||||
namespace YooAsset
|
||||
{
|
||||
internal class FileSystemParametersDefine
|
||||
public class FileSystemParametersDefine
|
||||
{
|
||||
public const string FILE_VERIFY_LEVEL = "FILE_VERIFY_LEVEL";
|
||||
public const string REMOTE_SERVICES = "REMOTE_SERVICES";
|
||||
|
@ -11,5 +11,7 @@ namespace YooAsset
|
|||
public const string DISABLE_UNITY_WEB_CACHE = "DISABLE_UNITY_WEB_CACHE";
|
||||
public const string RESUME_DOWNLOAD_MINMUM_SIZE = "RESUME_DOWNLOAD_MINMUM_SIZE";
|
||||
public const string RESUME_DOWNLOAD_RESPONSE_CODES = "RESUME_DOWNLOAD_RESPONSE_CODES";
|
||||
public const string ASYNC_SIMULATE_MIN_FRAME = "ASYNC_SIMULATE_MIN_FRAME";
|
||||
public const string ASYNC_SIMULATE_MAX_FRAME = "ASYNC_SIMULATE_MAX_FRAME";
|
||||
}
|
||||
}
|
|
@ -147,7 +147,7 @@ namespace YooAsset
|
|||
|
||||
// 当执行次数用完时
|
||||
_whileFrame--;
|
||||
if (_whileFrame == 0)
|
||||
if (_whileFrame <= 0)
|
||||
{
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = $"Operation {this.GetType().Name} failed to wait for async complete !";
|
||||
|
|
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
guid: a9ca0d0d29eb5294b9c6926c6a09e76b
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,15 @@
|
|||
|
||||
namespace YooAsset
|
||||
{
|
||||
internal class VirtualBundle
|
||||
{
|
||||
private readonly IFileSystem _fileSystem;
|
||||
private readonly PackageBundle _packageBundle;
|
||||
|
||||
internal VirtualBundle(IFileSystem fileSystem, PackageBundle packageBundle)
|
||||
{
|
||||
_fileSystem = fileSystem;
|
||||
_packageBundle = packageBundle;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 822bb85f05144d842977dda341174db2
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -69,6 +69,9 @@ namespace YooAsset
|
|||
if (_loadBundleOp == null)
|
||||
_loadBundleOp = BundleFileInfo.LoadBundleFile();
|
||||
|
||||
if (IsWaitForAsyncComplete)
|
||||
_loadBundleOp.WaitForAsyncComplete();
|
||||
|
||||
DownloadProgress = _loadBundleOp.DownloadProgress;
|
||||
DownloadedBytes = _loadBundleOp.DownloadedBytes;
|
||||
if (_loadBundleOp.IsDone == false)
|
||||
|
@ -101,9 +104,6 @@ namespace YooAsset
|
|||
{
|
||||
while (true)
|
||||
{
|
||||
if (_loadBundleOp != null)
|
||||
_loadBundleOp.WaitForAsyncComplete();
|
||||
|
||||
if (ExecuteWhileDone())
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
|
|
|
@ -36,6 +36,14 @@ namespace YooAsset
|
|||
|
||||
if (_steps == ESteps.CheckDepend)
|
||||
{
|
||||
if (IsWaitForAsyncComplete)
|
||||
{
|
||||
foreach (var loader in Depends)
|
||||
{
|
||||
loader.WaitForAsyncComplete();
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var loader in Depends)
|
||||
{
|
||||
if (loader.IsDone == false)
|
||||
|
@ -73,11 +81,6 @@ namespace YooAsset
|
|||
{
|
||||
while (true)
|
||||
{
|
||||
foreach (var loader in Depends)
|
||||
{
|
||||
loader.WaitForAsyncComplete();
|
||||
}
|
||||
|
||||
if (ExecuteWhileDone())
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
|
|
|
@ -96,6 +96,7 @@ namespace YooAsset
|
|||
{
|
||||
if (LoadDependBundleFileOp != null)
|
||||
LoadDependBundleFileOp.WaitForAsyncComplete();
|
||||
|
||||
if (LoadBundleFileOp != null)
|
||||
LoadBundleFileOp.WaitForAsyncComplete();
|
||||
|
||||
|
|
|
@ -176,6 +176,16 @@ namespace YooAsset
|
|||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
// 检测文件系统参数
|
||||
if (_playMode == EPlayMode.WebPlayMode)
|
||||
{
|
||||
var webPlayModeParams = parameters as WebPlayModeParameters;
|
||||
var fileSystemClassName = webPlayModeParams.WebFileSystemParameters.FileSystemClass;
|
||||
if (fileSystemClassName == typeof(DefaultCacheFileSystem).FullName
|
||||
|| fileSystemClassName == typeof(DefaultBuildinFileSystem).FullName)
|
||||
throw new Exception($"{fileSystemClassName} not support {nameof(EPlayMode.WebPlayMode)}");
|
||||
}
|
||||
}
|
||||
private void InitializeOperation_Completed(AsyncOperationBase op)
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue