Pull down UnityNetworkTask.

This commit is contained in:
2023-06-22 13:23:03 +08:00
parent 60cc763cd0
commit ea02fc22bd

View File

@@ -92,15 +92,6 @@ namespace Cryville.Common.Unity {
/// A network task.
/// </summary>
public abstract class NetworkTask {
protected NetworkTask(string uri) {
Uri = uri;
}
/// <summary>
/// The URI of the resource.
/// </summary>
public string Uri { get; private set; }
/// <summary>
/// Whether the task is cancelled.
/// </summary>
@@ -109,40 +100,56 @@ namespace Cryville.Common.Unity {
/// <summary>
/// Cancels the task.
/// </summary>
public virtual void Cancel() {
public void Cancel() {
Cancelled = true;
OnCancel();
}
protected virtual void OnCancel() { }
#if UNITY_5_4_OR_NEWER
protected UnityWebRequest www;
/// <summary>
/// Starts the task.
/// </summary>
public virtual void Start() {
www = new UnityWebRequest(Uri);
www.SendWebRequest();
}
public abstract void Start();
/// <summary>
/// Gets whether the task is done.
/// </summary>
/// <returns>Whether the task is done.</returns>
public virtual bool Done() {
public abstract bool Done();
}
/// <summary>
/// A Unity network task.
/// </summary>
public abstract class UnityNetworkTask : NetworkTask {
protected UnityNetworkTask(string uri) {
Uri = uri;
}
/// <summary>
/// The URI of the resource.
/// </summary>
public string Uri { get; private set; }
#if UNITY_5_4_OR_NEWER
protected UnityWebRequest www;
/// <inheritdoc />
public override void Start() {
www = new UnityWebRequest(Uri);
www.SendWebRequest();
}
/// <inheritdoc />
public override bool Done() {
if (!www.isDone) return false;
return true;
}
#else
protected WWW www;
/// <summary>
/// Starts the task.
/// </summary>
/// <inheritdoc />
public virtual void Start() {
www = new WWW(Uri);
}
/// <summary>
/// Gets whether the task is done.
/// </summary>
/// <returns>Whether the task is done.</returns>
/// <inheritdoc />
public virtual bool Done() {
if (!www.isDone) return false;
return true;
@@ -150,9 +157,9 @@ namespace Cryville.Common.Unity {
#endif
}
/// <summary>
/// A <see cref="NetworkTask" /> that loads a texture.
/// A <see cref="UnityNetworkTask" /> that loads a texture.
/// </summary>
public class LoadTextureTask : NetworkTask {
public class LoadTextureTask : UnityNetworkTask {
/// <summary>
/// Creates an instance of the <see cref="LoadTextureTask" /> class.
/// </summary>