Fixed site menu buttons

This commit is contained in:
Pascal Serrarens 2022-02-22 17:49:52 +01:00
parent 4b3bd49242
commit 41409d627d
2 changed files with 35 additions and 12 deletions

View File

@ -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<SiteNavigator>();
}
return _instance;
}
}
protected virtual void Awake() {
if (_instance == null) {
// Bit of a hack, find the sitenavigator outside the menu...
SiteNavigator parentSiteNavigator = GetComponentInParent<SiteNavigator>();
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 {
/// <summary>
/// Change the current Site
/// </summary>
/// <param name="vrsiteName">The URL of the site to visit</param>
/// <param name="siteLocation">The URL of the site to visit</param>
/// 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() {

View File

@ -874,7 +874,7 @@ MonoBehaviour:
m_Name:
m_EditorClassIdentifier:
loadSiteAtStart: 0
startSite: passervr.com/sites/start
startSite:
startScene:
--- !u!1 &1100335821991332
GameObject: