Ejemplo n.º 1
0
        /// <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="location">location of the prefab.</param>
        /// <param name="instantiateParameters">A struct containing the parameters to pass the the Instantiation call.</param>
        /// <typeparam name="TObject">Instantiated object type.</typeparam>
        public static IAsyncOperation <TObject> ProvideInstance <TObject>(IResourceLocation location, InstantiationParameters instantiateParameters)
            where TObject : Object
        {
            if (InstanceProvider == null)
            {
                throw new NullReferenceException("ResourceManager.InstanceProvider is null.  Assign a valid IInstanceProvider object before using.");
            }

            if (location == null)
            {
                return(new CompletedOperation <TObject>().Start(null, null, default(TObject), new ArgumentNullException("location")));
            }
            var provider = GetResourceProvider <TObject>(location);

            if (provider == null)
            {
                return(new CompletedOperation <TObject>().Start(location, location, default(TObject), new UnknownResourceProviderException(location)));
            }

            ResourceManagerEventCollector.PostEvent(ResourceManagerEventCollector.EventType.InstantiateAsyncRequest, location, Time.frameCount);
            ResourceManagerEventCollector.PostEvent(ResourceManagerEventCollector.EventType.LoadAsyncRequest, location, Time.frameCount);

            return(InstanceProvider.ProvideInstanceAsync <TObject>(provider, location, LoadDependencies(location), instantiateParameters).Retain());
        }