[MenuItem("CreateScene/打包场景")]
static void CreateSceneALL()
{
Object[] SelectedAsset = Selection.GetFiltered(typeof(Object), SelectionMode.DeepAssets);
foreach (Object obj in SelectedAsset)
{
//取得当前选择场景文件路径
string myPath = AssetDatabase.GetAssetPath(obj);
//去掉路径前部分得到文件名
string path = myPath.Replace("Assets/", "");
//替换文件扩展名
path = path.Replace("unity", "unity3d");
//清楚缓存
Caching.ClearCache();
//拼接出打包之后文件存放路径(和场景文件同目录下)
string Path = Application.dataPath + "/" + path;
string[] array = path.Split('.');
for (int i = 0; i < array.Length; i++)
{
Debug.Log(array[i]);
}
string[] levels = { myPath };
//打包场景
BuildPipeline.BuildPlayer(levels, Path, BuildTarget.WebGL, BuildOptions.BuildAdditionalStreamedScenes);
}
//刷新编辑器
AssetDatabase.Refresh();
}
[MenuItem("CreateScene/打包模型")]
static void CreatePrefabs()
{
//取得当前选择场景文件路径
string myPath = AssetDatabase.GetAssetPath(Selection.activeObject);
//去掉路径前部分得到文件名
string path = myPath.Replace("Assets/", "");
//替换文件扩展名
//path = path.Replace("prefab", "assetbundle");
//清楚缓存
Caching.ClearCache();
//拼接出打包之后文件存放路径(和场景文件同目录下)
string Path = Application.dataPath + "/" + path;
if (Path.Length != 0)
{
// 选择的要保存的对象
Object[] selection = Selection.GetFiltered(typeof(Object), SelectionMode.DeepAssets);
AssetBundleBuild[] buildMap = new AssetBundleBuild[1];
buildMap[0].assetBundleName = Path;
buildMap[0].assetNames = new string[] { Path };
//打包
//BuildPipeline.BuildAssetBundle(Selection.activeObject, selection, Path, BuildAssetBundleOptions.CollectDependencies | BuildAssetBundleOptions.DeterministicAssetBundle, BuildTarget.StandaloneWindows);
// BuildPipeline.BuildAssetBundles(Application.dataPath+ "/ResourcesPrefab", buildMap);
BuildPipeline.BuildAssetBundles(Application.dataPath + "/Prefab", 0, EditorUserBuildSettings.activeBuildTarget);
}
//刷新编辑器
AssetDatabase.Refresh();
}
using UnityEngine;
using System.Collections;
using UnityEditor;
public class createABundle : MonoBehaviour {
[MenuItem("Framework/Build WebGL Resource", false, 101)]
public static void BuildWebGLResource()
{
Caching.ClearCache();
string streamPath = Application.streamingAssetsPath + "/scene/";
BuildPipeline.BuildAssetBundles(streamPath, BuildAssetBundleOptions.None, BuildTarget.WebGL);
AssetDatabase.Refresh();
}
[MenuItem("Framework/SetAssetBundleNameExtension")] //将选定的资源进行统一设置AssetBundle名
static void SetBundleName()
{
Object[] selects = Selection.objects;
foreach (Object item in selects)
{
string path = AssetDatabase.GetAssetPath(item);
AssetImporter asset = AssetImporter.GetAtPath(path);
asset.assetBundleName = item.name;//设置Bundle文件的名称
asset.assetBundleVariant = "unity3d";//设置Bundle文件的扩展名
asset.SaveAndReimport();
}
AssetDatabase.Refresh();
}
}