示例#1
0
 public void Init(ResourceManager rm, IInstanceProvider instanceProvider, InstantiationParameters instantiationParams, AsyncOperationHandle <GameObject> dependency)
 {
     m_RM                  = rm;
     m_dependency          = dependency;
     m_instanceProvider    = instanceProvider;
     m_instantiationParams = instantiationParams;
 }
 public InternalOp <TObject> Start(IAsyncOperation <TObject> loadOperation, IResourceLocation location, InstantiationParameters instantiateParameters)
 {
     Validate();
     m_PrefabResult           = null;
     m_Result                 = null;
     Context                  = location;
     m_InstParams             = instantiateParameters;
     m_StartFrame             = Time.frameCount;
     loadOperation.Completed += m_CompleteAction;
     return(this);
 }
示例#3
0
            public InternalOp <TObject> Start(IAsyncOperation <TObject> loadOperation, IResourceLocation location, TObject value, InstantiationParameters instantiateParameters)
            {
                Validate();
                m_PrefabResult = null;
                m_InstParams   = instantiateParameters;
                SetResult(value);
                Context      = location;
                m_StartFrame = Time.frameCount;
                if (loadOperation != null)
                {
                    loadOperation.Completed += m_OnLoadOperationCompleteAction;
                }
                else
                {
                    DelayedActionManager.AddAction(m_OnValidResultCompleteAction, 0, Result);
                }

                return(this);
            }
        /// <summary>
        /// Asynchronously 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));
        }
示例#5
0
        /// <inheritdoc/>
        public IAsyncOperation <TObject> ProvideInstanceAsync <TObject>(IResourceProvider loadProvider, IResourceLocation location, IAsyncOperation <IList <object> > loadDependencyOperation, InstantiationParameters instantiateParameters) where TObject : Object
        {
            if (location == null)
            {
                throw new ArgumentNullException("location");
            }
            if (loadProvider == null)
            {
                throw new ArgumentNullException("loadProvider");
            }
            InstancePool pool;

            if (!m_Pools.TryGetValue(location, out pool))
            {
                m_Pools.Add(location, pool = new InstancePool(loadProvider, location));
            }

            pool.holdCount++;
            return(pool.ProvideInstanceAsync <TObject>(loadProvider, loadDependencyOperation, instantiateParameters));
        }
示例#6
0
            internal IAsyncOperation <TObject> ProvideInstanceAsync <TObject>(IResourceProvider loadProvider, IAsyncOperation <IList <object> > loadDependencyOperation, InstantiationParameters instantiateParameters) where TObject : Object
            {
                if (m_Instances.Count > 0)
                {
                    //this accounts for the dependency load which is not needed since the asset is cached.
                    for (int i = 0; m_Location.Dependencies != null && i < m_Location.Dependencies.Count; i++)
                    {
                        ReleaseInternal(ResourceManager.GetResourceProvider <object>(m_Location.Dependencies[i]), m_Location.Dependencies[i]);
                    }

                    return(AsyncOperationCache.Instance.Acquire <InternalOp <TObject> >().Start(null, m_Location, Get <TObject>(), instantiateParameters));
                }

                var depOp = loadProvider.Provide <TObject>(m_Location, loadDependencyOperation);

                return(AsyncOperationCache.Instance.Acquire <InternalOp <TObject> >().Start(depOp, m_Location, null, instantiateParameters));
            }
        /// <inheritdoc/>
        public IAsyncOperation <TObject> ProvideInstanceAsync <TObject>(IResourceProvider loadProvider, IResourceLocation location, IAsyncOperation <IList <object> > loadDependencyOperation, InstantiationParameters instantiateParameters)
            where TObject : Object
        {
            if (location == null)
            {
                throw new ArgumentNullException("location");
            }

            if (loadProvider == null)
            {
                throw new ArgumentNullException("loadProvider");
            }

            var depOp = loadProvider.Provide <TObject>(location, loadDependencyOperation);

            var operation = AsyncOperationCache.Instance.Acquire <InternalOp <TObject> >();

            return(operation.Start(depOp, location, instantiateParameters));
        }
示例#8
0
        /// <summary>
        /// Asynchronously instantiate multiple prefabs (GameObjects) at the specified <paramref name="locations"/>.
        /// </summary>
        /// <returns>Async operation that will complete when the prefab is instantiated.</returns>
        /// <param name="locations">locations of prefab asset</param>
        /// <param name="callback">This is called for each instantiated object.</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 <IList <TObject> > ProvideInstances <TObject>(IList <IResourceLocation> locations, Action <IAsyncOperation <TObject> > callback, InstantiationParameters instantiateParameters)
            where TObject : Object
        {
            if (InstanceProvider == null)
            {
                throw new NullReferenceException("ResourceManager.InstanceProvider is null.  Assign a valid IInstanceProvider object before using.");
            }

            if (locations == null)
            {
                return(new CompletedOperation <IList <TObject> >().Start(null, locations, null, new ArgumentNullException("locations")));
            }

            return(AsyncOperationCache.Instance.Acquire <GroupOperation <TObject> >().Start(locations, callback, ProvideInstance <TObject>, instantiateParameters).Retain());
        }
示例#9
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());
        }