AssetBundle资源打包
using UnityEngine;
using System.Collections;
using UnityEditor;
using System.IO;
using System.Collections.Generic;
public class ExportAssetBundles : MonoBehaviour {
[MenuItem("Tools/BuildWebplayerScene")]
static void MyBuildScene()
{
//清空緩存
Caching.CleanCache();
//地址數組,用於存儲待打包的場景,需自己決定打包那些場景
string[] scenes = { "Assets/Scenes/LvTest.unity" };
//將場景打包到Test.unity3d文件中,注意打包目標是.WebPlayer的資源,用於發布成網頁的資源,這裏可以指定打包成.StandaloneWindows
BuildPipeline.BuildPlayer(scenes , "Assets/Resources/Test.unity3d", BuildTarget.WebPlayer, BuildOptions.BuildAdditionalStreamedScenes);
AssetDatabase.Refresh();
}
//打包場景
[MenuItem("Tools/BuildWindowScene")]
static void ExportScene()
{
//清空緩存
Caching.CleanCache();
// 打開保存麵板,獲得用戶選擇的路徑 ,參1 對話框名,參2默認路徑,參3默認保存名,參4資源格式
string path = EditorUtility.SaveFilePanel("Save Resource", @"E:\", "New Resource", "assetbundle");//或可以為.unity3d
if (path.Length != 0)
{
// 選擇的要保存的對象
Object[] selection = Selection.GetFiltered(typeof(Object), SelectionMode.DeepAssets);
string[] scenes = { "Assets/Scenes/LvB.unity" };//要打包的場景放在該數組中
//注意BuildTarget選項
BuildPipeline.BuildPlayer(scenes, path, BuildTarget.StandaloneWindows, BuildOptions.BuildAdditionalStreamedScenes);
}
AssetDatabase.Refresh();
}
}
- 下一篇:Unity3d 一个优秀的程序必备的几种设计模式
- 上一篇:unity中的基础数学