Пример #1
0
        private IEnumerator LoadAssetsIEnumerator(string path, Type assetType, Action <Object> callback)
        {
            if (assetsDics.ContainsKey(path))
            {
                AssetsData assets = assetsDics[path];
                assets.refCount++;

                if (callback != null)
                {
                    callback(assets.Assets[0]);
                }
            }
            else
            {
                yield return(loader.LoadAssetsIEnumerator(path, assetType, (assets) =>
                {
                    assetsDics.Add(path, assets);
                    if (callback != null)
                    {
                        callback(assets.Assets[0]);
                    }
                }));
            }

            yield return(0);
        }
Пример #2
0
        public void DestoryAssetsCounter(string path)
        {
            if (assetsDics.ContainsKey(path))
            {
                AssetsData assets = assetsDics[path];
                assets.refCount--;

                if (assets.refCount < 0)
                {
                    Debug.LogError("资源引用计数错误:(" + assets.refCount + ") " + assets.assetPath);
                    assets.refCount = 0;
                }
                if (assets.refCount == 0)
                {
                    //TO DO
                }
                string[] dependenciesNames = loader.GetAllDependenciesName(path);
                foreach (var item in dependenciesNames)
                {
                    DestoryAssetsCounter(item);
                }
            }
            else
            {
                Debug.LogError("未加载资源,不能Destroy :" + path);
            }
        }
Пример #3
0
        public override IEnumerator LoadAssetsIEnumerator(string path, Type resType, Action <AssetsData> callback)
        {
            AssetsData      assetsData      = null;
            string          newPath         = PathUtils.RemoveExtension(path);
            ResourceRequest resourceRequest = null;

            if (resType != null)
            {
                resourceRequest = Resources.LoadAsync(newPath, resType);
            }
            else
            {
                resourceRequest = Resources.LoadAsync(newPath);
            }
            yield return(resourceRequest);

            if (resourceRequest.asset != null)
            {
                assetsData        = new AssetsData(path);
                assetsData.Assets = new Object[] { resourceRequest.asset };
            }
            else
            {
                Debug.LogError("속潼呵겨,Path:" + path);
            }
            if (callback != null)
            {
                callback(assetsData);
            }
            yield return(new WaitForEndOfFrame());
        }
Пример #4
0
        public override IEnumerator LoadAssetsIEnumerator(string path, Type resType, Action <AssetsData> callback)
        {
            AssetBundleCreateRequest req = AssetBundle.LoadFromFileAsync(path);

            yield return(req);

            AssetBundle        ab    = req.assetBundle;
            AssetBundleRequest abReq = null;

            if (resType != null)
            {
                abReq = ab.LoadAllAssetsAsync(resType);
            }
            else
            {
                abReq = ab.LoadAllAssetsAsync();
            }
            yield return(abReq);

            AssetsData ad = new AssetsData(path);

            if (!assetBundleDics.ContainsKey(path))
            {
                assetBundleDics.Add(path, ab);
            }
            ad.Assets      = abReq.allAssets;
            ad.AssetBundle = ab;
            if (callback != null)
            {
                callback(ad);
            }

            yield return(0);
        }
Пример #5
0
        public Object LoadResourceAssets(string name)
        {
            //string path = PathUtils.GetAbsolutePath(ResLoadLocation.Resource, name);
            AssetsData assets = loadController.LoadAssets(name);

            if (assets != null)
            {
                return(assets.Assets[0]);
            }
            return(null);
        }
Пример #6
0
        public void Release(string path)
        {
            AssetsData assets = null;

            if (assetsDics.TryGetValue(path, out assets))
            {
                if (assets.refCount <= 0)
                {
                    UnloadAssets(assets, true);
                    assetsDics.Remove(path);
                    Debug.LogWarning("彻底释放" + path);
                }
            }
        }
Пример #7
0
 public void UnloadAssets(AssetsData assets, bool isForceAB)
 {
     if (assets.Assets != null && isForceAB)
     {
         foreach (var item in assets.Assets)
         {
             Debug.LogWarning("释放资源" + item);
             UnloadObject(item);
         }
         assets.Assets = null;
     }
     if (assets.AssetBundle != null)
     {
         assets.AssetBundle.Unload(isForceAB);
     }
 }
Пример #8
0
        public T LoadResourceAssets <T>(string name) where T : Object
        {
            T res = null;
            //string path = PathUtils.GetAbsolutePath(ResLoadLocation.Resource, name);
            AssetsData assets = loadController.LoadAssets <T>(name);

            if (assets != null)
            {
                res = assets.GetAssets <T>();
            }
            if (res == null)
            {
                Debug.LogError("Error=> Load Name :" + name + "  Type:" + typeof(T).FullName + "\n" + " Load Object:" + res);
            }
            return(res);
        }
Пример #9
0
        public override AssetsData LoadAssets <T>(string path)
        {
            AssetsData assetsData = null;
            string     newPath    = PathUtils.RemoveExtension(path);
            T          ass        = Resources.Load <T>(newPath);

            if (ass != null)
            {
                assetsData        = new AssetsData(path);
                assetsData.Assets = new Object[] { ass };
            }
            else
            {
                Debug.LogError("속潼呵겨,Path:" + path);
            }

            return(assetsData);
        }
Пример #10
0
        public AssetsData LoadAssetsLogic(string path, Func <bool> checkContainsAssets, Func <string, AssetsData> loadFunc)
        {
            LoadAssetsDependencie(path);
            AssetsData assets = null;

            if (checkContainsAssets())
            {
                assets = assetsDics[path];
            }
            else
            {
                assets = loadFunc(path);
                if (assets == null)
                {
                    Debug.LogError("资源加载失败:" + path);
                    return(assets);
                }
                else
                {
                    if (assetsDics.ContainsKey(path))
                    {
                        List <Object> list = new List <Object>(assetsDics[path].Assets);
                        foreach (var item in assets.Assets)
                        {
                            if (!list.Contains(item))
                            {
                                list.Add(item);
                            }
                        }
                        assetsDics[path].Assets = list.ToArray();
                        assets = assetsDics[path];
                    }
                    else
                    {
                        assetsDics.Add(path, assets);
                    }
                }
            }
            return(assets);
        }