public static IResourceLocation GetRelatedResourceLocation(IResourceLocation location) { EmbeddedLocation el = location as EmbeddedLocation; if (el != null) { string fn = el.ResourceName + ".resources"; if (ResourcesExists(el.Assembly, fn)) return new EmbeddedLocation(el.Assembly, fn); int i = el.ResourceName.LastIndexOf('.'); if (i > 0) { fn = el.ResourceName.Substring(0, i) + ".resources"; if (ResourcesExists(el.Assembly, fn)) return new EmbeddedLocation(el.Assembly, fn); } return null; } TypeLocation tl = location as TypeLocation; if (tl != null) { string fn = tl.ProxyType.FullName + ".resources"; if (ResourcesExists(tl.ProxyType.Assembly, fn)) return new EmbeddedLocation(tl.ProxyType.Assembly, fn); } return null; }
public ResourceMapping(VirtualPath root, IResourceLocation location) { if (root.Type != VirtualPathType.AppRelative) { throw new ArgumentException("The root path must be app-relative."); } Root = root; Location = location; }
public override IResource GetResource(IResourceLocation location) { EmbeddedLocation el = location as EmbeddedLocation; if (el != null && el.FileName.EndsWith(".resources", StringComparison.InvariantCultureIgnoreCase)) return new FileResourceProxy(el); else return null; }
public override IResource GetResource(IResourceLocation location) { FileLocation l = location as FileLocation; if (l == null) return null; if (!l.FileName.EndsWith(".html", StringComparison.InvariantCultureIgnoreCase)) { ExternalLocation el = l as ExternalLocation; if (el == null || el.Mime == null || !el.Mime.EndsWith("/html", StringComparison.InvariantCultureIgnoreCase)) return null; } return new HtmlProxy(l); }
public static IResourceLocation GetLocation(IResourceLocation baseLocation, string assembly, string name) { if (assembly != null) { Assembly a = Assembly.Load(assembly); return GetAssemblyLocation(a, name); } if (isUrl.IsMatch(name)) { return new ExternalLocation(name); } return baseLocation.GetRelativeLocation(name); }
public ResourcePackage(IResourceConfiguration configuration, IResourceLocation packageLocation, IEnumerable<IResourceLocation> locations) { _package = configuration.GetResource(packageLocation); if (locations == null) return; List<IResource> res = new List<IResource>(); foreach (IResourceLocation l in locations) { IResource r = configuration.GetResource(l); if (r != null) res.Add(r); } _includedResources = res.Count > 0 ? res.ToArray() : null; }
public override IResource GetResource(IResourceLocation location) { FileLocation l = location as FileLocation; if (l == null) return null; if (!l.FileName.EndsWith(".class.swf", StringComparison.InvariantCultureIgnoreCase)) return null; string className = l.FileName.Substring(0, l.FileName.Length - 10); IResource swiffCode = base.Configuration.GetResource(new EmbeddedLocation(typeof(SwiffClassFactory).Assembly, "Calyptus.SwiffClass.js")); if (l is EmbeddedLocation) return new ProxySwiffClassResource(l, className, swiffCode); else return new PlainSwiffClassResource(l, className, swiffCode); }
public static string ConvertUrls(string css, IResourceLocation baseLocation, IResourceURLFactory urlFactory, IEnumerable<IImageResource> includedImages) { return _urlParser.Replace(css, m => { string assembly = m.Groups[2].Success ? m.Groups[1].Value : null; string filename = m.Groups[2].Success ? m.Groups[2].Value : m.Groups[1].Value; IResourceLocation location = ResourceLocations.GetLocation(baseLocation, assembly, filename); if (location == null) return m.Groups[0].Value; if (includedImages != null) foreach (IImageResource res in includedImages) if (location.Equals(res.Location)) return GetBase64URL(res); return urlFactory.GetURL(new UnknownResource(location)); }); }
public override IResource GetResource(IResourceLocation location) { FileLocation l = location as FileLocation; if (l == null) return null; if (!l.FileName.EndsWith(".swf", StringComparison.InvariantCultureIgnoreCase)) { ExternalLocation el = l as ExternalLocation; if (el == null || el.Mime == null || !el.Mime.Equals("application/x-shockwave-flash", StringComparison.OrdinalIgnoreCase)) return null; } if (l is EmbeddedLocation) return new ProxyFlashResource(l); else return new PlainFlashResource(l); }
public RoutingResourceHttpHandler(RequestContext context) { var values = context.RouteData.Values; var assembly = (values["assembly"] as string) ?? context.HttpContext.Request.QueryString["assembly"]; var path = ((values["name"] ?? values["path"]) as string) ?? context.HttpContext.Request.QueryString["name"]; if (assembly != null) location = ResourceLocations.GetAssemblyLocation(Assembly.Load(assembly), path); else location = new VirtualPathLocation("~/", path); version = (context.RouteData.Values["version"] as string) ?? context.HttpContext.Request.QueryString["version"]; culture = (context.RouteData.Values["culture"] as string) ?? context.HttpContext.Request.QueryString["culture"]; cultureUI = (context.RouteData.Values["cultureUI"] as string) ?? context.HttpContext.Request.QueryString["cultureUI"]; urlFactory = new RoutingResourceURLFactory(context.RouteData.Route, context); }
public override IResource GetResource(IResourceLocation location) { FileLocation l = location as FileLocation; if (l == null) return null; string mime = GetMime(l.FileName); if (mime == null) { ExternalLocation el = l as ExternalLocation; if (el == null) return null; mime = el.Mime; if (!IsValidMime(mime)) return null; } if (l is EmbeddedLocation) return new ProxyImageResource(mime, l); else return new PlainImageResource(mime, l); }
public static AsyncOperationHandle <TObject> LoadAsset <TObject>(IResourceLocation location) { return(LoadAssetAsync <TObject>(location)); }
/// <summary> /// Load the <typeparamref name="TObject"/> at the specified <paramref name="location"/>. /// </summary> /// <returns>An async operation.</returns> /// <param name="location">Location to load.</param> /// <typeparam name="TObject">Object type to load.</typeparam> public AsyncOperationHandle <TObject> ProvideResource <TObject>(IResourceLocation location) { AsyncOperationHandle handle = ProvideResource(location, typeof(TObject)); return(handle.Convert <TObject>()); }
/// <summary> /// Construct a new UnknownResourceProviderException /// </summary> /// <param name="location">The location that caused the exception to be created.</param> public UnknownResourceProviderException(IResourceLocation location) { Location = location; }
public abstract void RenderLink(IResourceLocation location, IHtmlWriter writer, IDotvvmRequestContext context, string resourceName);
/// <summary> /// Create IResourceLocator object /// </summary> /// <param name="providerSuffix">If specified, this value will be appeneded to all provider ids. This is used when loading additional catalogs that need to have unique providers.</param> /// <returns>ResourceLocationMap, which implements the IResourceLocator interface.</returns> public ResourceLocationMap CreateLocator(string providerSuffix = null) { var bucketData = Convert.FromBase64String(m_BucketDataString); int bucketCount = BitConverter.ToInt32(bucketData, 0); var buckets = new Bucket[bucketCount]; int bi = 4; for (int i = 0; i < bucketCount; i++) { var index = SerializationUtilities.ReadInt32FromByteArray(bucketData, bi); bi += 4; var entryCount = SerializationUtilities.ReadInt32FromByteArray(bucketData, bi); bi += 4; var entryArray = new int[entryCount]; for (int c = 0; c < entryCount; c++) { entryArray[c] = SerializationUtilities.ReadInt32FromByteArray(bucketData, bi); bi += 4; } buckets[i] = new Bucket { entries = entryArray, dataOffset = index }; } if (!string.IsNullOrEmpty(providerSuffix)) { for (int i = 0; i < m_ProviderIds.Length; i++) { if (!m_ProviderIds[i].EndsWith(providerSuffix, StringComparison.Ordinal)) { m_ProviderIds[i] = m_ProviderIds[i] + providerSuffix; } } } var extraData = Convert.FromBase64String(m_ExtraDataString); var keyData = Convert.FromBase64String(m_KeyDataString); var keyCount = BitConverter.ToInt32(keyData, 0); var keys = new object[keyCount]; for (int i = 0; i < buckets.Length; i++) { keys[i] = SerializationUtilities.ReadObjectFromByteArray(keyData, buckets[i].dataOffset); } var locator = new ResourceLocationMap(m_LocatorId, buckets.Length); var entryData = Convert.FromBase64String(m_EntryDataString); int count = SerializationUtilities.ReadInt32FromByteArray(entryData, 0); var locations = new IResourceLocation[count]; for (int i = 0; i < count; i++) { var index = kBytesPerInt32 + i * (kBytesPerInt32 * k_EntryDataItemPerEntry); var internalId = SerializationUtilities.ReadInt32FromByteArray(entryData, index); index += kBytesPerInt32; var providerIndex = SerializationUtilities.ReadInt32FromByteArray(entryData, index); index += kBytesPerInt32; var dependencyKeyIndex = SerializationUtilities.ReadInt32FromByteArray(entryData, index); index += kBytesPerInt32; var depHash = SerializationUtilities.ReadInt32FromByteArray(entryData, index); index += kBytesPerInt32; var dataIndex = SerializationUtilities.ReadInt32FromByteArray(entryData, index); index += kBytesPerInt32; var primaryKey = SerializationUtilities.ReadInt32FromByteArray(entryData, index); index += kBytesPerInt32; var resourceType = SerializationUtilities.ReadInt32FromByteArray(entryData, index); object data = dataIndex < 0 ? null : SerializationUtilities.ReadObjectFromByteArray(extraData, dataIndex); locations[i] = new CompactLocation(locator, Addressables.ResolveInternalId(ExpandInternalId(m_InternalIdPrefixes, m_InternalIds[internalId])), m_ProviderIds[providerIndex], dependencyKeyIndex < 0 ? null : keys[dependencyKeyIndex], data, depHash, keys[primaryKey].ToString(), m_resourceTypes[resourceType].Value); } for (int i = 0; i < buckets.Length; i++) { var bucket = buckets[i]; var key = keys[i]; var locs = new IResourceLocation[bucket.entries.Length]; for (int b = 0; b < bucket.entries.Length; b++) { locs[b] = locations[bucket.entries[b]]; } locator.Add(key, locs); } return(locator); }
/// <summary> /// Creates a new instance of <see cref="ProviderException"/>. /// </summary> /// <param name="message">A message describing the error.</param> /// <param name="location">The resource location that the operation was trying to provide.</param> /// <param name="innerException">The exception that caused the error, if any.</param> public ProviderException(string message, IResourceLocation location = null, Exception innerException = null) : base(message, innerException) { Location = location; }
protected override void Execute() { Addressables.LogFormat("Addressables - runtime data operation completed with status = {0}, result = {1}.", m_rtdOp.Status, m_rtdOp.Result); if (m_rtdOp.Result == null) { Addressables.LogWarningFormat("Addressables - Unable to load runtime data at location {0}.", m_rtdOp); Complete(Result, false, string.Format("Addressables - Unable to load runtime data at location {0}.", m_rtdOp)); return; } #if UNITY_2019_3_OR_NEWER Addressables.LogFormat("Initializing Addressables version {0}.", m_rtdOp.Result.AddressablesVersion); #endif var rtd = m_rtdOp.Result; m_Addressables.ResourceManager.postProfilerEvents = rtd.ProfileEvents; WebRequestQueue.SetMaxConcurrentRequests(rtd.MaxConcurrentWebRequests); m_Addressables.CatalogRequestsTimeout = rtd.CatalogRequestsTimeout; foreach (var catalogLocation in rtd.CatalogLocations) { if (catalogLocation.Data != null && catalogLocation.Data is ProviderLoadRequestOptions loadData) { loadData.WebRequestTimeout = rtd.CatalogRequestsTimeout; } } m_Addressables.Release(m_rtdOp); if (rtd.CertificateHandlerType != null) { m_Addressables.ResourceManager.CertificateHandlerInstance = Activator.CreateInstance(rtd.CertificateHandlerType) as CertificateHandler; } #if UNITY_EDITOR if (UnityEditor.EditorUserBuildSettings.activeBuildTarget.ToString() != rtd.BuildTarget) { Addressables.LogErrorFormat("Addressables - runtime data was built with a different build target. Expected {0}, but data was built with {1}. Certain assets may not load correctly including shaders. You can rebuild player content via the Addressables window.", UnityEditor.EditorUserBuildSettings.activeBuildTarget, rtd.BuildTarget); } #endif if (!rtd.LogResourceManagerExceptions) { ResourceManager.ExceptionHandler = null; } if (!rtd.ProfileEvents) { m_Diagnostics.Dispose(); m_Diagnostics = null; m_Addressables.ResourceManager.ClearDiagnosticCallbacks(); } Addressables.Log("Addressables - loading initialization objects."); ContentCatalogProvider ccp = m_Addressables.ResourceManager.ResourceProviders .FirstOrDefault(rp => rp.GetType() == typeof(ContentCatalogProvider)) as ContentCatalogProvider; if (ccp != null) { ccp.DisableCatalogUpdateOnStart = rtd.DisableCatalogUpdateOnStartup; ccp.IsLocalCatalogInBundle = rtd.IsLocalCatalogInBundle; } var locMap = new ResourceLocationMap("CatalogLocator", rtd.CatalogLocations); m_Addressables.AddResourceLocator(locMap); IList <IResourceLocation> catalogs; if (!locMap.Locate(ResourceManagerRuntimeData.kCatalogAddress, typeof(ContentCatalogData), out catalogs)) { Addressables.LogWarningFormat( "Addressables - Unable to find any catalog locations in the runtime data."); m_Addressables.RemoveResourceLocator(locMap); Complete(Result, false, "Addressables - Unable to find any catalog locations in the runtime data."); } else { Addressables.LogFormat("Addressables - loading content catalogs, {0} found.", catalogs.Count); IResourceLocation remoteHashLocation = null; if (catalogs[0].Dependencies.Count == 2 && rtd.DisableCatalogUpdateOnStartup) { remoteHashLocation = catalogs[0].Dependencies[(int)ContentCatalogProvider.DependencyHashIndex.Remote]; catalogs[0].Dependencies[(int)ContentCatalogProvider.DependencyHashIndex.Remote] = catalogs[0].Dependencies[(int)ContentCatalogProvider.DependencyHashIndex.Cache]; } m_loadCatalogOp = LoadContentCatalogInternal(catalogs, 0, locMap, remoteHashLocation); } }
/// <summary> /// Release the specified object that was created from the specified location. /// </summary> /// <param name="location">The location of the object</param> /// <param name="obj">The object to release.</param> public virtual void Release(IResourceLocation location, object obj) { }
public StylesheetResource(IResourceLocation location) : base(ResourceRenderPosition.Head, "text/css", location) { }
/// <inheritdoc/> public AsyncOperationHandle <SceneInstance> ProvideScene(ResourceManager resourceManager, IResourceLocation location, LoadSceneMode loadMode, bool activateOnLoad, int priority) { AsyncOperationHandle <IList <AsyncOperationHandle> > depOp = default(AsyncOperationHandle <IList <AsyncOperationHandle> >); if (location.HasDependencies) { depOp = resourceManager.ProvideResourceGroupCached(location.Dependencies, location.DependencyHashCode, typeof(IAssetBundleResource), null); } SceneOp op = new SceneOp(resourceManager); op.Init(location, loadMode, activateOnLoad, priority, depOp); var handle = resourceManager.StartOperation <SceneInstance>(op, depOp); if (depOp.IsValid()) { depOp.Release(); } return(handle); }
/// <summary> /// Instantiate a single object. Note that the dependency loading is done asynchronously, but generally the actual instantiate is synchronous. /// </summary> /// <param name="location">The location of the Object to instantiate.</param> /// <param name="instantiateParameters">Parameters for instantiation.</param> /// <param name="trackHandle">If true, Addressables will track this request to allow it to be released via the result object.</param> /// <returns>The operation handle for the request.</returns> public static AsyncOperationHandle <GameObject> InstantiateAsync(IResourceLocation location, InstantiationParameters instantiateParameters, bool trackHandle = true) { return(m_Addressables.InstantiateAsync(location, instantiateParameters, trackHandle)); }
/// <summary> /// Asynchronouslly instantiate a prefab (GameObject) at the specified <paramref name="location"/>. /// </summary> /// <returns>Async operation that will complete when the prefab is instantiated.</returns> /// <param name="provider">An implementation of IInstanceProvider that will be used to instantiate and destroy the GameObject.</param> /// <param name="location">Location of the prefab.</param> /// <param name="instantiateParameters">A struct containing the parameters to pass the the Instantiation call.</param> public AsyncOperationHandle <GameObject> ProvideInstance(IInstanceProvider provider, IResourceLocation location, InstantiationParameters instantiateParameters) { if (provider == null) { throw new NullReferenceException("provider is null. Assign a valid IInstanceProvider object before using."); } if (location == null) { throw new ArgumentNullException("location"); } var depOp = ProvideResource <GameObject>(location); var baseOp = CreateOperation <InstanceOperation>(typeof(InstanceOperation), s_InstanceOperationTypeHash, 0, m_ReleaseInstanceOp); baseOp.Init(this, provider, instantiateParameters, depOp); m_TrackedInstanceOperations.Add(baseOp); return(StartOperation <GameObject>(baseOp, depOp)); }
/// <summary> /// Load a scene at a specificed resource location. /// </summary> /// <param name="sceneProvider">The scene provider instance.</param> /// <param name="location">The location of the scene.</param> /// <param name="loadMode">The load mode for the scene.</param> /// <param name="activateOnLoad">If false, the scene will be loaded in the background and not activated when complete.</param> /// <param name="priority">The priority for the load operation.</param> /// <returns>Async operation handle that will complete when the scene is loaded. If activateOnLoad is false, then Activate() will need to be called on the SceneInstance returned.</returns> public AsyncOperationHandle <SceneInstance> ProvideScene(ISceneProvider sceneProvider, IResourceLocation location, LoadSceneMode loadMode, bool activateOnLoad, int priority) { if (sceneProvider == null) { throw new NullReferenceException("sceneProvider is null"); } return(sceneProvider.ProvideScene(this, location, loadMode, activateOnLoad, priority)); }
/// <summary> /// Instantiate a single object. Note that the dependency loading is done asynchronously, but generally the actual instantiate is synchronous. /// </summary> /// <param name="location">The location of the Object to instantiate.</param> /// <param name="position">The position of the instantiated object.</param> /// <param name="rotation">The rotation of the instantiated object.</param> /// <param name="parent">Parent transform for instantiated object.</param> /// <param name="trackHandle">If true, Addressables will track this request to allow it to be released via the result object.</param> /// <returns>The operation handle for the request.</returns> public static AsyncOperationHandle <GameObject> InstantiateAsync(IResourceLocation location, Vector3 position, Quaternion rotation, Transform parent = null, bool trackHandle = true) { return(m_Addressables.InstantiateAsync(location, position, rotation, parent, trackHandle)); }
static AsyncOperationHandle <IResourceLocator> OnCatalogDataLoaded(AddressablesImpl addressables, AsyncOperationHandle <ContentCatalogData> op, string providerSuffix, IResourceLocation remoteHashLocation) { var data = op.Result; addressables.Release(op); if (data == null) { return(addressables.ResourceManager.CreateCompletedOperation <IResourceLocator>(null, new Exception("Failed to load content catalog.").Message)); } else { if (data.ResourceProviderData != null) { foreach (var providerData in data.ResourceProviderData) { LoadProvider(addressables, providerData, providerSuffix); } } if (addressables.InstanceProvider == null) { var prov = data.InstanceProviderData.CreateInstance <IInstanceProvider>(); if (prov != null) { addressables.InstanceProvider = prov; } } if (addressables.SceneProvider == null) { var prov = data.SceneProviderData.CreateInstance <ISceneProvider>(); if (prov != null) { addressables.SceneProvider = prov; } } if (remoteHashLocation != null) { data.location.Dependencies[(int)ContentCatalogProvider.DependencyHashIndex.Remote] = remoteHashLocation; } ResourceLocationMap locMap = data.CreateCustomLocator(data.location.PrimaryKey, providerSuffix); addressables.AddResourceLocator(locMap, data.localHash, data.location); addressables.AddResourceLocator(new DynamicResourceLocator(addressables)); return(addressables.ResourceManager.CreateCompletedOperation <IResourceLocator>(locMap, string.Empty)); } }
/// <inheritdoc/> public virtual bool CanProvide(Type t, IResourceLocation location) { return(GetDefaultType(location).IsAssignableFrom(t)); }
public static AsyncOperationHandle <IResourceLocator> LoadContentCatalog(AddressablesImpl addressables, IResourceLocation loc, string providerSuffix, IResourceLocation remoteHashLocation = null) { Type provType = typeof(ProviderOperation <ContentCatalogData>); var catalogOp = addressables.ResourceManager.CreateOperation <ProviderOperation <ContentCatalogData> >(provType, provType.GetHashCode(), null, null); IResourceProvider catalogProvider = null; foreach (IResourceProvider provider in addressables.ResourceManager.ResourceProviders) { if (provider is ContentCatalogProvider) { catalogProvider = provider; break; } } var dependencies = addressables.ResourceManager.CreateGroupOperation <string>(loc.Dependencies, true); catalogOp.Init(addressables.ResourceManager, catalogProvider, loc, dependencies, true); var catalogHandle = addressables.ResourceManager.StartOperation(catalogOp, dependencies); dependencies.Release(); var chainOp = addressables.ResourceManager.CreateChainOperation(catalogHandle, res => OnCatalogDataLoaded(addressables, res, providerSuffix, remoteHashLocation)); return(chainOp); }
/// <summary> /// Get the default type of object that this provider can provide. /// </summary> /// <param name="location"></param> /// <returns></returns> public virtual Type GetDefaultType(IResourceLocation location) { return(typeof(object)); }
public AsyncOperationHandle <IResourceLocator> LoadContentCatalog(IResourceLocation loc, string providerSuffix, IResourceLocation remoteHashLocation) { return(LoadContentCatalog(m_Addressables, loc, providerSuffix, remoteHashLocation)); }
/// <inheritdoc/> public override IAsyncOperation <TObject> Provide <TObject>(IResourceLocation location, IAsyncOperation <IList <object> > loadDependencyOperation) { var operation = AsyncOperationCache.Instance.Acquire <InternalOp <TObject> >(); return(operation.Start(location)); }
//Attempts to load each catalog in order, stopping at first success. internal AsyncOperationHandle <IResourceLocator> LoadContentCatalogInternal(IList <IResourceLocation> catalogs, int index, ResourceLocationMap locMap, IResourceLocation remoteHashLocation) { Addressables.LogFormat("Addressables - loading content catalog from {0}.", m_Addressables.ResourceManager.TransformInternalId(catalogs[index])); var loadOp = LoadContentCatalog(catalogs[index], m_ProviderSuffix, remoteHashLocation); if (loadOp.IsDone) { LoadOpComplete(loadOp, catalogs, locMap, index, remoteHashLocation); } else { loadOp.Completed += op => { LoadOpComplete(op, catalogs, locMap, index, remoteHashLocation); } }; return(loadOp); } void LoadOpComplete(AsyncOperationHandle <IResourceLocator> op, IList <IResourceLocation> catalogs, ResourceLocationMap locMap, int index, IResourceLocation remoteHashLocation) { if (op.Result != null) { m_Addressables.RemoveResourceLocator(locMap); Result = op.Result; Complete(Result, true, string.Empty); m_Addressables.Release(op); Addressables.Log("Addressables - initialization complete."); } else { Addressables.LogFormat("Addressables - failed to load content catalog from {0}.", op); if (index + 1 >= catalogs.Count) { Addressables.LogWarningFormat("Addressables - initialization failed.", op); m_Addressables.RemoveResourceLocator(locMap); Complete(Result, false, op.OperationException != null ? op.OperationException.Message : "LoadContentCatalogInternal"); m_Addressables.Release(op); } else { m_loadCatalogOp = LoadContentCatalogInternal(catalogs, index + 1, locMap, remoteHashLocation); m_Addressables.Release(op); } } } }
/// <summary> /// Creates a new instance of <see cref="ProviderException"/>. /// </summary> /// <param name="message">A message describing the error.</param> /// <param name="location">The resource location that the operation was trying to provide.</param> /// <param name="uwrResult">The result of the unity web request, if any.</param> /// <param name="innerException">The exception that caused the error, if any.</param> public RemoteProviderException(string message, IResourceLocation location = null, UnityWebRequestResult uwrResult = null, Exception innerException = null) : base(message, location, innerException) { WebRequestResult = uwrResult; }
public IEnumerable<IResourceLocation> GetLocations(IResourceLocation baseLocation, string name) { throw new NotImplementedException(); }
public LinkResourceBase(ResourceRenderPosition renderPosition, string mimeType, IResourceLocation location) : base(renderPosition) { this.Location = location; this.MimeType = mimeType; }
public override IResource GetResource(IResourceLocation location) { FileLocation l = location as FileLocation; if (l == null) return null; if (!l.FileName.EndsWith(".css", StringComparison.InvariantCultureIgnoreCase)) { ExternalLocation el = l as ExternalLocation; if (el == null || el.Mime == null || !el.Mime.EndsWith("/css", StringComparison.InvariantCultureIgnoreCase)) return null; } Stream s = l.GetStream(); if (s == null) return null; SyntaxReader reader; using (TextReader r = new StreamReader(s)) reader = new SyntaxReader(r, false, location, null); Compress compress = reader.Compress == null ? Compress.Release : (Compress)Enum.Parse(typeof(Compress), reader.Compress, true); bool cmpr = (compress == Compress.Always || (compress == Compress.Release && !Configuration.DebugMode)); var includes = new List<ICSSResource>(); var imageIncludes = new List<IImageResource>(); var builds = new List<ICSSResource>(); var references = new List<IResource>(); if (reader.References != null) foreach (var rl in reader.References) { var resource = Configuration.GetResource(rl); if (resource == null) throw new Exception(String.Format("Resource '{0}' is not a valid resource.", rl)); if (resource is ICSSResource && !((ICSSResource)resource).CanReferenceCSS) includes.Add((ICSSResource)resource); else if (!references.Contains(resource)) references.Add(resource); } if (reader.Includes != null) foreach (var rl in reader.Includes) { if (location.Equals(rl)) continue; var resource = Configuration.GetResource(rl); if (resource == null) throw new Exception(String.Format("Resource '{0}' is not a valid resource.", rl)); if (resource is ICSSResource && (!Configuration.DebugMode || !((ICSSResource)resource).CanReferenceCSS)) includes.Add((ICSSResource)resource); else if (resource is IImageResource) { if (!Configuration.DebugMode) imageIncludes.Add((IImageResource)resource); } else if (!references.Contains(resource)) references.Add(resource); } if (reader.Builds != null) foreach (var rl in reader.Builds) { var resource = Configuration.GetResource(rl); if (resource == null) throw new Exception(String.Format("Resource '{0}' is not a valid resource.", rl)); if (resource is ICSSResource) { if (!Configuration.DebugMode) builds.Add((ICSSResource)resource); else if (!((ICSSResource)resource).CanReferenceCSS) includes.Add((ICSSResource)resource); else if (!references.Contains(resource)) references.Add(resource); } else if (resource is IImageResource) { if (!Configuration.DebugMode) imageIncludes.Add((IImageResource)resource); } else if (!references.Contains(resource)) references.Add(resource); } if ((reader.Compress == null || compress == Compress.Never) && imageIncludes.Count == 0 && includes.Count == 0 && builds.Count == 0 && l is VirtualPathLocation) return new PlainCSSResource(references.Count > 0 ? references.ToArray() : null, l, reader.HasContent); else return new ExtendedCSSResource( reader.Compress == null ? (bool?)null : cmpr, !Configuration.DebugMode, references.Count > 0 ? references.ToArray() : null, imageIncludes.Count > 0 ? imageIncludes.ToArray() : null, includes.Count > 0 ? includes.ToArray() : null, builds.Count > 0 ? builds.ToArray() : null, l, reader.HasContent); }
public abstract IResource GetResource(IResourceLocation location);
public bool HasLocation(IResourceLocation location) { throw new NotImplementedException(); }
public Package GetPackageByLocation(IResourceLocation location) { throw new NotImplementedException(); }
/// <summary> /// Load scene. /// </summary> /// <param name="location">The location of the scene to load.</param> /// <param name="loadMode">Scene load mode.</param> /// <param name="activateOnLoad">If false, the scene will load but not activate (for background loading). The SceneInstance returned has an Activate() method that can be called to do this at a later point.</param> /// <param name="priority">Async operation priority for scene loading.</param> /// <returns>The operation handle for the request.</returns> public static AsyncOperationHandle <SceneInstance> LoadSceneAsync(IResourceLocation location, LoadSceneMode loadMode = LoadSceneMode.Single, bool activateOnLoad = true, int priority = 100) { return(m_Addressables.LoadSceneAsync(location, loadMode, activateOnLoad, priority)); }
public IEnumerable<IResourceLocation> GetLocations(IResourceLocation baseLocation, string packageName, string componentname) { throw new NotImplementedException(); }
public LoadAssetOp(IResourceLocation location, VirtualAssetBundleEntry assetInfo) { Context = location; m_AssetInfo = assetInfo; m_LastUpdateTime = Time.realtimeSinceStartup; }
public UnknownResource(IResourceLocation location) { this.Location = location; }
/// <summary> /// Load a single asset /// </summary> /// <param name="location">The location of the asset.</param> public static AsyncOperationHandle <TObject> LoadAssetAsync <TObject>(IResourceLocation location) { return(m_Addressables.LoadAssetAsync <TObject>(location)); }
public override Type GetDefaultType(IResourceLocation location) { return(typeof(IAssetBundleResource)); }
/// <summary> /// Instantiate a single object. Note that the dependency loading is done asynchronously, but generally the actual instantiate is synchronous. /// </summary> /// <param name="location">The location of the Object to instantiate.</param> /// <param name="parent">Parent transform for instantiated object.</param> /// <param name="instantiateInWorldSpace">Option to retain world space when instantiated with a parent.</param> /// <param name="trackHandle">If true, Addressables will track this request to allow it to be released via the result object.</param> /// <returns>The operation handle for the request.</returns> public static AsyncOperationHandle <GameObject> InstantiateAsync(IResourceLocation location, Transform parent = null, bool instantiateInWorldSpace = false, bool trackHandle = true) { return(m_Addressables.InstantiateAsync(location, new InstantiationParameters(parent, instantiateInWorldSpace), trackHandle)); }
public ResourcePackage(IResourceConfiguration configuration, IResourceLocation packageLocation, params IResourceLocation[] locations) : this(configuration, packageLocation, (IEnumerable<IResourceLocation>)locations) { }
public ScriptResource(IResourceLocation location) : base(ResourceRenderPosition.Body, "text/javascript", location) { }
public override IResource GetResource(IResourceLocation location) { FileLocation l = location as FileLocation; if (l == null) return null; if (!l.FileName.EndsWith(".js", StringComparison.InvariantCultureIgnoreCase)) { ExternalLocation el = l as ExternalLocation; if (el == null || el.Mime == null || (!el.Mime.EndsWith("/javascript", StringComparison.InvariantCultureIgnoreCase) && !el.Mime.EndsWith("/x-javascript", StringComparison.InvariantCultureIgnoreCase))) return null; } Stream s = l.GetStream(); if (s == null) return null; SyntaxReader reader; using (TextReader r = new StreamReader(s)) reader = new SyntaxReader(r, true, location, ".js"); Compress compress = reader.Compress == null ? Compress.Release : (Compress)Enum.Parse(typeof(Compress), reader.Compress, true); bool cmpr = (compress == Compress.Always || (compress == Compress.Release && !Configuration.DebugMode)); var includes = new List<IResource>(); var builds = new List<IResource>(); var references = new List<IResource>(); if (reader.References != null) foreach (var rl in reader.References) { var resource = Configuration.GetResource(rl); if (resource == null) throw new Exception(String.Format("Resource '{0}' is not a valid resource.", rl)); if (resource is IJavaScriptResource && !((IJavaScriptResource)resource).CanReferenceJavaScript) includes.Add(resource); else if (!references.Contains(resource)) references.Add(resource); } if (reader.Includes != null) foreach (var rl in reader.Includes) { var resource = Configuration.GetResource(rl); if (resource == null) throw new Exception(String.Format("Resource '{0}' is not a valid resource.", rl)); if (resource is IJavaScriptResource && (!Configuration.DebugMode || !((IJavaScriptResource)resource).CanReferenceJavaScript)) includes.Add(resource); else if (!references.Contains(resource)) references.Add(resource); } if (reader.Builds != null) foreach (var rl in reader.Builds) { var resource = Configuration.GetResource(rl); if (resource == null) throw new Exception(String.Format("Resource '{0}' is not a valid resource.", rl)); if (resource is IJavaScriptResource) { if (!Configuration.DebugMode) builds.Add(resource); else if (!((IJavaScriptResource)resource).CanReferenceJavaScript) includes.Add(resource); else if (!references.Contains(resource)) references.Add(resource); } else if (!references.Contains(resource)) references.Add(resource); } IResourceLocation rf = FileResourceHelper.GetRelatedResourceLocation(location); if (rf != null) { IResource rs = Configuration.GetResource(rf); if (rs != null) { if (rs is IJavaScriptResource && !Configuration.DebugMode) includes.Add(rs); else references.Add(rs); } } if ((reader.Compress == null || compress == Compress.Never) && includes.Count == 0 && builds.Count == 0 && !(l is EmbeddedLocation)) return new PlainJavaScriptResource(references.Count > 0 ? references.ToArray() : null, l, reader.HasContent); else return new ExtendedJavaScriptResource( reader.Compress == null ? (bool?)null : cmpr, !Configuration.DebugMode, references.Count > 0 ? references.ToArray() : null, includes.Count > 0 ? includes.ToArray() : null, builds.Count > 0 ? builds.ToArray() : null, l, reader.HasContent); }
public static AsyncOperationHandle <IResourceLocator> LoadContentCatalog(AddressablesImpl addressables, IResourceLocation loc, string providerSuffix) { var loadOp = addressables.LoadAssetAsync <ContentCatalogData>(loc); var chainOp = addressables.ResourceManager.CreateChainOperation(loadOp, res => OnCatalogDataLoaded(addressables, res, providerSuffix)); addressables.Release(loadOp); return(chainOp); }