Exemplo n.º 1
0
        public void LoadAssetsAsync <T>(T source,
                                        List <AssetInfo> assetInfos,
                                        Action <T, List <UnityObject> > handlerAction,
                                        AssetLoadOption assetLoadOption = default(AssetLoadOption))
        {
            if (assetInfos != null)
            {
                var batch = AssetLoadRequestBatch <T> .Alloc(source, assetInfos.Count(), !assetLoadOption.DontAutoActive);

                batch.OnLoaded = handlerAction;
                int count        = 0;
                var singleOption = new AssetLoadOption(true, assetLoadOption.Parent,
                                                       assetLoadOption.Recyclable, assetLoadOption.PostProcessorFactory, assetLoadOption.ObjectType);
                foreach (var assetInfo in assetInfos)
                {
                    var req = AppendAssetRequest(source, assetInfo, null, singleOption);
                    batch.PackRequest(req);
                    count++;
                }

                if (count == 0)
                {
                    AssetLoadRequestBatch <T> .Free(batch);
                }
            }
        }
Exemplo n.º 2
0
        public void LoadAssetsAsync <T>(T source,
                                        IEnumerable <AssetInfo> assetInfos,
                                        Action <T, IEnumerable <UnityObject> > handlerAction,
                                        AssetLoadOption assetLoadOption = default(AssetLoadOption))
        {
            if (assetInfos != null)
            {
                var batch = AssetLoadRequestBatch <T> .Alloc();

                batch.OnLoaded = handlerAction;
                int count = 0;
                foreach (var assetInfo in assetInfos)
                {
                    var req = AppendAssetRequest(source, assetInfo, null, assetLoadOption);
                    batch.PackRequest(req);
                    count++;
                }

                if (count == 0)
                {
                    AssetLoadRequestBatch <T> .Free(batch);
                }
            }
        }
Exemplo n.º 3
0
        private AssetLoadRequest <T> AppendAssetRequest <T>(T source,
                                                            AssetInfo assetInfo,
                                                            Action <T, UnityObject> handlerAction,
                                                            AssetLoadOption option)
        {
            _logger.DebugFormat("*****  *****  ***** Loading Asset {0}", assetInfo);

            var req = AssetLoadRequest <T> .Alloc();

            req.Source = source;

            req.AssetInfo   = assetInfo;
            req.OnLoaded    = handlerAction;
            req.RequestType = ELoadRequestType.Asset;
            req.Option      = option;
            if (assetInfo.BundleName == null || assetInfo.AssetName == null)
            {
                try
                {
                    throw new ArgumentNullException(string.Format("Loading Asset {0} is Invalid", assetInfo));
                }
                catch (Exception e)
                {
                    _logger.ErrorFormat("Loading Asset {0} is Invalid from {1}", assetInfo, e);
                }


                req.IsDisposed = true;
                return(req);
            }

            var profiler = SingletonManager.Get <LoadRequestProfileHelp>().GetProfile(assetInfo);

            profiler.RequestTimes++;
            var unityObj = _objectPool.GetOrNull(assetInfo, req.AutoActive);

            if (unityObj != null)
            {
                profiler.PooledTimes++;

                if (req.Parent != null)
                {
                    var transform = req.Parent.transform;
                    var go        = unityObj.AsGameObject;
                    if (go != null && go.transform.parent != transform)
                    {
                        go.transform.SetParent(transform, false);
                    }
                }

                unityObj.OnLoadFromPool();
                req.LoadedObject = unityObj;
                _loadedRequests.Enqueue(req);
                _logger.InfoFormat("Load resource for object pool {0}", assetInfo);
            }
            else
            {
                _pendingRequests.AddLast(req);
            }

            return(req);
        }
Exemplo n.º 4
0
 public void LoadAssetAsync <T>(T source, AssetInfo assetInfo, Action <T, UnityObject> handlerAction,
                                AssetLoadOption assetLoadOption = default(AssetLoadOption))
 {
     AppendAssetRequest(source, assetInfo, handlerAction, assetLoadOption);
 }
Exemplo n.º 5
0
 public virtual void Dispose()
 {
     IsDisposed   = false;
     LoadedObject = null;
     Option       = AssetLoadOption.Default;
 }