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 System;
using System.Collections;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.Networking;
using UnityEngine.Events;
using UnityEngine.Networking;
namespace NewHorizons.Utility
{
public static class ImageUtilities
@ -317,43 +317,47 @@ namespace NewHorizons.Utility
newTexture.Apply();
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> { }
public ImageLoadedEvent imageLoadedEvent = new ImageLoadedEvent();
// 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> { }
public ImageLoadedEvent imageLoadedEvent = new ImageLoadedEvent();
void Start()
{
for (int i = 0; i < pathsToLoad.Count; i++)
{
StartCoroutine(DownloadTexture(pathsToLoad[i], i));
}
}
IEnumerator DownloadTexture(string url, int index)
{
using (UnityWebRequest uwr = UnityWebRequestTexture.GetTexture(url))
{
yield return uwr.SendWebRequest();
var hasError = uwr.error != null && uwr.error != "";
if (hasError) // (uwr.result != UnityWebRequest.Result.Success)
{
Debug.Log(uwr.error);
}
else
{
// Get downloaded asset bundle
var texture = DownloadHandlerTexture.GetContent(uwr);
imageLoadedEvent.Invoke(texture, index);
}
}
}
// 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 them to start loading, and unload when the player leaves)
void Start()
{
for (int i = 0; i < pathsToLoad.Count; i++)
{
StartCoroutine(DownloadTexture(pathsToLoad[i], i));
}
}
IEnumerator DownloadTexture(string url, int index)
{
using (UnityWebRequest uwr = UnityWebRequestTexture.GetTexture(url))
{
yield return uwr.SendWebRequest();
var hasError = uwr.error != null && uwr.error != "";
if (hasError) // (uwr.result != UnityWebRequest.Result.Success)
{
Debug.Log(uwr.error);
}
else
{
// Get downloaded asset bundle
var texture = DownloadHandlerTexture.GetContent(uwr);
imageLoadedEvent.Invoke(texture, index);
}
}
}
}
}