added comment for future enhancement

This commit is contained in:
FreezeDriedMangoes 2022-05-25 17:44:05 -04:00
parent 5cc232ee8c
commit 0955bda3f6

View File

@ -1,12 +1,12 @@
using OWML.Common; using OWML.Common;
using System; using System;
using System.Collections; using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using UnityEngine; using UnityEngine;
using UnityEngine.Events; using UnityEngine.Events;
using UnityEngine.Networking; using UnityEngine.Networking;
namespace NewHorizons.Utility namespace NewHorizons.Utility
{ {
public static class ImageUtilities public static class ImageUtilities
@ -317,43 +317,47 @@ namespace NewHorizons.Utility
newTexture.Apply(); newTexture.Apply();
return newTexture; return newTexture;
} }
} }
// Modified from https://stackoverflow.com/a/69141085/9643841
public class AsyncImageLoader : MonoBehaviour
{
public List<string> pathsToLoad = new List<string>();
public class ImageLoadedEvent : UnityEvent<Texture2D, int> { } // Modified from https://stackoverflow.com/a/69141085/9643841
public ImageLoadedEvent imageLoadedEvent = new ImageLoadedEvent(); public class AsyncImageLoader : MonoBehaviour
{
public List<string> pathsToLoad = new List<string>();
public class ImageLoadedEvent : UnityEvent<Texture2D, int> { }
public ImageLoadedEvent imageLoadedEvent = new ImageLoadedEvent();
void Start() // TODO: set up an optional “StartLoading” and “StartUnloading” condition on AsyncTextureLoader,
{ // and make use of that for at least for projector stuff (require player to be in the same sector as the slides
for (int i = 0; i < pathsToLoad.Count; i++) // for them to start loading, and unload when the player leaves)
{
StartCoroutine(DownloadTexture(pathsToLoad[i], i)); void Start()
} {
} for (int i = 0; i < pathsToLoad.Count; i++)
{
IEnumerator DownloadTexture(string url, int index) StartCoroutine(DownloadTexture(pathsToLoad[i], i));
{ }
using (UnityWebRequest uwr = UnityWebRequestTexture.GetTexture(url)) }
{
yield return uwr.SendWebRequest(); IEnumerator DownloadTexture(string url, int index)
{
var hasError = uwr.error != null && uwr.error != ""; using (UnityWebRequest uwr = UnityWebRequestTexture.GetTexture(url))
{
if (hasError) // (uwr.result != UnityWebRequest.Result.Success) yield return uwr.SendWebRequest();
{
Debug.Log(uwr.error); var hasError = uwr.error != null && uwr.error != "";
}
else if (hasError) // (uwr.result != UnityWebRequest.Result.Success)
{ {
// Get downloaded asset bundle Debug.Log(uwr.error);
var texture = DownloadHandlerTexture.GetContent(uwr); }
imageLoadedEvent.Invoke(texture, index); else
} {
} // Get downloaded asset bundle
} var texture = DownloadHandlerTexture.GetContent(uwr);
imageLoadedEvent.Invoke(texture, index);
}
}
}
} }
} }