Ejemplo n.º 1
0
        /// <summary>
        /// 加载
        /// </summary>
        static private ResRef LoadResByUrl <T>(string url, string resName, ResLoadCompleteDelegate onComplete, IResDesc resDesc, bool holdbundle = false) where T : ResBase, new()
        {
            // 查找
            var res = FindRes(url);

            if (null == res)
            {
                res = new T();
                res.Init(url, resName, holdbundle);
            }
            else
            {
                // 从空闲列表移除
                if (res.refCount <= 0)
                {
                    _unusedResources.Remove(res);
                }

                if (res.isLoaded)
                {
                    var Ref = ResRef.Create(res, onComplete, resDesc);
                    Ref.OnComplete();
                    return(Ref);
                }
            }

            var r = ResRef.Create(res, onComplete, resDesc);

            // 加入列表
            _loader.Push(r);
            return(r);
        }
Ejemplo n.º 2
0
 /// <summary>
 /// 设置加载完成回调
 /// </summary>
 void PushLoadCompleteDelegate()
 {
     ResManager.Release(ref _resOnLoadSceneComplete);
     if (string.IsNullOrEmpty(SceneController.sceneName))
     {
         _resOnLoadSceneComplete = ResManager.PushDelegate(OnLoadSceneAllAssetsComplete);
     }
 }
Ejemplo n.º 3
0
        /// <summary>
        /// 创建
        /// </summary>
        public static ResRef Create(ResBase res, ResLoadCompleteDelegate onComplete, IResDesc resDesc)
        {
            ResRef r = new ResRef(res, onComplete, resDesc);

            if (null != r._res)
            {
                r._res.IncRef();
            }
            return(r);
        }
Ejemplo n.º 4
0
 /// <summary>
 /// 移除
 /// </summary>
 public bool Remove(ResRef r)
 {
     for (int i = 0; i < _loadPipelines.Length; ++i)
     {
         if (_loadPipelines[i].Stop(r))
         {
             return(true);
         }
     }
     return(_loadingResources.Remove(r));
 }
Ejemplo n.º 5
0
        /// <summary>
        /// 开始
        /// </summary>
        public bool Start(ResRef r)
        {
            if (!_resRef.IsNull)
            {
                return(false);
            }

            _resRef = r;
            _loader.StartCoroutine(Load());
            return(true);
        }
Ejemplo n.º 6
0
 /// <summary>
 /// 加载场景,原来的意义还保留, 以后只初始化场景树资源相关 fixed by ljp 2020-06-23
 /// </summary>
 /// <param name="sceneName"></param>
 static public void LoadQuadtree(string sceneName)
 {
     _camera = Camera.main;
     if (!string.IsNullOrEmpty(sceneName))
     {
         _resScene = ResManager.LoadScene(sceneName, OnLoadSceneComplete);
     }
     else
     {
         OnLoadSceneComplete(null);
     }
     _sceneName = sceneName;
 }
Ejemplo n.º 7
0
        /// <summary>
        /// 停止
        /// </summary>
        public bool Stop(ResRef r)
        {
            if (_resRef.IsNull)
            {
                return(false);
            }
            if (r != _resRef)
            {
                return(false);
            }

            _resRef.RemoveCallback();
            return(true);
        }
Ejemplo n.º 8
0
        /// <summary>
        /// 添加
        /// </summary>
        /// <param name="r"></param>
        public void Push(ResRef r)
        {
            if (_startLoadTime < MathUtil.fEpsilon)
            {
                _startLoadTime = Time.realtimeSinceStartup;
            }

            ResBase res;

            if (!_LoadingPoolResource.TryGetValue(r.url, out res))
            {
                _LoadingPoolResource.Add(r.url, r.res);
            }
            _loadingResources.AddLast(r);
        }
Ejemplo n.º 9
0
        /// <summary>
        /// 添加回调(空资源引用)
        /// </summary>
        /// <param name="onComplete"></param>
        /// <returns></returns>
        static public ResRef PushDelegate(ResLoadCompleteDelegate onComplete)
        {
            var r = ResRef.Create(null, onComplete, null);

            if (r.res == null)
            {
                r.OnComplete();
            }
            else
            {
                _loader.Push(r);
            }
            // 重置进度
            _loader.ResetProgress();

            return(r);
        }
Ejemplo n.º 10
0
        /// <summary>
        /// 释放
        /// </summary>
        public static int Release(ref ResRef r)
        {
            int refCount = 0;

            if (null != r._res)
            {
                refCount = r._res.Release();
            }

            if (r != null && null != r._resDesc && refCount == 0)
            {
                r._resDesc.RemoveRes();
            }


            return(refCount);
        }
Ejemplo n.º 11
0
 /// <summary>
 /// 加载完成
 /// </summary>
 private void OnLoadOneComplete()
 {
     try
     {
         _resRef.res.SetLoadingState(ELoadingState.Loaded);
         _resRef.OnComplete();
     }
     catch (Exception e)
     {
         Debug.LogErrorFormat("OnLoadOneComplete {0} Exception!", _resRef.url);
         Debug.LogException(e);
     }
     finally
     {
         _resRef = ResRef.Null;
         _www.Dispose();
         _www = null;
     }
 }
Ejemplo n.º 12
0
        /// <summary>
        /// 释放
        /// </summary>
        static public void      Release(ref ResRef r, bool bReleaseAb = false)
        {
            // 空引用
            if (r.IsNull)
            {
                return;
            }
            var res = r.res;

            // 从加载器中移除
            bool isLoading = false; //_loader.Remove(r);

            // 场景直接销毁
            if (res is ResScene)
            {
                _dictResources.Remove(r.url);
                res.Destroy();
                r = ResRef.Null;
                return;
            }

            // 释放
            ResRef.Release(ref r);

            // 加入空闲列表
            if (!isLoading && null != res && res.refCount <= 0)
            {
                if (bReleaseAb)
                {
                    _dictResources.Remove(r.url);
                    res.Destroy();
                    r = ResRef.Null;
                }
                else
                {
                    _unusedResources.Add(res);
                }
            }
            r = ResRef.Null;
        }
Ejemplo n.º 13
0
        /// <summary>
        /// 取下一个资源
        /// </summary>
        private bool PeekNextRes(out ResRef r)
        {
            r = ResRef.Null;
            var count = _loadingResources.Count;

            if (count < 1)
            {
                if (_startLoadTime > MathUtil.fEpsilon)
                {
                    _startLoadTime = 0;
                }
                return(false);
            }

            LinkedListNode <ResRef> temp = null;
            LinkedListNode <ResRef> node = _loadingResources.First;

            while (node != null)
            {
                r = node.Value;
                if (null == r.res)
                {
                    if (!IsAllPipelineIdle())
                    {
                        _isBlocking = true;
                        return(false);
                    }

                    r.OnComplete();

                    temp = node;
                    node = node.Next;
                    _loadingResources.Remove(temp);
                    temp = null;
                    continue;
                }

                if (r.res.isPeeking)
                {
                    node = node.Next;
                    continue;
                }

                if (r.res.isLoading)
                {
                    node = node.Next;
                    continue;
                }

                temp = node;
                node = node.Next;
                _loadingResources.Remove(temp);
                temp = null;
                ++_loadingIndex;
                if (r.res.isLoaded)
                {
                    r.OnComplete();
                    continue;
                }

                r.res.SetLoadingState(ELoadingState.Peek);
                return(true);
            }
            return(false);
        }