- 最后登录
- 2019-12-2
- 注册时间
- 2012-8-25
- 阅读权限
- 90
- 积分
- 34660
- 纳金币
- 38268
- 精华
- 111
|
- 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!!!!!");
- }
- }
- }
复制代码 |
|