Exemplo n.º 1
0
        void DownLoadScene(string name, string path, _DelegateAssetsResource onLoadOK, EResourceType type)
        {
            string[]       deps  = _manifest.GetAllDependencies(path);
            Queue <string> queue = new Queue <string>(deps.Length);

            for (int i = 0, imax = deps.Length; i < imax; ++i)
            {
                queue.Enqueue(deps[i]);
            }

            DownLoadResInfo info = new DownLoadResInfo();

            info.Assets = new AssetsResource();
            info.Assets.SetNameAndPath(name, path, type);
            info.MainAbPath       = path;
            info.DependenceAbPath = queue;
            info.onLoadComplete   = delegate(AssetsResource ar)
            {
                if (ar != null)
                {
                    ar.AddRef();
                    onLoadOK(ar);
                }
                else
                {
                    onLoadOK(null);
                }
            };

            DownLoadMgr.Instance.AddToDownLoadQueue(info);
        }
Exemplo n.º 2
0
        public Object GetOriginObjImmediately(string name, string path, EResourceType type)
        {
            //string path = ResourcePath.GetPath (type) + name + _bundleEx;
            AssetsResource ar;

            if (_originObjDic.TryGetValue(path, out ar))
            {
                ar.AddRef();
                return(ar.OriginObj);
            }
            else
            {
                string[]       deps  = _manifest.GetAllDependencies(path);
                Queue <string> queue = new Queue <string>(deps.Length);
                for (int i = 0, imax = deps.Length; i < imax; ++i)
                {
                    queue.Enqueue(deps[i]);
                }

                DownLoadResInfo info = new DownLoadResInfo();
                info.Assets = new AssetsResource();
                info.Assets.SetNameAndPath(name, path, type);
                info.MainAbPath       = path;
                info.DependenceAbPath = queue;
                ar = DownLoadMgr.Instance.DirectDownLoad(info);
                ar.LoadObject();
                ar.AddRef();
                AddAssetsResource(ar);
                return(ar.OriginObj);
            }
        }
        public AssetsResource DirectDownLoad(DownLoadResInfo info)
        {
            AssetsResource  ar   = info.Assets;
            AssetBundleInfo mabi = null;
            AssetBundleInfo abi  = null;
            AssetBundle     ab   = null;

            if ((mabi = GameAssetsMgr.Instance.CheckAssetBundle(info.MainAbPath)) != null)
            {
                ar.MainAbi = mabi;
            }
            else
            {
                ab         = AssetBundle.LoadFromFile(info.MainAbPath);
                abi        = new AssetBundleInfo(info.MainAbPath, ab);
                ar.MainAbi = abi;
                GameAssetsMgr.Instance.AddAssetBundle(abi);
            }

            while (info.DependenceAbPath.Count > 0)
            {
                string path = info.DependenceAbPath.Dequeue();
                if ((abi = GameAssetsMgr.Instance.CheckAssetBundle(path)) != null)
                {
                    ar.DependenceAbi.Add(abi);
                    continue;
                }
                ab  = AssetBundle.LoadFromFile(info.MainAbPath);
                abi = new AssetBundleInfo(info.MainAbPath, ab);
                ar.DependenceAbi.Add(abi);
                GameAssetsMgr.Instance.AddAssetBundle(abi);
            }
            return(ar);
        }
 public void AddToDownLoadQueue(DownLoadResInfo info)
 {
     if (_isMaxiSpeed)
     {
         FindMin().Enqueue(info);
     }
     else
     {
         _downLoadQueues[0].Enqueue(info);
     }
 }
        IEnumerator WWWDownLoad(int index)
        {
            bool hasError = false;

            while (true)
            {
                //				if(!_isMaxiSpeed && index > 0)
                //				{
                //					yield return null;
                //					continue;
                //				}
                if (_downLoadQueues[index].Count == 0)
                {
                    yield return(null);

                    continue;
                }

                hasError = false;
                DownLoadResInfo info = _downLoadQueues[index].Dequeue();
                AssetsResource  ar   = info.Assets;

                AssetBundleInfo mabi = null;
                if ((mabi = GameAssetsMgr.Instance.CheckAssetBundle(info.MainAbPath)) != null)
                {
                    ar.MainAbi = mabi;
                }
                else
                {
                    WWW www = new WWW(info.MainAbPath);
                    www.threadPriority = _isMaxiSpeed ? ThreadPriority.High : ThreadPriority.Low;
                    while (!www.isDone)
                    {
                        yield return(null);
                    }

                    if (!string.IsNullOrEmpty(www.error))
                    {
                        hasError = true;
                        LogManager.LogError(info.MainAbPath);
                    }
                    else
                    {
                        ar.MainAbi = new AssetBundleInfo(www.url, www.assetBundle);
                        GameAssetsMgr.Instance.AddAssetBundle(ar.MainAbi);
                    }
                    www.Dispose();
                }

                while (info.DependenceAbPath.Count > 0)
                {
                    string          path = info.DependenceAbPath.Dequeue();
                    AssetBundleInfo abi  = null;
                    if ((abi = GameAssetsMgr.Instance.CheckAssetBundle(path)) != null)
                    {
                        ar.DependenceAbi.Add(abi);
                        continue;
                    }
                    WWW www = new WWW(path);
                    www.threadPriority = _isMaxiSpeed ? ThreadPriority.High : ThreadPriority.Low;
                    while (!www.isDone)
                    {
                        yield return(null);
                    }

                    if (!string.IsNullOrEmpty(www.error))
                    {
                        LogManager.LogError(path);
                        www.Dispose();
                        hasError = true;
                        yield return(null);

                        continue;
                    }

                    abi = new AssetBundleInfo(www.url, www.assetBundle);
                    ar.DependenceAbi.Add(abi);
                    GameAssetsMgr.Instance.AddAssetBundle(abi);
                    www.Dispose();
                    yield return(null);
                }

                if (hasError)
                {
                    GameAssetsMgr.Instance.RemoveAssetsResource(ar);
                }
                if (info.onLoadComplete != null)
                {
                    info.onLoadComplete(hasError ? null : ar);
                }

                yield return(null);
            }
        }