Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[增加]1. 增加是否加载成功的快捷判断属性 #353

Open
wants to merge 4 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Assets/YooAsset/Runtime/OperationSystem/AsyncOperationBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ internal virtual void InternalWaitForAsyncComplete()
throw new System.NotImplementedException(this.GetType().Name);
}

internal string GetPackageName()
public string GetPackageName()
{
return _packageName;
}
Expand Down Expand Up @@ -191,4 +191,4 @@ void IEnumerator.Reset()
private TaskCompletionSource<object> _taskCompletionSource;
#endregion
}
}
}
10 changes: 9 additions & 1 deletion Assets/YooAsset/Runtime/ResourceManager/Handle/HandleBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,14 @@ internal HandleBase(ProviderOperation provider)
}
internal abstract void InvokeCallback();

/// <summary>
/// 是否成功
/// </summary>
public bool IsSucceed
{
get { return IsDone && Status == EOperationStatus.Succeed; }
}

/// <summary>
/// 获取资源信息
/// </summary>
Expand Down Expand Up @@ -158,4 +166,4 @@ object IEnumerator.Current
}
#endregion
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ private enum ESteps

private const int MAX_LOADER_COUNT = 64;

public delegate void OnDownloadOver(bool isSucceed);
public delegate void OnDownloadProgress(int totalDownloadCount, int currentDownloadCount, long totalDownloadBytes, long currentDownloadBytes);
public delegate void OnDownloadError(string fileName, string error);
public delegate void OnStartDownloadFile(string fileName, long sizeBytes);
public delegate void OnDownloadOver(string packageName, bool isSucceed);
public delegate void OnDownloadProgress(string packageName, int totalDownloadCount, int currentDownloadCount, long totalDownloadBytes, long currentDownloadBytes);
public delegate void OnDownloadError(string packageName, string fileName, string error);
public delegate void OnStartDownloadFile(string packageName, string fileName, long sizeBytes);

private readonly string _packageName;
private readonly int _downloadingMaxNumber;
Expand Down Expand Up @@ -160,7 +160,7 @@ internal override void InternalOnUpdate()
_lastDownloadBytes = downloadBytes;
_lastDownloadCount = _cachedDownloadCount;
Progress = (float)_lastDownloadBytes / TotalDownloadBytes;
OnDownloadProgressCallback?.Invoke(TotalDownloadCount, _lastDownloadCount, TotalDownloadBytes, _lastDownloadBytes);
OnDownloadProgressCallback?.Invoke(GetPackageName(), TotalDownloadCount, _lastDownloadCount, TotalDownloadBytes, _lastDownloadBytes);
}

// 动态创建新的下载器到最大数量限制
Expand All @@ -177,7 +177,7 @@ internal override void InternalOnUpdate()
var downloader = bundleInfo.CreateDownloader(_failedTryAgain, _timeout);
_downloaders.Add(downloader);
_bundleInfoList.RemoveAt(index);
OnStartDownloadFileCallback?.Invoke(bundleInfo.Bundle.BundleName, bundleInfo.Bundle.FileSize);
OnStartDownloadFileCallback?.Invoke(GetPackageName(), bundleInfo.Bundle.BundleName, bundleInfo.Bundle.FileSize);
}
}

Expand All @@ -191,15 +191,15 @@ internal override void InternalOnUpdate()
_steps = ESteps.Done;
Status = EOperationStatus.Failed;
Error = $"Failed to download file : {bundleName}";
OnDownloadErrorCallback?.Invoke(bundleName, failedDownloader.Error);
OnDownloadOverCallback?.Invoke(false);
OnDownloadErrorCallback?.Invoke(GetPackageName(), bundleName, failedDownloader.Error);
OnDownloadOverCallback?.Invoke(GetPackageName(), false);
}
else
{
// 结算成功
_steps = ESteps.Done;
Status = EOperationStatus.Succeed;
OnDownloadOverCallback?.Invoke(true);
OnDownloadOverCallback?.Invoke(GetPackageName(), true);
}
}
}
Expand Down Expand Up @@ -361,4 +361,4 @@ internal static ResourceImporterOperation CreateEmptyImporter(string packageName
return operation;
}
}
}
}
Loading