使用方法:
在unity的Project视图中,建立editor目录,建立javascript,将下面的代码拷入.
然后在出现的Level菜单下选择.
用于导出场景或Prefab,然后游戏运行时通过WWW类来加载.
祝大家开心.
#pragma strict
#pragma implicit
#pragma downcast
import System.Collections.Generic;
//////////////////////////////////////////////////////
///场景,组件,导出工具.
//////////////////////////////////////////////////////
/** 上次场景保存的名字 */
static var lastSceneName:String = "";
/** 常量 */
static var strSaveScene:String = "指定保存场景的位置";
/** 导出的场景后缀 */
static var strScenesAssetName = "unity3d";
/** 场景后缀 */
static var strSceneExtendName = "unity";
static var strSceneExportError = "no scene file!";
/**
导出场景
*/
@MenuItem("Level4/Export/ExportScene")
static function BuildStreaedScene(){
var pathList:List.<String> = new List.<String>();
var objs:Object[] = Selection.GetFiltered(typeof(Object),SelectionMode.DeepAssets);
for(var obj:UnityEngine.Object in objs){
var path:String = AssetDatabase.GetAssetPath(obj);
if(path.Contains(strSceneExtendName)){
pathList.Add(path);
}
}
if(pathList.Count > 0){
var locationPath:String = EditorUtility.SaveFilePanel(strSaveScene,"",lastSceneName,strScenesAssetName);
if(!String.IsNullOrEmpty(locationPath)){
BuildPipeline.BuildStreamedSceneAssetBundle(pathList.ToArray(),locationPath,BuildTarget.WebPlayer);
OpenDir(locationPath);
}
}else{
Debug.Log(strSceneExportError);
}
pathList.Clear();
pathList = null;
}
/**
导出素材
*/
@MenuItem("Level4/Export/ExportResource")
static function ExportResource(){
var path:String = EditorUtility.SaveFilePanel("导出","","资源名","unity3d");
if(path.Length != 0){
BuildPipeline.BuildAssetBundle(Selection.activeObject,Selection.objects,path);
}
}
/**
导出素材和素材依赖
*/
@MenuItem("Level4/Export/ExportResourceTrack Dependence")
static function ExportResourceTrack(){
var path:String = EditorUtility.SaveFilePanel("导出","","资源名","unity3d");
if(path.Length != 0){
var objs:Object[] = Selection.GetFiltered(Object,SelectionMode.DeepAssets);
BuildPipeline.BuildAssetBundle(Selection.activeObject,objs,path,BuildAssetBundleOptions.CollectDependencies | BuildAssetBundleOptions.CompleteAssets);
Selection.objects = objs;
//打开导出的目录
OpenDir(path);
}
}
/**
打开目录
*/
static function OpenDir(path:String){
path = System.IO.Directory.GetParent(path).ToString();
System.Diagnostics.Process.Start(path);
}