From f60f7a5634c65073e6515b8f43e4552ecfabe059 Mon Sep 17 00:00:00 2001 From: Pascal Serrarens Date: Mon, 21 Feb 2022 16:53:00 +0100 Subject: [PATCH] Make possession retrieve cross-platform --- .../Visitors/Scripts/VisitorPossessions.cs | 35 ++++++++++++------- 1 file changed, 22 insertions(+), 13 deletions(-) diff --git a/Runtime/Visitors/Scripts/VisitorPossessions.cs b/Runtime/Visitors/Scripts/VisitorPossessions.cs index 7a96146..d6f2815 100644 --- a/Runtime/Visitors/Scripts/VisitorPossessions.cs +++ b/Runtime/Visitors/Scripts/VisitorPossessions.cs @@ -200,12 +200,14 @@ namespace Passer { StartCoroutine(RetrievePossessionAsync(possession)); } - //public void RetrievePossession(PersistentPossession possession, System.Action callback) { - // StartCoroutine(RetrievePossessionAsync(possession, callback)); - //} - private static IEnumerator RetrievePossessionAsync(Possession possession) { - string url = "https://" + possession.siteLocation + ".windows" + ".site"; +#if UNITY_ANDROID + string url = "https://" + possession.siteLocation + ".android.site"; +#elif UNITY_WEBGL + string url = "https://" + possession.siteLocation + ".webgl.site"; +#else + string url = "https://" + possession.siteLocation + ".windows.site"; +#endif Debug.Log("Loading possession: " + url); UnityWebRequest request = UnityWebRequestAssetBundle.GetAssetBundle(url); @@ -234,10 +236,15 @@ namespace Passer { prefab.SetActive(false); } else { - Debug.Log("Cache size: " + cache.Count); CachedPossession foundPossession = cache.Find(entry => entry.siteLocation == possession.siteLocation); if (foundPossession == null) { - string url = "https://" + possession.siteLocation + ".windows" + ".site"; +#if UNITY_ANDROID + string url = "https://" + possession.siteLocation + ".android.site"; +#elif UNITY_WEBGL + string url = "https://" + possession.siteLocation + ".webgl.site"; +#else + string url = "https://" + possession.siteLocation + ".windows.site"; +#endif Debug.Log("Loading possession: " + url); UnityWebRequest request = UnityWebRequestAssetBundle.GetAssetBundle(url); @@ -286,7 +293,13 @@ namespace Passer { Debug.Log("Cache size: " + cache.Count); CachedPossession foundPossession = cache.Find(entry => entry.siteLocation == possessableLocation); if (foundPossession == null) { - string url = "https://" + possessableLocation + ".windows" + ".site"; +#if UNITY_ANDROID + string url = "https://" + possessableLocation + ".android.site"; +#elif UNITY_WEBGL + string url = "https://" + possessableLocation + ".webgl.site"; +#else + string url = "https://" + possessableLocation + ".windows.site"; +#endif Debug.Log("Loading possession: " + url); UnityWebRequest request = UnityWebRequestAssetBundle.GetAssetBundle(url); @@ -302,13 +315,9 @@ namespace Passer { int lastSlashIx = possessablePath.LastIndexOf('/'); if (lastSlashIx >= 0) possessableName = possessablePath.Substring( + 1); - //string[] assetPaths = assetBundle.GetAllAssetNames(); - //foreach (string assetPath in assetPaths) { - // Debug.Log(" " + assetPath); - //} Debug.Log("Load: " + possessablePath); - prefab = assetBundle.LoadAsset(possessableName); // possessablePath); + prefab = assetBundle.LoadAsset(possessableName); if (prefab == null) { Debug.LogError("Could not load " + possessablePath); yield break;