Exemple #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.Scripts || string.IsNullOrEmpty(assetName))
        {
            return;
        }

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

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

        if (assetBundlePath != null)
        {
            UnloadAsset(assetBundlePath, true);
        }
    }
Exemple #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 = FilePathUtil.GetAssetBundlePath(type, assetName);

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

        AssetBundle assetBundle = LoadSingleAssetBundleSync(assetBundlePath);

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

        //返回AssetBundleName;
        string[] DependentAssetBundle = Manifest.GetAllDependencies(assetBundleName);
        foreach (string tempAssetBundle in DependentAssetBundle)
        {
            if (tempAssetBundle == FilePathUtil.GetAssetBundleFileName(AssetType.Shader, "Shader"))
            {
                continue;
            }
            string tempPtah = FilePathUtil.assetBundlePath + tempAssetBundle;
            LoadSingleAssetBundleSync(tempPtah);
        }
        return(assetBundle);
    }
Exemple #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 = FilePathUtil.GetAssetBundlePath(type, assetName);

        if (assetBundlePath != null)
        {
            UnloadAsset(assetBundlePath, false);
        }
    }
Exemple #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 LoadAssetBundleAsync(AssetType type, string assetName, Action <AssetBundle> action, Action <float> progress)
    {
        if (type == AssetType.Non || string.IsNullOrEmpty(assetName))
        {
            yield break;
        }
        string assetBundlePath = FilePathUtil.GetAssetBundlePath(type, assetName);

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

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

        while (itorTarget.MoveNext())
        {
            yield return(null);
        }
    }
Exemple #5
0
    /// <summary>
    /// 加载Shader AssetBundle;
    /// </summary>
    /// <returns>AssetBundle</returns>
    public AssetBundle LoadShaderAssetBundle()
    {
        string path = FilePathUtil.GetAssetBundlePath(AssetType.Shader, "Shader");

        return(LoadSingleAssetBundleSync(path));
    }