예제 #1
0
        //仅供Bundle加载器调用加载所需依赖
        internal void LoadAllDependencies(string assetPath)
        {
            List <JsonNode> deps = FileManager.GetDependencies(assetPath);

            foreach (var dep in deps)
            {
                BundleSyncLoader loader = Load(dep.ToString(), true) as BundleSyncLoader;
                if (loader != null)
                {
                    loader.RefSet(1);
                }
            }
        }
예제 #2
0
        public AssetLoader Load(string assetPath, bool isSync, int priority = 0)
        {
            AssetLoader loader = null;

            deleteInLoad = false;
            bundlePath   = String.Empty;

            if (Config.BundleMode)
            {
                #region Bundle加载
                if (!FileManager.GetBundlePath(assetPath, ref bundlePath))//不存在该bundle
                {
                    return(null);
                }

                if (m_assetDic.TryGetValue(bundlePath, out loader))
                {
                    if (!isSync && !loader.isDone)
                    {
                        //当前已有未完成的异步加载且当前换成同步加载
                        if (m_waitList.Contains(loader))
                        {
                            m_waitList.Remove(loader);
                        }
                        m_assetDic.Remove(bundlePath);
                        m_deleteList.Add(loader);
                        deleteInLoad = true;
                    }
                }

                AssetLoader asset;
                if (loader == null || deleteInLoad)
                {
                    if (!isSync)
                    {
                        asset = new BundleLoader(bundlePath);
                    }
                    else
                    {
                        asset = new BundleSyncLoader(bundlePath, priority);
                    }
                    asset.SetManager(this);

                    if (deleteInLoad)
                    {
                        asset.CopyCompleteEvents(loader);
                    }

                    loader = asset;
                    m_assetDic.Add(bundlePath, loader);

                    if (isSync)
                    {
                        m_waitList.Add(loader);
                        m_waitList.Sort();
                        LoadNext();
                    }
                    else
                    {
                        asset.Load();
                    }
                }
                #endregion
            }
            else
            {
                #region Resources加载或Editor加载
                if (m_assetDic.TryGetValue(assetPath, out loader))
                {
                    if (!isSync && !loader.isDone)
                    {
                        //当前已有未完成的异步加载且当前换成同步加载
                        if (m_waitList.Contains(loader))
                        {
                            m_waitList.Remove(loader);
                        }
                        m_assetDic.Remove(assetPath);
                        m_deleteList.Add(loader);
                        deleteInLoad = true;
                    }
                }

                AssetLoader asset;
                if (loader == null || deleteInLoad)
                {
                    if (isSync)
                    {
                        asset = new AssetSyncLoader(assetPath, priority);
                    }
                    else
                    {
                        asset = new AssetLoader(assetPath);
                    }
                    asset.SetManager(this);

                    if (deleteInLoad)//转移完成回调
                    {
                        asset.CopyCompleteEvents(loader);
                    }

                    loader = asset;
                    m_assetDic.Add(assetPath, loader);

                    if (isSync)
                    {
                        m_waitList.Add(loader);
                        m_waitList.Sort();
                        LoadNext();
                    }
                    else
                    {
                        asset.Load();
                    }
                }
                #endregion
            }
            return(loader);
        }