From 41409d627d54e0c427f6855864caa9878f797651 Mon Sep 17 00:00:00 2001 From: Pascal Serrarens Date: Tue, 22 Feb 2022 17:49:52 +0100 Subject: [PATCH] Fixed site menu buttons --- Runtime/Sites/Scripts/SiteNavigator.cs | 45 ++++++++++++++----- .../Visitors/Prefabs/HumanoidMenu.prefab | 2 +- 2 files changed, 35 insertions(+), 12 deletions(-) diff --git a/Runtime/Sites/Scripts/SiteNavigator.cs b/Runtime/Sites/Scripts/SiteNavigator.cs index f4dc407..c31327d 100644 --- a/Runtime/Sites/Scripts/SiteNavigator.cs +++ b/Runtime/Sites/Scripts/SiteNavigator.cs @@ -42,15 +42,33 @@ namespace Passer { protected static AssetBundle currentAssetBundle = null; protected static AssetBundle loadedAssetBundle = null; - //public class Startup { - // public string startSite; - //} - #endregion Properties #region Init + static SiteNavigator _instance; + public static SiteNavigator instance { + get { + if (_instance == null) { + Debug.LogWarning("No SiteNavigator instance found, instantiating a new instance..."); + GameObject go = new GameObject(); + _instance = go.AddComponent(); + } + return _instance; + } + } + + protected virtual void Awake() { + if (_instance == null) { + // Bit of a hack, find the sitenavigator outside the menu... + SiteNavigator parentSiteNavigator = GetComponentInParent(); + if (parentSiteNavigator != null) + _instance = parentSiteNavigator; + else + _instance = this; + } + if (loadSiteAtStart) LoadStartSiteFromStartupJSON(); } @@ -67,7 +85,6 @@ namespace Passer { if (startScene != null && startScene != "" && startScene != "-none-") { Debug.Log("Load scene " + startScene); UnityEditor.SceneManagement.EditorSceneManager.LoadSceneInPlayMode(startScene, new LoadSceneParameters(LoadSceneMode.Additive)); - //UnityEngine.SceneManagement.SceneManager.LoadScene(startScene); currentSite = new HistoryEntry() { siteName = "directload", siteLocation = "passervr.com/sites/start", @@ -90,7 +107,7 @@ namespace Passer { protected void Update() { if (loadedAssetBundle != currentAssetBundle) { if (loadedAssetBundle != null) { - Debug.Log("unload"); + Debug.Log("unload " + loadedAssetBundle.name); loadedAssetBundle.Unload(false); } @@ -114,10 +131,10 @@ namespace Passer { /// /// Change the current Site /// - /// The URL of the site to visit + /// The URL of the site to visit /// The URL should not include a protocol (like https://) or an extension (like .site or .windows.site) - public void LoadSiteFromURL(string vrsiteName) { - StartCoroutine(LoadSite(vrsiteName)); + public void LoadSiteFromURL(string siteLocation) { + SiteNavigator.instance.StartCoroutine(LoadSite(siteLocation)); } protected static IEnumerator LoadSite(string siteLocation) { @@ -140,6 +157,7 @@ namespace Passer { } string scenePath = null; + HistoryEntry foundEntry = cache.Find(entry => entry.siteLocation == siteLocation); // cache is disabled because we unload the asset bundles foundEntry = null; @@ -152,10 +170,10 @@ namespace Passer { string url = "https://" + siteLocation + ".windows" + ".site"; #endif - Debug.Log("Loading site: " + url); //ShowLoadingDialog(); GameObject dialog = ShowDialog("Loading..."); + Debug.Log("Loading site: " + url); UnityWebRequest request = UnityWebRequestAssetBundle.GetAssetBundle(url); yield return request.SendWebRequest(); @@ -242,8 +260,13 @@ namespace Passer { } public void ReloadSite() { - if (currentSite != null) + if (currentSite != null) { + if (currentAssetBundle != null) { + Debug.Log("unload " + currentAssetBundle.name); + currentAssetBundle.Unload(false); + } LoadSiteFromURL(currentSite.siteLocation); + } } private static void DestroyAllSocketAttachments() { diff --git a/Samples~/VisitorsAndSites/Visitors/Prefabs/HumanoidMenu.prefab b/Samples~/VisitorsAndSites/Visitors/Prefabs/HumanoidMenu.prefab index 9fdc040..96fcfdb 100644 --- a/Samples~/VisitorsAndSites/Visitors/Prefabs/HumanoidMenu.prefab +++ b/Samples~/VisitorsAndSites/Visitors/Prefabs/HumanoidMenu.prefab @@ -874,7 +874,7 @@ MonoBehaviour: m_Name: m_EditorClassIdentifier: loadSiteAtStart: 0 - startSite: passervr.com/sites/start + startSite: startScene: --- !u!1 &1100335821991332 GameObject: