Skip to content
This repository has been archived by the owner on Sep 21, 2022. It is now read-only.

Commit

Permalink
Changed ImageRequest back to unmanaged class... for now
Browse files Browse the repository at this point in the history
  • Loading branch information
Jackson Wood committed Jun 19, 2019
1 parent ec843f6 commit 31aa01b
Showing 1 changed file with 3 additions and 70 deletions.
73 changes: 3 additions & 70 deletions src/Requests/ImageRequest.cs
@@ -1,14 +1,11 @@
using System;
using UnityEngine;
using UnityEngine.Networking;

using Texture2D = UnityEngine.Texture2D;

namespace ModIO
{
public class ImageRequest
{
// ---------[ FIELDS ]---------
public event Action<ImageRequest> succeeded;
public event Action<ImageRequest> failed;

Expand All @@ -18,79 +15,15 @@ public class ImageRequest

public WebRequestError error;

private UnityWebRequestAsyncOperation m_asyncOperation;

// --- ACCESSORS ---
public UnityWebRequestAsyncOperation asyncOperation
{
get { return this.m_asyncOperation; }
set
{
if(this.m_asyncOperation != value)
{
if(this.m_asyncOperation != null)
{
this.m_asyncOperation.completed -= this.OnCompleted;
}
if(value != null)
{
value.completed += this.OnCompleted;
}

this.m_asyncOperation = value;
}
}
}

// ---------[ EVENTS ]---------
private void OnCompleted(AsyncOperation operation)
{
Debug.Assert(operation == this.m_asyncOperation);

UnityWebRequest webRequest = this.m_asyncOperation.webRequest;
this.isDone = true;

if(webRequest.isNetworkError || webRequest.isHttpError)
{
this.error = WebRequestError.GenerateFromWebRequest(webRequest);

if(this.failed != null)
{
this.failed(this);
}
}
else
{
#if DEBUG
if(PluginSettings.data.logAllRequests)
{
var responseTimeStamp = ServerTimeStamp.Now;
Debug.Log("IMAGE DOWNLOAD SUCEEDED"
+ "\nDownload completed at: " + ServerTimeStamp.ToLocalDateTime(responseTimeStamp)
+ "\nURL: " + webRequest.url);
}
#endif

this.imageTexture = (webRequest.downloadHandler as DownloadHandlerTexture).texture;

if(succeeded != null)
{
succeeded(this);
}
}
}

// ---------[ OBSOLETE ]---------
[Obsolete("No longer necessary.")]
public void NotifySucceeded()
internal void NotifySucceeded()
{
if(succeeded != null)
{
succeeded(this);
}
}
[Obsolete("No longer necessary.")]
public void NotifyFailed()

internal void NotifyFailed()
{
if(failed != null)
{
Expand Down

0 comments on commit 31aa01b

Please sign in to comment.