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 currentAssetBundle = null;
protected static AssetBundle loadedAssetBundle = null; protected static AssetBundle loadedAssetBundle = null;
//public class Startup {
// public string startSite;
//}
#endregion Properties #endregion Properties
#region Init #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() { 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) if (loadSiteAtStart)
LoadStartSiteFromStartupJSON(); LoadStartSiteFromStartupJSON();
} }
@ -67,7 +85,6 @@ namespace Passer {
if (startScene != null && startScene != "" && startScene != "-none-") { if (startScene != null && startScene != "" && startScene != "-none-") {
Debug.Log("Load scene " + startScene); Debug.Log("Load scene " + startScene);
UnityEditor.SceneManagement.EditorSceneManager.LoadSceneInPlayMode(startScene, new LoadSceneParameters(LoadSceneMode.Additive)); UnityEditor.SceneManagement.EditorSceneManager.LoadSceneInPlayMode(startScene, new LoadSceneParameters(LoadSceneMode.Additive));
//UnityEngine.SceneManagement.SceneManager.LoadScene(startScene);
currentSite = new HistoryEntry() { currentSite = new HistoryEntry() {
siteName = "directload", siteName = "directload",
siteLocation = "passervr.com/sites/start", siteLocation = "passervr.com/sites/start",
@ -90,7 +107,7 @@ namespace Passer {
protected void Update() { protected void Update() {
if (loadedAssetBundle != currentAssetBundle) { if (loadedAssetBundle != currentAssetBundle) {
if (loadedAssetBundle != null) { if (loadedAssetBundle != null) {
Debug.Log("unload"); Debug.Log("unload " + loadedAssetBundle.name);
loadedAssetBundle.Unload(false); loadedAssetBundle.Unload(false);
} }
@ -114,10 +131,10 @@ namespace Passer {
/// <summary> /// <summary>
/// Change the current Site /// Change the current Site
/// </summary> /// </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) /// The URL should not include a protocol (like https://) or an extension (like .site or .windows.site)
public void LoadSiteFromURL(string vrsiteName) { public void LoadSiteFromURL(string siteLocation) {
StartCoroutine(LoadSite(vrsiteName)); SiteNavigator.instance.StartCoroutine(LoadSite(siteLocation));
} }
protected static IEnumerator LoadSite(string siteLocation) { protected static IEnumerator LoadSite(string siteLocation) {
@ -140,6 +157,7 @@ namespace Passer {
} }
string scenePath = null; string scenePath = null;
HistoryEntry foundEntry = cache.Find(entry => entry.siteLocation == siteLocation); HistoryEntry foundEntry = cache.Find(entry => entry.siteLocation == siteLocation);
// cache is disabled because we unload the asset bundles // cache is disabled because we unload the asset bundles
foundEntry = null; foundEntry = null;
@ -152,10 +170,10 @@ namespace Passer {
string url = "https://" + siteLocation + ".windows" + ".site"; string url = "https://" + siteLocation + ".windows" + ".site";
#endif #endif
Debug.Log("Loading site: " + url);
//ShowLoadingDialog(); //ShowLoadingDialog();
GameObject dialog = ShowDialog("Loading..."); GameObject dialog = ShowDialog("Loading...");
Debug.Log("Loading site: " + url);
UnityWebRequest request = UnityWebRequestAssetBundle.GetAssetBundle(url); UnityWebRequest request = UnityWebRequestAssetBundle.GetAssetBundle(url);
yield return request.SendWebRequest(); yield return request.SendWebRequest();
@ -242,8 +260,13 @@ namespace Passer {
} }
public void ReloadSite() { public void ReloadSite() {
if (currentSite != null) if (currentSite != null) {
if (currentAssetBundle != null) {
Debug.Log("unload " + currentAssetBundle.name);
currentAssetBundle.Unload(false);
}
LoadSiteFromURL(currentSite.siteLocation); LoadSiteFromURL(currentSite.siteLocation);
}
} }
private static void DestroyAllSocketAttachments() { private static void DestroyAllSocketAttachments() {

View File

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