예제 #1
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);
        }
예제 #2
0
        public I_ObjectInfo LoadAsset <T>(string resPath) where T : Object
        {
            ResToAssetBundleCnf mainPackageCnf = _mainInfo.GetResToAb(resPath);

            if (mainPackageCnf == null)
            {
                return(null);
            }

            string            mainPackagePath = mainPackageCnf.PackagePath;
            AssetBundleDepCnf depsCnf         = _mainInfo.GetDepsInfo(mainPackagePath);

            if (depsCnf == null)
            {
                return(null);
            }

            foreach (var depInfo in depsCnf._childRef)
            {
                InternalSyncloadPackage(depInfo.Key);
            }

            AssetBundleInfo packageInfo = InternalSyncloadPackage(depsCnf.AbName);

            ResLog.Assert(packageInfo != null, "AssetBundleLoader LoadAsset 加载主包失败:[{0}]", resPath);

            return(packageInfo);
        }
예제 #3
0
 public SpriteTagPoolCacheRef(string tag, string firstName)
 {
     ResLog.Assert(!(string.IsNullOrEmpty(tag) || string.IsNullOrEmpty(firstName)),
                   "初始化SpriteTagPoolCacheRef失败.Tag:[{0}],firstName[{1}]", tag, firstName);
     _spriteTag       = tag;
     _firstSpriteName = firstName;
 }
예제 #4
0
        public AssetBundlePackageCnf GetPackageCnf(string packagePath)
        {
            AssetBundlePackageCnf info;

            _packageMap.TryGetValue(packagePath, out info);
            ResLog.Assert((info != null), "找不到路径:[{0}]的包的PackageInfo", packagePath);
            return(info);
        }
예제 #5
0
        /// <summary>
        /// 通过资源路径找到对应的AssetBundle的路径
        /// </summary>
        public ResToAssetBundleCnf GetResToAb(string resPath)
        {
            ResToAssetBundleCnf info;

            _resMap.TryGetValue(resPath, out info);
            ResLog.Assert(info != null, "根据包路径:[{0}]查找相关依赖包失败", resPath);
            return(info);
        }
예제 #6
0
        public AssetBundleDepCnf GetDepsInfo(string packagePath)
        {
            AssetBundleDepCnf cnf;

            _depMap.TryGetValue(packagePath, out cnf);
            ResLog.Assert((cnf != null), "找不到路径:[{0}]的包的依赖信息(关于他儿子的)", packagePath);
            return(cnf);
        }
예제 #7
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);
 }
예제 #8
0
 void OnDisable()
 {
     ResLog.Assert(_initComplete, "初始化没有完成.GameObject Name:[{0}],Res Path:[{1}]", gameObject.name, _resPath);
     if (!_initComplete)
     {
         return;
     }
     SpriteAltasCachePool.Instance.UnLoadSprite(this);
 }
예제 #9
0
        public const string EVN = "Assets/";//"Assets/";


        #region I_ResourceLoad

        public I_ObjectInfo LoadAsset <T>(string resPath) where T : Object
        {
            T obj = AssetDatabase.LoadAssetAtPath <T>(EVN + resPath);

            ResLog.Assert(obj != null, "AssetDatabaseLoader 加载失败:[{0}]", resPath);
            I_ObjectInfo info = new ResInfo(obj, resPath);

            return(info);
        }
예제 #10
0
 protected override bool Update()
 {
     if (_request == null)
     {
         return(false);
     }
     ResLog.Log("等待加载:{0},加载状态{1}", RequestResPath, _request.isDone);
     return(_request.isDone);
 }
예제 #11
0
        public I_ObjectInfo LoadAsset <T>(string resPath) where T : Object
        {
            Object obj = Resources.Load(resPath);

            ResLog.Assert(obj != null, "ResoucesLoader 加载失败:[{0}]", resPath);
            I_ObjectInfo info = new ResInfo(obj, resPath);

            return(info);
        }
예제 #12
0
 void OnDisable()
 {
     ResLog.Assert(_initComplete, "初始化没有完成.GameObject Name:[{0}],Res Path:[{1}]", gameObject.name, _disabledSpritePath);
     if (!_initComplete)
     {
         return;
     }
     //SpritePool.Instance.ReaycelSprite(this);
 }
예제 #13
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);
        }
예제 #14
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);
        }
예제 #15
0
        public Dictionary <string, int> _childRef = new Dictionary <string, int>(); // 儿子有谁 依赖配置表已经确定了

        public void InitInfo(string[] infos)
        {
            AbName    = infos[0];
            _depCount = infos[1].ToInt();
            for (int i = 2; i < infos.Length; i++)
            {
                bool result = _childRef.ContainsKey(infos[i]);
                ResLog.Assert(!result, "初始化AssetBundlePackage的包信息失败,[{0}]", infos[i]);
                if (result)
                {
                    continue;
                }
                _childRef.Add(infos[i], 0);
            }
        }
예제 #16
0
        public T GetAsset <T>(string resName) where T : Object
        {
            if (_object == null)
            {
                ResLog.Error("AssetInfo Error,Object Is Null. Path:[{0}]", Path);
                return(null);
            }
            T t = _object as T;

            if (t == null)
            {
                ResLog.Error("AssetInfo Error,Object 类型不对.Path:[{0}],提取类型:[{1}],实际类型:[{2}]", Path, typeof(T), _object);
            }
            RefCount++;
            return(t);
        }
예제 #17
0
        // 内置同步加载指定路径的AssetBundle包
        private AssetBundleInfo InternalSyncloadPackage(string packagePath)
        {
            // 1.已经在缓存中,引用+1
            AssetBundleInfo packageInfo = GetPackageInfo(packagePath);

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

            // 2.如果已经在加载中,妈蛋老子只能等你了呗
            if (_onLoadingAbPackage.Contains(packagePath))
            {
                ResLog.Assert(!string.IsNullOrEmpty(packagePath), "主资源:[{0}],同步和异步同时加载,报错", packagePath);
                return(null);
            }
            // 3.如果在等待资源中直接剔除请求
            int index = _onWaitAbPackage.IndexOf(packagePath);

            if (index > 0)
            {
                _onWaitAbPackage.RemoveAt(index);
                _waitToLoadRequest.RemoveAt(index);
            }

            // 4.加载AssetBundle资源
            AssetBundlePackageCnf packageCnf = _mainInfo.GetPackageCnf(packagePath);

            if (packageCnf == null)
            {
                return(null);
            }

            AssetBundle assetbundle = AssetBundle.LoadFromFile(packageCnf.FullPath);

            ResLog.Assert(assetbundle != null, "同步加载AssetBundlePack失败,路径不存在:[{0}]", packageCnf.FullPath);
            if (assetbundle == null)
            {
                return(null);
            }

            // 5.初始化AssetBundle
            packageInfo = InitAssetBundleInfo(assetbundle, packageCnf);

            return(packageInfo);
        }
예제 #18
0
        public T LoadAsset <T>(string resPath) where T : Object
        {
            // 1.优先从缓存中提取资源信息
            T t = PopAssetForCache <T>(resPath);

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

            // 2.通过加载器加载
            InternalLoadAsset <T>(resPath);

            // 3.从缓存中得到资源
            t = PopAssetForCache <T>(resPath);
            ResLog.Assert(t != null, "ResLoader LoadAsset 加载资源失败.路径:[{0}]", resPath);
            return(t);
        }
예제 #19
0
        // 内置卸载指定路径的AssetBundle包
        private bool InternalUnLoad(string packagePath, bool force = false)
        {
            // 1.得到AB包的配置信息
            AssetBundlePackageCnf mainPackageCnf = _mainInfo.GetPackageCnf(packagePath);
            string mainPackagePath = mainPackageCnf.PackagePath;

            // 2.从缓存查找得到AssetBundle
            AssetBundleInfo packageInfo;

            _packageMap.TryGetValue(mainPackagePath, out packageInfo);
            ResLog.Assert(packageInfo != null, "AssetBundleLoader UnLoadAssetBundle 缓存中找不到对应的资源:[{0}]", mainPackagePath);
            if (packageInfo == null)
            {
                return(false);
            }

            // 3.这个AssetBundle的爸爸们还在,所以不能卸载
            List <string> parentPaths = _mainInfo.GetParentPaths(mainPackagePath);

            if (parentPaths != null)
            {
                int length = parentPaths.Count;
                for (int i = 0; i < length; i++)
                {
                    if (_packageMap.ContainsKey(parentPaths[i]))
                    {
                        return(false);
                    }
                }
            }
            // 4.爸爸们已经不在了,看下内部的引用是否已经完全为0了

            bool result = packageInfo.IsEmptyRef();

            ResLog.Assert(!(force && !result), "AssetBundleLoader InternalUnLoad Error.主资源:[{0}]强制卸载但还有引用在引用数:",
                          packagePath, packageInfo.RefCount);
            if (result || force)
            {
                packageInfo.UnLoad();
                _packageMap.Remove(mainPackagePath);
            }

            return(result);
        }
예제 #20
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);
        }
예제 #21
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);
        }
예제 #22
0
        public void CheckInfo()
        {
            int length = _otherOperation.Count;

            LogManager.Log("--------------------资源数量:[{0}]--------------------", _cacheRes.Count);
            LogManager.Log("--------------------其他请求:[{0}]--------------------", length);

            length = _onLoadingRes.Count;
            LogManager.Log("--------------------加载中的名字:[{0}]--------------------", length);
            for (int i = 0; i < length; i++)
            {
                ResLog.Log(_onLoadingRes[i]);
            }
            length = _loadOpertions.Count;
            LogManager.Log("--------------------加载中的请求:[{0}]--------------------", length);
            for (int i = 0; i < length; i++)
            {
                ResLog.Log(_loadOpertions[i].RequestResPath);
            }
            _loader.CheckInfo();
        }
예제 #23
0
        private void InternalCheckInfo()
        {
            LogManager.Assert(_onLoadingRequest.Count == _onLoadingAbPackage.Count, "AssetBundleLoader OnLoading Request List!=Name List");

            LogManager.Log("--------------------资源数量:[{0}]--------------------", _packageMap.Count);
            int length = _onLoadingRequest.Count;

            LogManager.Log("--------------------加载中的请求:[{0}]--------------------", length);
            for (int i = 0; i < length; i++)
            {
                ResLog.Log(_onLoadingRequest[i].RequestResPath);
            }

            LogManager.Assert(_waitToLoadRequest.Count == _onWaitAbPackage.Count, "OnWait Request List!=Name List");
            length = _waitToLoadRequest.Count;
            LogManager.Log("--------------------等待中的请求:[{0}]--------------------", length);
            for (int i = 0; i < length; i++)
            {
                ResLog.Log(_waitToLoadRequest[i].RequestResPath);
            }
        }
예제 #24
0
        public bool InitAssetBundle(AssetBundle ab, Object[] objs)
        {
            ResLog.Assert(ab != null, "AssetBundleInfo InitAssetBundle 初始化失败:ab为空");
            if (ab == null)
            {
                return(false);
            }
            _assetbundle = ab;
            _abList.Clear();
            int length = objs.Length;

            for (int i = 0; i < length; i++)
            {
                if (!_cnf._resNames.ContainsKey(objs[i].name))
                {
                    ResLog.Error("AssetBundleInfo InitAssetBundle 失败. 配置文件:[{0}]", objs[i].name);
                    continue;
                }
                ObjectInfo info = new ObjectInfo(objs[i], _cnf._resNames[objs[i].name]);
                _abList.Add(info);
            }
            return(true);
        }
예제 #25
0
        public T GetAsset <T>(string resPath) where T : Object
        {
            ResLog.Assert(!(_assetbundle == null || string.IsNullOrEmpty(resPath)),
                          "AssetBundleInfo GetAsset 失败。PackagePath:[{2}],AssetBundel:[{0}](true代表空),名字:[{1}]", _assetbundle == null, resPath, Path);
            if (_assetbundle == null || string.IsNullOrEmpty(resPath))
            {
                return(null);
            }


            ResToAssetBundleCnf resToAbCnf = AssetBundleManifestInfo.Instance.GetResToAb(resPath);

            if (resToAbCnf == null)
            {
                return(null);
            }

            int length = _abList.Count;

            for (int i = 0; i < length; i++)
            {
                ObjectInfo tmpInfo = _abList[i];
                if (tmpInfo.Path != resToAbCnf.ResPath)
                {
                    continue;
                }
                if (!tmpInfo.CheckType <T>())
                {
                    continue;
                }
                RefCount++;
                return(tmpInfo.GetAsset <T>(String.Empty));
            }
            ResLog.Assert(false, "从资源主包[{0}]中找不到对应类型的AssetInfo:[{1}]的资源", _cnf.PackagePath, resToAbCnf.ResPath);
            return(null);
        }
예제 #26
0
 protected override void Init()
 {
     ResLog.Log("Res:{0}", _path);
     _request = Resources.LoadAsync(_path);
 }