コード例 #1
0
        /// <summary>
        /// 通用资源AssetBundle卸载方法[Unload(true)];
        /// </summary>
        /// <param name="type">资源类型</param>
        /// <param name="assetName">资源名字</param>
        public void UnloadAsset(AssetType type, string assetName)
        {
            if (type == AssetType.Non || type == AssetType.Shader || type == AssetType.Lua || type == AssetType.Scripts || string.IsNullOrEmpty(assetName))
            {
                return;
            }

            string assetBundleName = FilePathUtility.GetAssetBundleFileName(type, assetName);

            string[] DependentAssetBundle = Manifest.GetAllDependencies(assetBundleName);
            foreach (string tempAssetBundle in DependentAssetBundle)
            {
                if (tempAssetBundle == FilePathUtility.GetAssetBundleFileName(AssetType.Shader, "Shader"))
                {
                    continue;
                }
                string tempPtah = FilePathUtility.AssetBundlePath + tempAssetBundle;
                UnloadAsset(tempPtah, true);
            }
            string assetBundlePath = FilePathUtility.GetAssetBundlePath(type, assetName);

            if (assetBundlePath != null)
            {
                UnloadAsset(assetBundlePath, true);
            }
        }
コード例 #2
0
        /// <summary>
        /// AssetBundle同步加载;
        /// </summary>
        /// <param name="type">资源类型</param>
        /// <param name="assetName">资源名字</param>
        /// <returns>AssetBundle</returns>
        public AssetBundle LoadAssetBundleSync(AssetType type, string assetName)
        {
            if (type == AssetType.Non || string.IsNullOrEmpty(assetName))
            {
                return(null);
            }

            string assetBundlePath = FilePathUtility.GetAssetBundlePath(type, assetName);

            if (assetBundlePath == null)
            {
                return(null);
            }
            string assetBundleName = FilePathUtility.GetAssetBundleFileName(type, assetName);

            AssetBundle assetBundle = LoadSingleSync(assetBundlePath);

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

            //返回AssetBundleName;
            string[] DependentAssetBundle = Manifest.GetAllDependencies(assetBundleName);
            foreach (string tempAssetBundle in DependentAssetBundle)
            {
                if (tempAssetBundle == FilePathUtility.GetAssetBundleFileName(AssetType.Shader, "Shader"))
                {
                    continue;
                }
                string tempPtah = FilePathUtility.AssetBundlePath + tempAssetBundle;
                LoadSingleSync(tempPtah);
            }
            return(assetBundle);
        }
コード例 #3
0
        /// <summary>
        /// AssetBundle 镜像卸载方法[Unload(false)],使用资源为一般初始化就全局保存不在销毁的资源,如:Shader;
        /// </summary>
        /// <param name="type">资源类型</param>
        /// <param name="assetName">资源名字</param>
        public void UnloadMirroring(AssetType type, string assetName)
        {
            if (type == AssetType.Non || type == AssetType.Scripts || string.IsNullOrEmpty(assetName))
            {
                return;
            }
            string assetBundlePath = FilePathUtility.GetAssetBundlePath(type, assetName);

            if (assetBundlePath != null)
            {
                UnloadAsset(assetBundlePath, false);
            }
        }
コード例 #4
0
        /// <summary>
        /// AssetBundle异步加载;
        /// </summary>
        /// <param name="type">资源类型</param>
        /// <param name="assetName">资源名字</param>
        /// <param name="action">AssetBundle回调</param>
        /// <param name="progress">progress回调</param>
        /// <returns></returns>
        public IEnumerator <float> LoadAssetBundleAsync(AssetType type, string assetName, Action <AssetBundle> action, Action <float> progress)
        {
            if (type == AssetType.Non || string.IsNullOrEmpty(assetName))
            {
                yield break;
            }
            string assetBundlePath = FilePathUtility.GetAssetBundlePath(type, assetName);

            if (assetBundlePath == null)
            {
                yield break;
            }
            string assetBundleName = FilePathUtility.GetAssetBundleFileName(type, assetName);

            //先加载依赖的AssetBundle;
            string[] DependentAssetBundle = Manifest.GetAllDependencies(assetBundleName);
            foreach (string tempAssetBundle in DependentAssetBundle)
            {
                if (tempAssetBundle == FilePathUtility.GetAssetBundleFileName(AssetType.Shader, "Shader"))
                {
                    continue;
                }
                string tempPtah          = FilePathUtility.AssetBundlePath + tempAssetBundle;
                IEnumerator <float> itor = LoadSingleAsync(tempPtah, null, null);
                while (itor.MoveNext())
                {
                    yield return(Timing.WaitForOneFrame);
                }
            }
            //加载目标AssetBundle;
            IEnumerator <float> itorTarget = LoadSingleAsync(assetBundlePath, action, progress);

            while (itorTarget.MoveNext())
            {
                yield return(Timing.WaitForOneFrame);
            }
        }
コード例 #5
0
        public AssetBundle LoadLuaAssetBundle()
        {
            string path = FilePathUtility.GetAssetBundlePath(AssetType.Lua, "lua");

            return(LoadSingleSync(path));
        }
コード例 #6
0
        /// <summary>
        /// 加载Shader AssetBundle;
        /// </summary>
        /// <returns>AssetBundle</returns>
        public AssetBundle LoadShaderAssetBundle()
        {
            string path = FilePathUtility.GetAssetBundlePath(AssetType.Shader, "Shader");

            return(LoadSingleSync(path));
        }