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