diff --git a/NewHorizons/Builder/Props/ProjectionBuilder.cs b/NewHorizons/Builder/Props/ProjectionBuilder.cs index 10963bac..b4bc971c 100644 --- a/NewHorizons/Builder/Props/ProjectionBuilder.cs +++ b/NewHorizons/Builder/Props/ProjectionBuilder.cs @@ -249,7 +249,12 @@ namespace NewHorizons.Builder.Props var mindSlideProjector = standingTorch.GetComponent(); mindSlideProjector._mindProjectorImageEffect = GameObject.Find("Player_Body/PlayerCamera").GetComponent(); - + + // setup for visually supporting async texture loading + mindSlideProjector.enabled = false; + var visionBeamEffect = SearchUtilities.FindChild(standingTorch, "VisionBeam"); + visionBeamEffect.SetActive(false); + // // set up slides // @@ -271,7 +276,25 @@ namespace NewHorizons.Builder.Props slideCollection.slides[i] = slide; } - imageLoader.imageLoadedEvent.AddListener((Texture2D tex, int index) => { slideCollection.slides[index].textureOverride = tex; }); + + // this variable just lets us track how many of the slides have been loaded. + // this way as soon as the last one is loaded (due to async loading, this may be + // slide 7, or slide 3, or whatever), we can enable the vision torch. This allows us + // to avoid doing a "is every element in the array `slideCollection.slides` not null" check every time a texture finishes loading + int displaySlidesLoaded = 0; + imageLoader.imageLoadedEvent.AddListener( + (Texture2D tex, int index) => + { + slideCollection.slides[index].textureOverride = tex; + displaySlidesLoaded++; // threading moment + + if (displaySlidesLoaded >= slides.Length) + { + mindSlideProjector.enabled = true; + visionBeamEffect.SetActive(true); + } + } + ); // set up the containers for the slides var slideCollectionContainer = standingTorch.AddComponent(); @@ -281,9 +304,8 @@ namespace NewHorizons.Builder.Props // make sure that these slides play when the player wanders into the beam // _slideCollectionItem is actually a reference to a SlideCollectionContainer. Not a slide reel item - standingTorch.GetComponent()._mindSlideCollection = mindSlideCollection; + mindSlideProjector._mindSlideCollection = mindSlideCollection; mindSlideProjector._slideCollectionItem = slideCollectionContainer; - mindSlideProjector._mindSlideCollection = mindSlideCollection; mindSlideProjector.SetMindSlideCollection(mindSlideCollection); diff --git a/NewHorizons/Utility/ImageUtilities.cs b/NewHorizons/Utility/ImageUtilities.cs index 4de79971..018abdd8 100644 --- a/NewHorizons/Utility/ImageUtilities.cs +++ b/NewHorizons/Utility/ImageUtilities.cs @@ -337,7 +337,6 @@ namespace NewHorizons.Utility IEnumerator DownloadTexture(string url, int index) { - Logger.Log("loading img " + url); using (UnityWebRequest uwr = UnityWebRequestTexture.GetTexture(url)) { yield return uwr.SendWebRequest(); @@ -352,7 +351,6 @@ namespace NewHorizons.Utility { // Get downloaded asset bundle var texture = DownloadHandlerTexture.GetContent(uwr); - Logger.Log("Finished loading image " + url); imageLoadedEvent.Invoke(texture, index); } } diff --git a/NewHorizons/Utility/SearchUtilities.cs b/NewHorizons/Utility/SearchUtilities.cs index 821e68ea..f1180e02 100644 --- a/NewHorizons/Utility/SearchUtilities.cs +++ b/NewHorizons/Utility/SearchUtilities.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.Linq; using UnityEngine; @@ -119,6 +119,16 @@ namespace NewHorizons.Utility } */ + public static GameObject FindChild(GameObject g, string childName) + { + foreach(Transform child in g.transform) + { + if (child.gameObject.name == childName) return child.gameObject; + } + + return null; + } + public static GameObject Find(string path) { if (CachedGameObjects.ContainsKey(path))