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

Use UnityWebRequest instead of WWW #127

Open
wants to merge 1 commit into
base: master
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
15 changes: 12 additions & 3 deletions Assets/StandaloneFileBrowser/Sample/CanvasSampleOpenFileImage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.EventSystems;
using UnityEngine.Networking;
using SFB;

[RequireComponent(typeof(Button))]
Expand Down Expand Up @@ -46,8 +47,16 @@ private void OnClick() {
#endif

private IEnumerator OutputRoutine(string url) {
var loader = new WWW(url);
yield return loader;
output.texture = loader.texture;
UnityWebRequest www = UnityWebRequestTexture.GetTexture(url);
yield return www.SendWebRequest();

if (www.result != UnityWebRequest.Result.Success)
{
Debug.LogError(www.error);
}
else
{
output.texture = ((DownloadHandlerTexture)www.downloadHandler).texture;
}
}
}
15 changes: 12 additions & 3 deletions Assets/StandaloneFileBrowser/Sample/CanvasSampleOpenFileText.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.EventSystems;
using UnityEngine.Networking;
using SFB;

[RequireComponent(typeof(Button))]
Expand Down Expand Up @@ -46,8 +47,16 @@ private void OnClick() {
#endif

private IEnumerator OutputRoutine(string url) {
var loader = new WWW(url);
yield return loader;
output.text = loader.text;
UnityWebRequest www = UnityWebRequest.Get(url);
yield return www.SendWebRequest();

if (www.result != UnityWebRequest.Result.Success)
{
Debug.LogError(www.error);
}
else
{
output.text = www.downloadHandler.text;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
using System.Text;
using System.Collections;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.EventSystems;
using UnityEngine.Networking;
using SFB;

[RequireComponent(typeof(Button))]
Expand Down Expand Up @@ -52,10 +51,19 @@ private void OnClick() {

private IEnumerator OutputRoutine(string[] urlArr) {
var outputText = "";
for (int i = 0; i < urlArr.Length; i++) {
var loader = new WWW(urlArr[i]);
yield return loader;
outputText += loader.text;
for (int i = 0; i < urlArr.Length; i++)
{
UnityWebRequest www = UnityWebRequest.Get(urlArr[i]);
yield return www.SendWebRequest();

if (www.result != UnityWebRequest.Result.Success)
{
Debug.LogError(www.error);
}
else
{
outputText += www.downloadHandler.text;
}
}
output.text = outputText;
}
Expand Down