Example #1
0
    private static void DestroyObject(ObjectReference or)
    {
        // 删除自己
        if (ResourceUtil.isLog)
        {
            Debug.Log("UnloadAsset " + or.assetName);
        }
        if (!(or.obj is GameObject))
        {
            Resources.UnloadAsset(or.obj);
        }
        //else

        /* GameObejct的释放方法
         *  1 assetbundle.unload(true)
         *  2 Resources.UnloadUnusedAsset()
         */


        // 释放引用bundle
        string bundleName = BundleAsset.GetBundleName(or.assetName);

        if (bundleName == null)
        {
            return;
        }
        ReferenceBundle.ReleaseBundle(bundleName);
    }
 public void Clear()
 {
     if (assetBundle != null)
     {
         //Debug.Log("Destory LoadBundleInfo " + bundleName);
         ReferenceBundle.ReleaseBundle(bundleName);
         assetBundle = null;
     }
     RemoveAllBundleRequest();
     bundleName = null;
     request    = null;
     step       = LoadBundleStep.None;
 }
    /// <summary>
    /// 异步加载bundle
    /// </summary>
    /// <param name="bundleName">bundle路径</param>
    /// <param name="onCreateAssetBundle">加载成功后的回调 取消加载后将回调将失效</param>
    /// <returns></returns>
    public static int CreateAssetBundleAsync(int requestId, string bundleName, OnCreateAssetBundle onCreateAssetBundle)
    {
        // 回调不存在不允加载
        if (onCreateAssetBundle == null)
        {
            return(0);
        }

        LoadBundleInfo loadBundleInfo = GetLoadBundleInfo(bundleName);

        if (loadBundleInfo == null)
        {
            loadBundleInfo = GetTempLoadBundleInfo();
            _loadBundleInfoList.Add(bundleName, loadBundleInfo);
            loadBundleInfo.bundleName = bundleName;
            EnterLoadWait(loadBundleInfo);
        }

        requestId = loadBundleInfo.CreateBundleRequest(requestId, onCreateAssetBundle);
        // 未请求
        if (loadBundleInfo.step == LoadBundleStep.LoadWait)
        {
            // 1 获取依赖列表
            List <string> dependencies = BundleDependencies.GetAssetBundleDependencies(bundleName);
            // 2 递归请求加载
            if (dependencies != null && dependencies.Count > 0)
            {
                foreach (string tempBundleName in dependencies)
                {
                    CreateAssetBundleAsync(requestId, tempBundleName, (string tBundleName, AssetBundle tAssetBundle, int tRequestId) => {
                        // 回调返回会增加引用 所以这里直接释放
                        ReferenceBundle.ReleaseBundle(tBundleName);
                    });
                }
            }
            // 3 正加载列表
            List <LoadBundleInfo> loadingBundleInfoList = GetLoadBundleStateList(LoadBundleStep.Loading);
            if (loadingBundleInfoList.Count < _frameLoadMaxCount)
            {
                LoadAssetBundle(loadBundleInfo);
            }
        }

        return(requestId);
    }
 public void Clear()
 {
     if (asset != null)
     {
         ReferenceObject.ReleaseObject(assetName);
         asset = null;
     }
     if (assetBundle != null)
     {
         ReferenceBundle.ReleaseBundle(bundleName);
         assetBundle = null;
     }
     step        = LoadAssetStep.None;
     bundleName  = null;
     requestId   = 0;
     request     = null;
     assetName   = null;
     onLoadAsset = null;
 }
Example #5
0
 public static void DestoryAssetBundle(string bundleName)
 {
     ReferenceBundle.ReleaseBundle(bundleName);
 }