Beispiel #1
0
 private AssetOperationHandle LoadInternal(string assetName, System.Type assetType, IAssetParam param)
 {
     if (_cacheLoader == null)
     {
         _cacheLoader = AssetSystem.CreateFileLoader(Location);
     }
     return(_cacheLoader.LoadAssetAsync(assetName, assetType, param));
 }
Beispiel #2
0
 /// <summary>
 /// 释放资源
 /// </summary>
 public void Release()
 {
     if (_cacheLoader != null)
     {
         _cacheLoader.Release();
         _cacheLoader = null;
     }
     Location = string.Empty;
 }
Beispiel #3
0
        /// <summary>
        /// 强制回收所有资源
        /// </summary>
        public static void ForceReleaseAll()
        {
            for (int i = 0; i < _fileLoaders.Count; i++)
            {
                AssetFileLoader loader = _fileLoaders[i];
                loader.Destroy(true);
            }
            _fileLoaders.Clear();

            // 释放所有资源
            Resources.UnloadUnusedAssets();
        }
Beispiel #4
0
 /// <summary>
 /// 资源回收
 /// 卸载引用计数为零的资源
 /// </summary>
 public static void Release()
 {
     for (int i = _fileLoaders.Count - 1; i >= 0; i--)
     {
         AssetFileLoader loader = _fileLoaders[i];
         if (loader.IsDone() && loader.RefCount <= 0)
         {
             loader.Destroy(true);
             _fileLoaders.RemoveAt(i);
         }
     }
 }
Beispiel #5
0
        public static int DebugGetFileLoaderFailedCount()
        {
            int count = 0;

            for (int i = 0; i < _fileLoaders.Count; i++)
            {
                AssetFileLoader temp = _fileLoaders[i];
                if (temp.States == EAssetFileLoaderStates.LoadAssetFileFailed || temp.GetFailedProviderCount() > 0)
                {
                    count++;
                }
            }
            return(count);
        }
Beispiel #6
0
        // 从列表里获取加载器
        private static AssetFileLoader TryGetFileLoader(string loadPath)
        {
            AssetFileLoader loader = null;

            for (int i = 0; i < _fileLoaders.Count; i++)
            {
                AssetFileLoader temp = _fileLoaders[i];
                if (temp.LoadPath.Equals(loadPath))
                {
                    loader = temp;
                    break;
                }
            }
            return(loader);
        }
Beispiel #7
0
        internal static AssetFileLoader CreateFileLoaderInternal(string loadPath, string manifestPath)
        {
            // 如果加载器已经存在
            AssetFileLoader loader = TryGetFileLoader(loadPath);

            if (loader != null)
            {
                loader.Reference();                 //引用计数
                return(loader);
            }

            // 创建加载器
            AssetFileLoader newLoader = null;

            if (SystemMode == EAssetSystemMode.EditorMode)
            {
                newLoader = new AssetDatabaseFileLoader(loadPath);
            }
            else if (SystemMode == EAssetSystemMode.ResourcesMode)
            {
                newLoader = new AssetResourcesFileLoader(loadPath);
            }
            else if (SystemMode == EAssetSystemMode.BundleMode)
            {
                newLoader = new AssetBundleFileLoader(loadPath, manifestPath);
            }
            else
            {
                throw new NotImplementedException($"{SystemMode}");
            }

            // 新增下载需求
            _fileLoaders.Add(newLoader);
            newLoader.Reference();             //引用计数
            return(newLoader);
        }
Beispiel #8
0
 public AssetResourcesProvider(AssetFileLoader owner, string assetName, System.Type assetType)
     : base(owner, assetName, assetType)
 {
 }
Beispiel #9
0
        public override void Update()
        {
            // 如果资源文件加载完毕
            if (States == EAssetFileLoaderStates.LoadAssetFileOK || States == EAssetFileLoaderStates.LoadAssetFileFailed)
            {
                UpdateAllProvider();
                return;
            }

            if (States == EAssetFileLoaderStates.None)
            {
                States = EAssetFileLoaderStates.LoadDepends;
            }

            // 1. 加载所有依赖项
            if (States == EAssetFileLoaderStates.LoadDepends)
            {
                string[] dependencies = AssetSystem.BundleServices.GetDirectDependencies(_manifestPath);
                if (dependencies.Length > 0)
                {
                    foreach (string dpManifestPath in dependencies)
                    {
                        string          dpLoadPath = AssetSystem.BundleServices.GetAssetBundleLoadPath(dpManifestPath);
                        AssetFileLoader dpLoader   = AssetSystem.CreateFileLoaderInternal(dpLoadPath, dpManifestPath);
                        _depends.Add(dpLoader);
                    }
                }
                States = EAssetFileLoaderStates.CheckDepends;
            }

            // 2. 检测所有依赖完成状态
            if (States == EAssetFileLoaderStates.CheckDepends)
            {
                foreach (var dpLoader in _depends)
                {
                    if (dpLoader.IsDone() == false)
                    {
                        return;
                    }
                }
                States = EAssetFileLoaderStates.LoadAssetFile;
            }

            // 3. 加载AssetBundle
            if (States == EAssetFileLoaderStates.LoadAssetFile)
            {
#if UNITY_EDITOR
                // 注意:Unity2017.4编辑器模式下,如果AssetBundle文件不存在会导致编辑器崩溃,这里做了预判。
                if (System.IO.File.Exists(LoadPath) == false)
                {
                    LogSystem.Log(ELogType.Warning, $"Not found assetBundle file : {LoadPath}");
                    States = EAssetFileLoaderStates.LoadAssetFileFailed;
                    return;
                }
#endif

                // Load assetBundle file
                _cacheRequest = AssetBundle.LoadFromFileAsync(LoadPath);
                States        = EAssetFileLoaderStates.CheckAssetFile;
            }

            // 4. 检测AssetBundle加载结果
            if (States == EAssetFileLoaderStates.CheckAssetFile)
            {
                if (_cacheRequest.isDone == false)
                {
                    return;
                }
                CacheBundle = _cacheRequest.assetBundle;

                // Check error
                if (CacheBundle == null)
                {
                    LogSystem.Log(ELogType.Warning, $"Failed to load assetBundle file : {LoadPath}");
                    States = EAssetFileLoaderStates.LoadAssetFileFailed;
                }
                else
                {
                    States = EAssetFileLoaderStates.LoadAssetFileOK;
                }
            }
        }
Beispiel #10
0
 public AssetSceneProvider(AssetFileLoader owner, string assetName, System.Type assetType, SceneInstanceParam param)
     : base(owner, assetName, assetType)
 {
     _param = param;
 }
Beispiel #11
0
 public AssetBundleProvider(AssetFileLoader owner, string assetName, System.Type assetType)
     : base(owner, assetName, assetType)
 {
     _loader = owner as AssetBundleFileLoader;
 }