Make possession retrieve cross-platform

This commit is contained in:
Pascal Serrarens 2022-02-21 16:53:00 +01:00
parent c512dd42c3
commit f60f7a5634

View File

@ -200,12 +200,14 @@ namespace Passer {
StartCoroutine(RetrievePossessionAsync(possession)); StartCoroutine(RetrievePossessionAsync(possession));
} }
//public void RetrievePossession(PersistentPossession possession, System.Action<GameObject> callback) {
// StartCoroutine(RetrievePossessionAsync(possession, callback));
//}
private static IEnumerator RetrievePossessionAsync(Possession possession) { 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); Debug.Log("Loading possession: " + url);
UnityWebRequest request = UnityWebRequestAssetBundle.GetAssetBundle(url); UnityWebRequest request = UnityWebRequestAssetBundle.GetAssetBundle(url);
@ -234,10 +236,15 @@ namespace Passer {
prefab.SetActive(false); prefab.SetActive(false);
} }
else { else {
Debug.Log("Cache size: " + cache.Count);
CachedPossession foundPossession = cache.Find(entry => entry.siteLocation == possession.siteLocation); CachedPossession foundPossession = cache.Find(entry => entry.siteLocation == possession.siteLocation);
if (foundPossession == null) { 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); Debug.Log("Loading possession: " + url);
UnityWebRequest request = UnityWebRequestAssetBundle.GetAssetBundle(url); UnityWebRequest request = UnityWebRequestAssetBundle.GetAssetBundle(url);
@ -286,7 +293,13 @@ namespace Passer {
Debug.Log("Cache size: " + cache.Count); Debug.Log("Cache size: " + cache.Count);
CachedPossession foundPossession = cache.Find(entry => entry.siteLocation == possessableLocation); CachedPossession foundPossession = cache.Find(entry => entry.siteLocation == possessableLocation);
if (foundPossession == null) { 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); Debug.Log("Loading possession: " + url);
UnityWebRequest request = UnityWebRequestAssetBundle.GetAssetBundle(url); UnityWebRequest request = UnityWebRequestAssetBundle.GetAssetBundle(url);
@ -302,13 +315,9 @@ namespace Passer {
int lastSlashIx = possessablePath.LastIndexOf('/'); int lastSlashIx = possessablePath.LastIndexOf('/');
if (lastSlashIx >= 0) if (lastSlashIx >= 0)
possessableName = possessablePath.Substring( + 1); possessableName = possessablePath.Substring( + 1);
//string[] assetPaths = assetBundle.GetAllAssetNames();
//foreach (string assetPath in assetPaths) {
// Debug.Log(" " + assetPath);
//}
Debug.Log("Load: " + possessablePath); Debug.Log("Load: " + possessablePath);
prefab = assetBundle.LoadAsset<GameObject>(possessableName); // possessablePath); prefab = assetBundle.LoadAsset<GameObject>(possessableName);
if (prefab == null) { if (prefab == null) {
Debug.LogError("Could not load " + possessablePath); Debug.LogError("Could not load " + possessablePath);
yield break; yield break;