using System; using System.Collections.Generic; using UnityEngine.ResourceManagement.AsyncOperations; using UnityEngine.ResourceManagement.ResourceLocations; using UnityEngine.ResourceManagement.Util; using UnityEngine.SceneManagement; namespace UnityEngine.ResourceManagement.ResourceProviders { /// /// Options for resource provider behavior. /// public enum ProviderBehaviourFlags { /// /// Indicates that the provider does not have extra specified behavior. /// None = 0, /// /// Indicates that the provider will still fulfill requests even with failed dependencies. /// CanProvideWithFailedDependencies = 1 } /// /// Container for all data need by providers to fulfill requests. /// public struct ProvideHandle { int m_Version; IGenericProviderOperation m_InternalOp; ResourceManager m_ResourceManager; internal ProvideHandle(ResourceManager rm, IGenericProviderOperation op) { m_ResourceManager = rm; m_InternalOp = op; m_Version = op.ProvideHandleVersion; } IGenericProviderOperation InternalOp { get { if (m_InternalOp.ProvideHandleVersion != m_Version) { throw new Exception(ProviderOperation.kInvalidHandleMsg); } return m_InternalOp; } } /// /// The ResourceManager used to create the operation. /// public ResourceManager ResourceManager { get { return m_ResourceManager; } } /// /// The requested object type. /// public Type Type { get { return InternalOp.RequestedType; } } /// /// The location for the request. /// public IResourceLocation Location { get { return InternalOp.Location; } } /// /// Number of dependencies. /// public int DependencyCount { get { return InternalOp.DependencyCount; } } /// /// Get a specific dependency object. /// /// The dependency type. /// The index of the dependency. /// The dependency object. public TDepObject GetDependency(int index) { return InternalOp.GetDependency(index); } /// /// Get the depedency objects. /// /// The list of dependecies to fill in. public void GetDependencies(IList list) { InternalOp.GetDependencies(list); } /// /// Set the func for handling progress requests. /// /// The callback function. public void SetProgressCallback(Func callback) { InternalOp.SetProgressCallback(callback); } /// /// Set the func for handling download progress requests. /// /// The callback function. public void SetDownloadProgressCallbacks(Func callback) { InternalOp.SetDownloadProgressCallback(callback); } /// /// Set the func for handling a request to wait for the completion of the operation /// /// The callback function. public void SetWaitForCompletionCallback(Func callback) { InternalOp.SetWaitForCompletionCallback(callback); } /// /// Called to complete the operation. /// /// The type of object requested. /// The result object. /// True if the operation was successful, false otherwise. /// The exception if the operation failed. public void Complete(T result, bool status, Exception exception) { InternalOp.ProviderCompleted(result, status, exception); } } /// /// Resoure Providers handle loading (Provide) and unloading (Release) of objects /// public interface IResourceProvider { /// /// Unique identifier for this provider, used by Resource Locations to find a suitable Provider /// /// The provider identifier. string ProviderId { get; } /// /// The default type of object that this provider can provide. /// /// The location that can be used to determine the type. /// The type of object that can be provided. Type GetDefaultType(IResourceLocation location); /// /// Determine if this provider can provide the specified object type from the specified location. /// /// The type of object. /// The resource location of the object. /// True if this provider can create the specified object. bool CanProvide(Type type, IResourceLocation location); /// /// Tells the provide that it needs to provide a resource and report the results through the passed provideHandle. When this is called, all dependencies have completed and are available through the provideHandle. /// /// A handle used to update the operation. void Provide(ProvideHandle provideHandle); /// /// Release and/or unload the given resource location and asset /// /// Location to release. /// Asset to unload. void Release(IResourceLocation location, object asset); /// /// Custom flags for the provider. /// ProviderBehaviourFlags BehaviourFlags { get; } } }