Resources 目录
Unity 打包时只会保留Resources 和StreamingAssets 目录下的资源,所以不需要运行时加载的资源一定不要放到Resources 目录。
GameObject.Destroy()
删除游戏对象并不会把它引用的资源删掉,可以使用Resources.UnloadAsset() / Resources.UnloadUnusedAssets() 方法强制卸载资源。
AssetBundle
打包代码
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
using System.IO;
public class AssetBundleTool {
[MenuItem("Tools/BuildAssetbundle")]
static void BuildAssetbundle(){
string outpath = Path.Combine(Application.dataPath, "StreamingAssets");
if(Directory.Exists(outpath)){
Directory.Delete(outpath, true);
}
Directory.CreateDirectory(outpath);
// 在editor中填写bundle名后打包
// BuildPipeline.BuildAssetBundles(outpath, BuildAssetBundleOptions.ChunkBasedCompression, BuildTarget.StandaloneWindows);
// 代码中设置要打包的资源
List<AssetBundleBuild> builds = new List<AssetBundleBuild>();
builds.Add(new AssetBundl