public static AssetBundle TryLoadBundle(IAssetBundleResource resource) { AssetBundleRequestOptions requestOptions = GetOptions(resource); if (requestOptions == null) { Debug.LogFormat("[{0}.{1}] Missing RequestOptions", nameof(AssetBundleCache), nameof(TryLoadBundle)); return(null); } if (assetBundles.TryGetValue(requestOptions.BundleName, out LoadedAssetBundle loadedAssetBundle)) { if (loadedAssetBundle.Matches(requestOptions) && loadedAssetBundle.assetBundle != null) { Debug.LogFormat("[{0}.{1}] assetBundle={2} already loaded", nameof(AssetBundleCache), nameof(TryLoadBundle), requestOptions.BundleName); return(loadedAssetBundle.assetBundle); } Debug.LogFormat("[{0}.{1}] assetBundle={2} unloading", nameof(AssetBundleCache), nameof(TryLoadBundle), requestOptions.BundleName); loadedAssetBundle.Unload(); } Debug.LogFormat("[{0}.{1}] assetBundle={2} loading", nameof(AssetBundleCache), nameof(TryLoadBundle), requestOptions.BundleName); AssetBundle assetBundle = resource.GetAssetBundle(); loadedAssetBundle = new LoadedAssetBundle(requestOptions.BundleName, requestOptions.Hash, requestOptions.Crc, assetBundle); assetBundles[requestOptions.BundleName] = loadedAssetBundle; Debug.LogFormat("[{0}.{1}] assetBundle={2} loaded={3}", nameof(AssetBundleCache), nameof(TryLoadBundle), requestOptions.BundleName, assetBundle != null); return(assetBundle); }
internal void Start(ProvideHandle provideHandle) { m_ActiveHandler = null; this.m_ProvideHandle = provideHandle; m_Options = provideHandle.Location.Data as AssetBundleRequestOptions; foreach (var module in m_Modules) { if (!module.TryBeginOperation(provideHandle, m_Options, OnCompleted)) { continue; } if (!m_IsSynchronous) { return; } Debug.LogFormat("[{0}.{1}] path={2} module={3} success={4}", nameof(ModularAssetBundleResource), nameof(Start), Path.GetFileNameWithoutExtension(provideHandle.Location.InternalId), module.GetType().Name, m_AssetBundle != null); bool success = m_AssetBundle != null; provideHandle.Complete(this, success, m_OperationException); return; } Debug.LogFormat("[{0}.{1}] path={2} Invalid Path", nameof(ModularAssetBundleResource), nameof(Start), Path.GetFileNameWithoutExtension(provideHandle.Location.InternalId)); provideHandle.Complete(this, false, new Exception($"Invalid path in AssetBundleProvider: '{provideHandle.Location}'.")); }
public void AssetBundleRequestOptionsTest() { var options = new AssetBundleRequestOptions { ChunkedTransfer = true, Crc = 123, Hash = new Hash128(1, 2, 3, 4).ToString(), RedirectLimit = 4, RetryCount = 7, Timeout = 12 }; var dataEntry = new ContentCatalogDataEntry(typeof(ContentCatalogData), "internalId", "provider", new object[] { 1 }, null, options); var entries = new List <ContentCatalogDataEntry>(); entries.Add(dataEntry); var ccData = new ContentCatalogData(entries); var locator = ccData.CreateLocator(); IList <IResourceLocation> locations; if (!locator.Locate(1, typeof(object), out locations)) { Assert.Fail("Unable to locate resource location"); } var loc = locations[0]; var locOptions = loc.Data as AssetBundleRequestOptions; Assert.IsNotNull(locOptions); Assert.AreEqual(locOptions.ChunkedTransfer, options.ChunkedTransfer); Assert.AreEqual(locOptions.Crc, options.Crc); Assert.AreEqual(locOptions.Hash, options.Hash); Assert.AreEqual(locOptions.RedirectLimit, options.RedirectLimit); Assert.AreEqual(locOptions.RetryCount, options.RetryCount); Assert.AreEqual(locOptions.Timeout, options.Timeout); }
public IEnumerator WhenWebRequestFails_RetriesCorrectAmount_AssetBundleProvider() { var prev = LogAssert.ignoreFailingMessages; LogAssert.ignoreFailingMessages = true; var nonExistingPath = "http://127.0.0.1/non-existing-bundle"; var loc = new ResourceLocationBase(nonExistingPath, nonExistingPath, typeof(AssetBundleProvider).FullName, typeof(AssetBundleResource)); var d = new AssetBundleRequestOptions(); d.RetryCount = 3; loc.Data = d; LogAssert.Expect(LogType.Log, new Regex(@"^(Web request failed, retrying \(0/3)")); LogAssert.Expect(LogType.Log, new Regex(@"^(Web request failed, retrying \(1/3)")); LogAssert.Expect(LogType.Log, new Regex(@"^(Web request failed, retrying \(2/3)")); var h = m_Addressables.ResourceManager.ProvideResource <AssetBundleResource>(loc); yield return(h); if (h.IsValid()) { h.Release(); } LogAssert.ignoreFailingMessages = prev; }
static void PostProcessBundles(AddressableAssetGroup assetGroup, List <string> bundles, IBundleBuildResults buildResult, IWriteData writeData, ResourceManagerRuntimeData runtimeData, List <ContentCatalogDataEntry> locations, FileRegistry registry) { var schema = assetGroup.GetSchema <BundledAssetGroupSchema>(); if (schema == null) { return; } var path = schema.BuildPath.GetValue(assetGroup.Settings); if (string.IsNullOrEmpty(path)) { return; } foreach (var originalBundleName in bundles) { var newBundleName = originalBundleName; var info = buildResult.BundleInfos[newBundleName]; ContentCatalogDataEntry dataEntry = locations.FirstOrDefault(s => newBundleName == (string)s.Keys[0]); if (dataEntry != null) { var requestOptions = new AssetBundleRequestOptions { Crc = schema.UseAssetBundleCrc ? info.Crc : 0, Hash = schema.UseAssetBundleCache ? info.Hash.ToString() : "", ChunkedTransfer = schema.ChunkedTransfer, RedirectLimit = schema.RedirectLimit, RetryCount = schema.RetryCount, Timeout = schema.Timeout, BundleName = Path.GetFileName(info.FileName), BundleSize = GetFileSize(info.FileName) }; dataEntry.Data = requestOptions; dataEntry.InternalId = BuildUtility.GetNameWithHashNaming(schema.BundleNaming, info.Hash.ToString(), dataEntry.InternalId); newBundleName = BuildUtility.GetNameWithHashNaming(schema.BundleNaming, info.Hash.ToString(), newBundleName); } else { Debug.LogWarningFormat("Unable to find ContentCatalogDataEntry for bundle {0}.", newBundleName); } var targetPath = Path.Combine(path, newBundleName); if (!Directory.Exists(Path.GetDirectoryName(targetPath))) { Directory.CreateDirectory(Path.GetDirectoryName(targetPath)); } File.Copy(Path.Combine(assetGroup.Settings.buildSettings.bundleBuildPath, originalBundleName), targetPath, true); registry.AddFile(targetPath); } }
public bool TryBeginOperation(ProvideHandle provideHandle) { string path = provideHandle.ResourceManager.TransformInternalId(provideHandle.Location); if (!File.Exists(path)) { return(false); } options = provideHandle.Location.Data as AssetBundleRequestOptions; provideHandle.SetProgressCallback(PercentComplete); BeginOperation(path); return(true); }
public bool TryBeginOperation(ProvideHandle provideHandle, AssetBundleRequestOptions options, Action <IAssetBundleResourceHandler, AssetBundle, Exception> completedCallback) { string path = provideHandle.ResourceManager.TransformInternalId(provideHandle.Location); if (!IsValidPath(path)) { return(false); } m_CompletedCallback = completedCallback; m_ProvideHandle = provideHandle; m_Options = options; provideHandle.SetProgressCallback(PercentComplete); BeginOperation(path); return(true); }
public bool TryBeginOperation(ProvideHandle provideHandle) { retries = 0; assetBundle = null; downloadHandler = null; this.provideHandle = provideHandle; string path = provideHandle.ResourceManager.TransformInternalId(provideHandle.Location); if (!ResourceManagerConfig.ShouldPathUseWebRequest(path)) { return(false); } options = provideHandle.Location.Data as AssetBundleRequestOptions; provideHandle.SetProgressCallback(PercentComplete); BeginOperation(); return(true); }
/// <summary> /// コンストラクタ /// </summary> public JsonAssetBundleResourceData ( [NotNull] ResourceManager resourceManager, [NotNull] AssetBundleRequestOptions options, [NotNull] IResourceLocation location ) { Url = resourceManager.TransformInternalId(location); Hash = options.Hash; Crc = options.Crc; Timeout = options.Timeout; RedirectLimit = options.RedirectLimit; RetryCount = options.RetryCount; BundleName = options.BundleName; BundleSize = options.BundleSize; UseCrcForCachedBundle = options.UseCrcForCachedBundle; InternalId = location.InternalId; ProviderId = location.ProviderId; DependencyHashCode = location.DependencyHashCode; HasDependencies = location.HasDependencies; PrimaryKey = location.PrimaryKey; ResourceTypeName = location.ResourceType.Name; }
void PostProcessBundles(AddressableAssetGroup assetGroup, List <string> buildBundles, List <string> outputBundles, IBundleBuildResults buildResult, IWriteData writeData, ResourceManagerRuntimeData runtimeData, List <ContentCatalogDataEntry> locations, FileRegistry registry, Dictionary <string, ContentCatalogDataEntry> primaryKeyToCatalogEntry) { var schema = assetGroup.GetSchema <BundledAssetGroupSchema>(); if (schema == null) { return; } var path = schema.BuildPath.GetValue(assetGroup.Settings); if (string.IsNullOrEmpty(path)) { return; } for (int i = 0; i < buildBundles.Count; ++i) { if (primaryKeyToCatalogEntry.TryGetValue(buildBundles[i], out ContentCatalogDataEntry dataEntry)) { var info = buildResult.BundleInfos[buildBundles[i]]; var requestOptions = new AssetBundleRequestOptions { Crc = schema.UseAssetBundleCrc ? info.Crc : 0, Hash = schema.UseAssetBundleCache ? info.Hash.ToString() : "", ChunkedTransfer = schema.ChunkedTransfer, RedirectLimit = schema.RedirectLimit, RetryCount = schema.RetryCount, Timeout = schema.Timeout, BundleName = Path.GetFileName(info.FileName), BundleSize = GetFileSize(info.FileName) }; dataEntry.Data = requestOptions; int extensionLength = Path.GetExtension(outputBundles[i]).Length; string[] deconstructedBundleName = outputBundles[i].Substring(0, outputBundles[i].Length - extensionLength).Split('_'); string reconstructedBundleName = string.Join("_", deconstructedBundleName, 1, deconstructedBundleName.Length - 1) + ".bundle"; outputBundles[i] = ConstructAssetBundleName(assetGroup, schema, info, reconstructedBundleName); dataEntry.InternalId = dataEntry.InternalId.Remove(dataEntry.InternalId.Length - buildBundles[i].Length) + outputBundles[i]; dataEntry.Keys[0] = outputBundles[i]; ReplaceDependencyKeys(buildBundles[i], outputBundles[i], locations); if (!m_BundleToInternalId.ContainsKey(buildBundles[i])) { m_BundleToInternalId.Add(buildBundles[i], dataEntry.InternalId); } if (dataEntry.InternalId.StartsWith("http:\\")) { dataEntry.InternalId = dataEntry.InternalId.Replace("http:\\", "http://").Replace("\\", "/"); } if (dataEntry.InternalId.StartsWith("https:\\")) { dataEntry.InternalId = dataEntry.InternalId.Replace("https:\\", "https://").Replace("\\", "/"); } } else { Debug.LogWarningFormat("Unable to find ContentCatalogDataEntry for bundle {0}.", outputBundles[i]); } var targetPath = Path.Combine(path, outputBundles[i]); if (!Directory.Exists(Path.GetDirectoryName(targetPath))) { Directory.CreateDirectory(Path.GetDirectoryName(targetPath)); } File.Copy(Path.Combine(assetGroup.Settings.buildSettings.bundleBuildPath, buildBundles[i]), targetPath, true); registry.AddFile(targetPath); } }
public bool Matches(AssetBundleRequestOptions requestOptions) { return(requestOptions.Hash == hash); }
static void PostProcessBundles(AddressableAssetGroup assetGroup, List <string> bundles, IBundleBuildResults buildResult, IWriteData writeData, ResourceManagerRuntimeData runtimeData, List <ContentCatalogDataEntry> locations, FileRegistry registry) { var schema = assetGroup.GetSchema <BundledAssetGroupSchema>(); if (schema == null) { return; } var path = schema.BuildPath.GetValue(assetGroup.Settings); if (string.IsNullOrEmpty(path)) { return; } foreach (var originalBundleName in bundles) { var newBundleName = originalBundleName; var info = buildResult.BundleInfos[newBundleName]; ContentCatalogDataEntry dataEntry = locations.FirstOrDefault(s => newBundleName == (string)s.Keys[0]); if (dataEntry != null) { var requestOptions = new AssetBundleRequestOptions { Crc = schema.UseAssetBundleCrc ? info.Crc : 0, Hash = schema.UseAssetBundleCache ? info.Hash.ToString() : "", ChunkedTransfer = schema.ChunkedTransfer, RedirectLimit = schema.RedirectLimit, RetryCount = schema.RetryCount, Timeout = schema.Timeout, BundleName = Path.GetFileName(info.FileName), BundleSize = GetFileSize(info.FileName) }; dataEntry.Data = requestOptions; int extensionLength = Path.GetExtension(originalBundleName).Length; string[] deconstructedBundleName = originalBundleName.Substring(0, originalBundleName.Length - extensionLength) .Split('_'); deconstructedBundleName[0] = assetGroup.Name .Replace(" ", "") .Replace('\\', '/') .Replace("//", "/") .ToLower(); string reconstructedBundleName = string.Join("_", deconstructedBundleName) + ".bundle"; newBundleName = BuildUtility.GetNameWithHashNaming(schema.BundleNaming, info.Hash.ToString(), reconstructedBundleName); dataEntry.InternalId = dataEntry.InternalId.Remove(dataEntry.InternalId.Length - originalBundleName.Length) + newBundleName; if (dataEntry.InternalId.StartsWith("http:\\")) { dataEntry.InternalId = dataEntry.InternalId.Replace("http:\\", "http://").Replace("\\", "/"); } } else { Debug.LogWarningFormat("Unable to find ContentCatalogDataEntry for bundle {0}.", newBundleName); } var targetPath = Path.Combine(path, newBundleName); if (!Directory.Exists(Path.GetDirectoryName(targetPath))) { Directory.CreateDirectory(Path.GetDirectoryName(targetPath)); } File.Copy(Path.Combine(assetGroup.Settings.buildSettings.bundleBuildPath, originalBundleName), targetPath, true); registry.AddFile(targetPath); } }