纳金网
标题:
AssetBunldes打包程序代码
[打印本页]
作者:
狂风大尉
时间:
2014-6-26 20:27
标题:
AssetBunldes打包程序代码
using UnityEngine;
using System.Collections;
using UnityEditor;
using System.IO;
/*
* 這只是打包assetBunldes的編輯項目
* androidr使用就要使用forAndroid結尾的項目打包
* 電腦上要使用的則不用
* IOS目前無需求
* 以下是全打包及單一打包差別
* BuildPipeline.BuildAssetBundle (obj, null, targetPath, BuildAssetBundleOptions.CollectDependencies,BuildTarget.Android)
* BuildPipeline.BuildAssetBundle (null, SelectedAsset, Path, BuildAssetBundleOptions.CollectDependencies,BuildTarget.Android)
* */
public class CreateAssetBunldes : MonoBehaviour
{
[MenuItem("yuchiHelper/CreateAssetBunldesMain")]
static void CreateAssetBunldesMain ()
{
//取得在Project中選擇的所有對象
Object[] SelectedAsset = Selection.GetFiltered (typeof(Object), SelectionMode.DeepAssets);
//遍歷這個選擇到的對象
foreach (Object obj in SelectedAsset)
{
string sourcePath = AssetDatabase.GetAssetPath (obj);
//将Assetbundle放在AssetBundles文件夹下,如果没有就創建一個
//AssetBundles是只是路徑
//網路下载:就不需要放在這裡。
string Path = Application.dataPath + "/AssetBundles/" + obj.name + ".assetbundle";
if (BuildPipeline.BuildAssetBundle (obj, null, Path, BuildAssetBundleOptions.CollectDependencies))
{
Debug.Log(obj.name +"打包成功");
}
else
{
Debug.Log(obj.name +"打包失敗");
}
}
//刷新
AssetDatabase.Refresh ();
}
[MenuItem("yuchiHelper/CreateAssetBunldesMainForAndroid")]
static void CreateAssetBunldesMainForAndroid ()
{
Object[] SelectedAsset = Selection.GetFiltered (typeof(Object), SelectionMode.DeepAssets);
foreach (Object obj in SelectedAsset)
{
string sourcePath = AssetDatabase.GetAssetPath (obj);
string Path = Application.dataPath + "/AssetBundles/" + obj.name + ".assetbundle";
if (BuildPipeline.BuildAssetBundle (obj, null, Path, BuildAssetBundleOptions.CollectDependencies,BuildTarget.Android))
{
Debug.Log(obj.name +"打包成功");
}
else
{
Debug.Log(obj.name +"打包失敗");
}
}
AssetDatabase.Refresh ();
}
[MenuItem("yuchiHelper/CreateAssetBunldesALLForAndroid")]
static void CreateAssetBunldesALLForAndroid ()
{
Caching.CleanCache ();
string Path = Application.dataPath + "/AssetBundles/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,BuildTarget.Android))
{
Debug.Log("Success!!! for android");
AssetDatabase.Refresh ();
}
else
{
Debug.Log("false!!!!!");
}
}
[MenuItem("yuchiHelper/CreateAssetBunldesALL")]
static void CreateAssetBunldesALL ()
{
Caching.CleanCache ();
string Path = Application.dataPath + "/AssetBundles/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))
{
Debug.Log("Success!!!");
AssetDatabase.Refresh ();
}
else
{
Debug.Log("false!!!!!");
}
}
}
复制代码
作者:
hyui
时间:
2014-6-26 21:22
感谢分享这个!! !
作者:
HIDEOKOJIMA
时间:
2014-6-26 22:39
感谢分享这个!
作者:
wucnj
时间:
2014-6-27 13:38
感谢分享!!!
欢迎光临 纳金网 (http://course.narkii.com/club/)
Powered by Discuz! X2.5