mirror of
https://github.com/Outer-Wilds-New-Horizons/new-horizons.git
synced 2025-12-11 20:15:44 +01:00
added comment for future enhancement
This commit is contained in:
parent
5cc232ee8c
commit
0955bda3f6
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user