Beispiel #1
0
 public bool UnloadAsset(I_ObjectInfo objectInfo)
 {
     //Object obj = objectInfo.GetAsset<Object>();
     //if (obj == null) return false;
     //Resources.UnloadAsset(obj);
     return(true);
 }
Beispiel #2
0
        private void InternalLoadAsset <T>(string resPath) where T : Object
        {
            I_ObjectInfo objectInfo = _loader.LoadAsset <T>(resPath);

            ResLog.Assert(objectInfo != null, "ResLoader结论:内部加载失败,找不到对应的资源,路径:[{0}]", resPath);
            PushAssetToCache(objectInfo);
        }
Beispiel #3
0
        public bool UnloadAsset(I_ObjectInfo objectInfo)
        {
            if (objectInfo == null)
            {
                return(false);
            }
            string mainPackagePath = objectInfo.Path;

            // 3.卸载主包
            bool result = InternalUnLoad(mainPackagePath, true);

            if (!result)
            {
                return(false);
            }

            // 4.卸载依赖包
            AssetBundleDepCnf depCnf = _mainInfo.GetDepsInfo(mainPackagePath);

            if (depCnf != null)
            {
                foreach (var depInfo in depCnf._childRef)
                {
                    InternalUnLoad(depInfo.Key, false);
                }
            }
            return(true);
        }
Beispiel #4
0
 public bool UnloadAsset(I_ObjectInfo objectInfo)
 {
     /*if (objectInfo == null) return false;
      * Object obj = objectInfo.GetAsset<Object>();
      * if (obj == null) return false;
      * Resources.UnloadAsset(obj);
      * return true;*/
     return(true);
 }
Beispiel #5
0
 //放到缓存中
 private void PushAssetToCache(I_ObjectInfo objectInfo)
 {
     ResLog.Assert(objectInfo != null, "ResLoader PushAssetToCache 推送到缓存中的AssetInfo 是空的");
     if (objectInfo == null || _cacheRes.ContainsKey(objectInfo.Path))
     {
         return;
     }
     _cacheRes.Add(objectInfo.Path, objectInfo);
 }
Beispiel #6
0
        private IEnumerator InternalLoadAssetAsync <T>(string resPath, Action <T> callback) where T : Object
        {
            // 1.得到路径 检测是否处于加载中
            if (_onLoadingRes.Contains(resPath))
            {
                // 3.等待加载 或者之类来一个ResWaitOpetion来确认
                // TODO Factory
                ResWaitLoadOpertion resWaitLoad = new ResWaitLoadOpertion(resPath, TIME_OUT);
                _otherOperation.Add(resWaitLoad);
                yield return(resWaitLoad);

                if (!ContainsRes(resPath))
                {
                    ResLog.Error("ResLoader InternalLoadAssetAsync 超时请求:[{0}]", resPath);
                    yield break;
                }
            }
            else
            {
                if (!CanAsynLoad())
                {
                    yield return(_maxOperationLoad);
                }

                _currAsyncCount++;
                // 4.请求异步加载
                ResLoadOpertion loadOpertion = _loader.LoadAssetAsync <T>(resPath);
                ResLog.Assert(loadOpertion != null, "ResLoader InternalLoadAssetAsync 异步请求为空.加载路径:[{0}]", resPath);
                if (loadOpertion == null)
                {
                    yield break;
                }
                // TODO 请求的地址是和加载的路径是不一样的东西
                _onLoadingRes.Add(resPath);
                _loadOpertions.Add(loadOpertion);
                // 等待加载完成
                if (!loadOpertion.IsDone())
                {
                    yield return(loadOpertion);
                }
                I_ObjectInfo objectInfo = loadOpertion.GetAsset <T>(resPath);
                // 6.卸载请求信息
                loadOpertion.UnloadRequest();
                // 7.t推送到内存中
                PushAssetToCache(objectInfo);
                _currAsyncCount--;
            }
            bool result = CallbackByCache(resPath, callback);

            if (!result)
            {
                ResLog.Error("加载完成...但出现资源错误,path:[{0}]", resPath);
            }
            yield return(null);
        }
Beispiel #7
0
        // 卸载引用
        public bool UnLoadRef(Object obj)
        {
            I_ObjectInfo objectInfo = GetAssetInfo(obj);

            if (objectInfo == null)
            {
                return(false);
            }

            objectInfo.UnRef(obj);
            return(true);
        }
Beispiel #8
0
        public bool UnLoadRef(string resPath)
        {
            I_ObjectInfo objectInfo = GetAssetInfo(resPath);

            if (objectInfo == null)
            {
                return(false);
            }

            objectInfo.UnRefByPath(resPath);
            return(true);
        }
Beispiel #9
0
        private I_ObjectInfo GetAssetInfo(string resPath)
        {
            string key = _loader.GetResPath(resPath);

            ResLog.Assert(_cacheRes.ContainsKey(key), "ResLoader UnLoadRes Fail.通过[{0}]找不到对应的I_ObjectInfo", key);
            if (!_cacheRes.ContainsKey(key))
            {
                return(null);
            }

            I_ObjectInfo objectInfo = _cacheRes[key];

            return(objectInfo);
        }
Beispiel #10
0
        private I_ObjectInfo GetAssetInfo(Object obj)
        {
            if (obj == null)
            {
                return(null);
            }
            var enumerator = _cacheRes.GetEnumerator();

            while (enumerator.MoveNext())
            {
                I_ObjectInfo tmpObjectInfo = enumerator.Current.Value;
                if (tmpObjectInfo.CheckObject(obj))
                {
                    return(tmpObjectInfo);
                }
            }

            ResLog.Assert(false, "ResLoader UnLoadRes 失败,通过Object:[{0}]找不到对应的AssetInfo", obj.name);
            return(null);
        }
Beispiel #11
0
        // 卸载资源
        public bool UnLoadRes(Object obj)
        {
            I_ObjectInfo objectInfo = GetAssetInfo(obj);

            if (objectInfo == null)
            {
                return(false);
            }

            objectInfo.UnRef(obj);
            string path   = objectInfo.Path;
            bool   result = _loader.UnloadAsset(objectInfo);

            if (result)
            {
                _cacheRes.Remove(path);
            }
            ResLog.Assert(result, "卸载失败:[{0}]", path);
            return(result);
        }
Beispiel #12
0
 public bool UnLoadAssetRef(I_ObjectInfo objectInfo)
 {
     return(false);
 }
Beispiel #13
0
 public bool UnloadAsset(I_ObjectInfo objectInfo)
 {
     return(false);
 }