Unity 4.x 资源打包

时间:2021-10-11 20:16:30
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor; public class ExportAssetBundles : MonoBehaviour
{
//在Unity编辑器中添加菜单
[MenuItem("Assets/Build AssetBundle From Selection")]
static void ExportResource()
{
//打开保存面板
string path = EditorUtility.SaveFilePanel("Save Resource", string.Empty, "New Resource", "assetbundle");
if (path.Length > 0)
{
//选择要打包的对象
Object[] selections = Selection.GetFiltered(typeof(Object), SelectionMode.DeepAssets); //打包
BuildPipeline.BuildAssetBundle(Selection.activeObject, selections, path, BuildAssetBundleOptions.CompleteAssets | BuildAssetBundleOptions.CollectDependencies, BuildTarget.StandaloneWindows);
}
} [MenuItem("Assets/Save Scene")]
static void ExportScene()
{
string path = EditorUtility.SaveFilePanel("Save Resource", string.Empty, "New Resource", "unity3d"); if (path.Length > 0)
{
Object[] selection = Selection.GetFiltered(typeof(Object), SelectionMode.DeepAssets); //具体到工程中,需要动态设置
string[] scenes = { "Assets/Scene1.unity" }; BuildPipeline.BuildPlayer(scenes, path, BuildTarget.StandaloneWindows, BuildOptions.BuildAdditionalStreamedScenes);
}
}
}