UnityのAssetbundleパッケージレコード1
3253 ワード
using UnityEngine;
using System.Collections;
using UnityEditor;
public class ExportAssetBundles {
[MenuItem("Custom Editor/Create comm asset")]
//
static void CreateCommAssetBunldes()
{
// login.png
// A
BuildPipeline.PushAssetDependencies();
string path = Application.streamingAssetsPath;
BuildPipeline.BuildAssetBundle(AssetDatabase.LoadMainAssetAtPath("Assets/Resources/login.png"), null,
path + "/login.assetbundle",
BuildAssetBundleOptions.CollectDependencies);
// B: B A
BuildPipeline.PushAssetDependencies();
BuildPipeline.BuildAssetBundle(AssetDatabase.LoadMainAssetAtPath("Assets/Resources/Prefab1.prefab"), null,
path + "/Prefab1.assetbundle",
BuildAssetBundleOptions.CollectDependencies);
//
BuildPipeline.PopAssetDependencies();
BuildPipeline.PopAssetDependencies();
// C
BuildPipeline.BuildAssetBundle(AssetDatabase.LoadMainAssetAtPath("Assets/Resources/Prefab2.prefab"), null,
path + "/Prefab2.assetbundle",
BuildAssetBundleOptions.CollectDependencies);
EditorUtility.DisplayDialog("", "Completed", "OK");
}
[@MenuItem("Custom Editor/Create AssetBunldes Main")]
//
static void CreateAssetBunldesMain()
{
Caching.CleanCache();
// Project
Object[] SelectedAsset = Selection.GetFiltered(typeof(Object), SelectionMode.DeepAssets);
int i = 0;
//
foreach (Object obj in SelectedAsset)
{
//string sourcePath = AssetDatabase.GetAssetPath(obj);
string targetPath = Application.streamingAssetsPath + "/" + obj.name + ".assetbundle";
if (BuildPipeline.BuildAssetBundle(obj, null, targetPath, BuildAssetBundleOptions.CollectDependencies))
{
Debug.Log(obj.name + " ");
}
else
{
Debug.Log(obj.name + " ");
}
}
//
EditorUtility.DisplayDialog("", "Completed", "OK");
AssetDatabase.Refresh();
}
[@MenuItem("Custom Editor/Create AssetBunldes ALL")]
//
static void CreateAssetBunldesALL()
{
Caching.CleanCache();
string Path = Application.streamingAssetsPath + "/ALL.assetbundle";
Object[] SelectedAsset = Selection.GetFiltered(typeof(Object), SelectionMode.DeepAssets);
foreach (Object obj in SelectedAsset)
{
Debug.Log("Create AssetBunldes name :" + obj);
}
//
if (BuildPipeline.BuildAssetBundle(null, SelectedAsset, Path, BuildAssetBundleOptions.CollectDependencies))
{
AssetDatabase.Refresh();
}
}
}