string GetAssetBundleNameByIndex(ShieldLocation location, int index) { if (index == -1) { return(string.Empty); } return(locationAssetBundlesDictionary[location][index]); }
int GetIdFromIndex(ShieldLocation location, int index) { if (index == -1) { return(-1); } return(GetIdFromAssetBundleName(location, locationAssetBundlesDictionary[location][index])); }
static IEnumerator <object> InstantiateShieldLocation(string assetBundleName, ShieldLocation keySelection, Vector3 position = default, int parentIndex = -1) { if (string.IsNullOrEmpty(assetBundleName)) { Logger.Log("Skipping empty asset bundle"); yield break; } AssetBundle downloadedAssetBundle = null; UnityWebRequest request = null; cachedAssetBundles = AssetBundle.GetAllLoadedAssetBundles().ToList(); AssetBundle cachedAssetBundle = cachedAssetBundles.FirstOrDefault(a => a.name == assetBundleName); if (cachedAssetBundle == null) { string uri = Constants.Routes.BackendIp + assetBundleName; Logger.Log($"Request {uri}", Logger.LogLevel.Info); request = UnityWebRequestAssetBundle.GetAssetBundle(uri, 0); yield return(request.SendWebRequest()); if (request.isNetworkError || request.isHttpError) { DebugText.text += "NetworkError, HttpError " + request.error; Logger.Log($"NetworkError, HttpError : " + request.error, Logger.LogLevel.Error); yield break; } downloadedAssetBundle = DownloadHandlerAssetBundle.GetContent(request); } else { downloadedAssetBundle = cachedAssetBundle; } if (downloadedAssetBundle == null) { Logger.Log("Failed to load AssetBundle! Download failed for " + assetBundleName + request.error + request.downloadHandler.text, Logger.LogLevel.Error); yield break; } try { var go = Utils.InstantiateAssetBundle(downloadedAssetBundle, position, parentIndex < 0 ? CurrentParent : CaptureParents[parentIndex]); var importablePrefab = go.GetComponent <ImportablePrefab>(); var assetBundleDef = importablePrefab.AssetBundleDefinition; } catch (Exception e) { Logger.Log(e.Message + e.StackTrace, Logger.LogLevel.Error); DebugText.text += e.Message; } }
static int GetRandomShieldLocationIndex(ShieldLocation location, bool acceptsNone = false, params int[] bannedIndexes) { var shieldLocationBundlesCount = locationAssetBundlesDictionary[location].Count(); int randomIndex = 0; if (shieldLocationBundlesCount > 1) { randomIndex = Utils.Random(acceptsNone ? -1 : 0, shieldLocationBundlesCount, bannedIndexes); } return(randomIndex); }
int GetIdFromAssetBundleName(ShieldLocation location, string assetBundleName) { var result = assetBundleName.Replace(Constants.Prefixes.AssetBundleLocation + location.Value + "_", string.Empty); var indexOf_ = result.IndexOf("_"); result = result.Replace(result.Substring(indexOf_, result.Length - indexOf_), string.Empty); try { return(int.Parse(result)); } catch { Logger.Log($"Parse error for Asset Bundle Name {assetBundleName}", Logger.LogLevel.Error); return(-1); } }
string GetAssetBundleNameById(ShieldLocation location, int id) { if (id < 0) { return(string.Empty); } var locationAssetBundles = locationAssetBundlesDictionary[location]; foreach (var assetBundleName in locationAssetBundles) { if (GetIdFromAssetBundleName(location, assetBundleName) == id) { return(assetBundleName); } } return(string.Empty); }