示例#1
0
        /// <summary>
        /// 释放本场景中所有的资源(建议仅在场景转换中使用)
        /// </summary>
        public void DisposeAllAssets()
        {
            try
            {
                //逐一释放所有加载过的AssetBundle包中的资源
                foreach (SingleABLoader loader in loaderCacheDict.Values)
                {
                    loader.DisposeAll();
                }
            }
            finally
            {
                loaderCacheDict.Clear();
                loaderCacheDict = null;

                //释放其他对象占用资源
                relationDict.Clear();
                relationDict         = null;
                currentSceneName     = null;
                label                = null;
                _LoadCompleteHandler = null;

                //卸载没有使用到的资源
                Resources.UnloadUnusedAssets();

                //立即执行垃圾回收
                System.GC.Collect();
            }
        }
示例#2
0
 void Update()
 {
     if (Input.GetKeyDown(KeyCode.A))
     {
         Debug.Log("释放资源");
         //loader.Dispose();
         loader.DisposeAll();
     }
 }