Exemple #1
0
        /// <summary>
        /// 同步加载Bundle
        /// </summary>
        /// <param name="hash"></param>
        /// <param name="location"></param>
        /// <param name="suffix"></param>
        /// <returns></returns>
        public ABObject LoadSync(uint hash, string location, string suffix)
        {
            //从缓存中寻找
            ABObject abObject = _loadContext.FindABObjectCache(hash);

            if (abObject != null)
            {
                return(abObject);
            }

            var loader = ABLoader.GetLoader(hash, _loadContext);

            #region 异常情况处理
            if (loader == null)
            {
                ReDebug.LogError(ReLogType.System, "ABManager", string.Format("Cannot create ABLoader, location={0}{1}, name={2}", location, suffix, hash));
                return(null);
            }

            //如果已经加载完成
            if (loader.isComplete)
            {
                ReDebug.LogError(ReLogType.System, "ABManager", String.Format("Cannot be here, name={0}", hash));
                return(loader.abObject);
            }
            #endregion 异常情况处理

            loader.Load(true);

            return(loader.abObject);
        }
Exemple #2
0
 /// <summary>
 /// 添加依赖
 /// </summary>
 /// <param name="target"></param>
 internal void AddDependency(ABObject target)
 {
     if (target != null && _deps.Add(target))
     {
         target.Retain();
     }
 }
        /// <summary>
        /// 寻找缓存
        /// </summary>
        /// <param name="hash"></param>
        /// <returns></returns>
        public ABObject FindABObjectCache(uint hash)
        {
            ABObject res = null;

            loadedABDict.TryGetValue(hash, out res);
            return(res);
        }
Exemple #4
0
        private void LoadDepends(bool immediately, Action <bool> loadSelf)
        {
            if (depLoaderList == null)
            {
                depLoaderList = ListPool <ABLoader> .Get();

                depObjectList = ListPool <ABObject> .Get();

                for (int i = 0; i < abData.dependencies.Length; i++)
                {
                    uint     hash     = abData.dependencies[i];
                    ABObject abObject = _loadContext.FindABObjectCache(hash);
                    if (abObject != null)
                    {
                        abObject.ResetLifeTime();
                        depObjectList.Add(abObject);
                    }
                    else
                    {
                        ABLoader loader = GetLoader(hash, _loadContext);
                        depLoaderList.Add(loader);
                    }
                }
            }

            ABLoader depLoader;
            int      loadDepCount = loadingDepCount = depLoaderList.Count;

            if (loadDepCount == 0)
            {
                loadSelf(immediately);
            }
            else
            {
                for (int i = 0; i < loadDepCount; i++)
                {
                    depLoader = depLoaderList[i];
                    if (depLoader.isComplete)
                    {
                        continue;
                    }

                    depLoader.Load(immediately, (abObject) =>
                    {
                        loadingDepCount--;
                        if (loadingDepCount == 0 && state != ABLoadState.LoadingDep)
                        {
                            loadSelf(immediately);
                        }
                    });
                }
            }
        }
Exemple #5
0
        /// <summary>
        /// 异步加载Bundle
        /// </summary>
        /// <param name="hash"></param>
        /// <param name="location"></param>
        /// <param name="suffix"></param>
        /// <param name="callBack"></param>
        public void LoadAsync(uint hash, string location, string suffix, Action <ABObject> callBack = null)
        {
            //从缓存中寻找
            ABObject abObject = _loadContext.FindABObjectCache(hash);

            if (abObject != null)
            {
                if (callBack != null)
                {
                    callBack(abObject);
                }
                return;
            }

            var loader = ABLoader.GetLoader(hash, _loadContext);

            #region 异常情况处理
            if (loader == null)
            {
                ReDebug.LogError(ReLogType.System, "ABManager", string.Format("Cannot create ABLoader, location={0}{1}, name={2}", location, suffix, hash));

                if (callBack != null)
                {
                    callBack(null);
                }

                return;
            }

            //如果已经加载完成
            if (loader.isComplete)
            {
                ReDebug.LogError(ReLogType.System, "ABManager", String.Format("Cannot be here, name={0}", hash));
                if (callBack != null)
                {
                    callBack(loader.abObject);
                }

                return;
            }
            #endregion 异常情况处理

            loader.Load(false, callBack);
        }
Exemple #6
0
        /// <summary>
        /// 创建ABObject
        /// </summary>
        /// <returns></returns>
        private ABObject CreateABObject()
        {
            ABObject abObject = new ABObject(abName, abData, bundle);

            abObject.isReady = true;
            abObject.ResetLifeTime();

            for (int i = 0; i < depObjectList.Count; i++)
            {
                abObject.AddDependency(depObjectList[i]);
            }

            for (int i = 0; i < depLoaderList.Count; i++)
            {
                abObject.AddDependency(depLoaderList[i].abObject);
            }

            return(abObject);
        }
Exemple #7
0
        public override void Dispose()
        {
            UnloadBundle();
            var e = _deps.GetEnumerator();

            while (e.MoveNext())
            {
                ABObject dep = e.Current;
                dep.Release();
            }
            _deps.Clear();
            if (OnUnloaded != null)
            {
                OnUnloaded(this);
            }
            if (_mainObject && !canDestroy)
            {
                Resources.UnloadAsset(_mainObject);
            }
            _mainObject = null;
            _sprites    = null;
        }