private void OnAssetBundleNameToUrlMapResolved(Dictionary <string, string> map) { pendingUrlResolveRequest = null; assetBundleNameToUrl = map; InvokePendingPrepareTemplates(); }
public void CancelAllTemplatePreparations() { if (pendingUrlResolveRequest != null) { pendingUrlResolveRequest.Cancel(); pendingUrlResolveRequest = null; } if (pendingPrepareTemplates != null) { pendingPrepareTemplates = null; return; } if (templateProvider != null) { templateProvider.CancelAllTemplatePreparations(); } }
protected virtual IAssetLoader <GameObject> InitializeAssetLoader() { var projectName = SpatialOS.Configuration.ProjectName; var deployment = SpatialOS.Deployment; var assemblyName = deployment.HasValue ? deployment.Value.AssemblyName : SpatialOS.Configuration.AssemblyName; // If an assembly name is set, default to streaming from it. The strategy can still be overridden by the command line. AssetDatabaseStrategy defaultStrategy = AssetDatabaseStrategy.Local; if (!string.IsNullOrEmpty(projectName) && !string.IsNullOrEmpty(assemblyName)) { defaultStrategy = AssetDatabaseStrategy.Streaming; } UseLocalPrefabs = SpatialOS.Configuration.GetCommandLineValue(CommandLineConfigNames.UseLocalPrefabs, UseLocalPrefabs); LoadingStrategy = SpatialOS.Configuration.GetCommandLineValue(CommandLineConfigNames.AssetDatabaseStrategy, defaultStrategy); LocalAssetDatabasePath = SpatialOS.Configuration.GetCommandLineValue(CommandLineConfigNames.LocalAssetDatabasePath, LocalAssetDatabasePath); IAssetLoader <GameObject> gameObjectLoader; if (Application.isEditor && UseLocalPrefabs) { gameObjectLoader = new PrefabGameObjectLoader(); } else { switch (LoadingStrategy) { case AssetDatabaseStrategy.Local: var path = Path.GetFullPath(LocalAssetDatabasePath); gameObjectLoader = new GameObjectFromAssetBundleLoader(new LocalAssetBundleLoader(path)); break; case AssetDatabaseStrategy.Streaming: pendingPrepareTemplates = new List <Action>(); var cachePath = Path.Combine(Application.persistentDataPath, "cache" + WorkerTypeUtils.ToWorkerName(SpatialOS.Configuration.WorkerPlatform)); Directory.CreateDirectory(cachePath); var assetBundleDownloader = new AssetBundleDownloader(cachePath, new MachineCache <byte[], AssetBundle>(Path.Combine(cachePath, "assets"), new AssetBundlePersistenceStrategy()), new MachineCache <CacheEntry, CacheEntry>(Path.Combine(cachePath, "asset-metadata"), new AssetMetadataPersistenceStrategy()), new WWWRequest(), this); assetBundleDownloader.GetAssetUrl = GetAssetUrl; var exponentialBackoffRetryAssetLoader = gameObject.GetComponent <ExponentialBackoffRetryAssetLoader>() ?? gameObject.AddComponent <ExponentialBackoffRetryAssetLoader>(); exponentialBackoffRetryAssetLoader.Init(assetBundleDownloader, SpatialOS.Configuration.GetCommandLineValue(CommandLineConfigNames.MaxAssetLoadingRetries, -1), SpatialOS.Configuration.GetCommandLineValue(CommandLineConfigNames.AssetLoadingRetryBackoffMilliseconds, -1)); gameObjectLoader = new GameObjectFromAssetBundleLoader(exponentialBackoffRetryAssetLoader); pendingUrlResolveRequest = CloudAssemblyArtifactResolver.ResolveAssetUrls(this, new WWWRequest(), SpatialOS.Configuration.InfraServiceUrl, projectName, assemblyName, OnAssetBundleNameToUrlMapResolved, OnAssetResolveFailed); break; default: throw new Exception(string.Format("Unknown loading strategy '{0}'", LoadingStrategy)); } } return(gameObjectLoader); }
private void OnAssetResolveFailed(Exception err) { pendingUrlResolveRequest = null; throw err; }