Unity 打包模型的方法

来源:互联网 发布:怎么删除软件 编辑:程序博客网 时间:2024/05/16 18:14

模型导出

首先要根据不同的平台有不同的打包方法,在代码中要有平台的区分执行不同的打包代码,用到的材质类型要在GraphicsSettings中设置一下,不然特效或者模型的材质容易丢失,打包时选中Project中的预设体,点击Custom Editor就可以导出,Custom Editor在菜单栏中,这个类要放在Editor文件夹中。

        using UnityEngine;        using System.Collections;        using UnityEditor;        public class Test : Editor        {            [MenuItem("Custom Editor/Create AssetBunldes Main")]            static void CreateAssetBunldesMain ()            {                //获取在Project视图中选择的所有游戏对象                Object[] SelectedAsset = Selection.GetFiltered (typeof(Object), SelectionMode.DeepAssets);                //遍历所有的游戏对象                foreach (Object obj in SelectedAsset)                 {                    string sourcePath = AssetDatabase.GetAssetPath (obj);                    //本地测试:建议最后将Assetbundle放在StreamingAssets文件夹下,如果没有就创建一个,因为移动平台下只能读取这个路径                    //StreamingAssets是只读路径,不能写入                    //服务器下载:就不需要放在这里,服务器上客户端用www类进行下载。                    //        #if UNITY_ANDROID                    string targetPath = "F:/" + obj.name + ".assetbundle";        #elif UNITY_IPHONE                    string targetPath = Application.dataPath + "/StreamingAssets/" + obj.name + ".assetbundle";        #endif                    bool dabao =        #if UNITY_ANDROID                    BuildPipeline.BuildAssetBundle(obj, null, targetPath, BuildAssetBundleOptions.CollectDependencies | BuildAssetBundleOptions.CompleteAssets, BuildTarget.Android);        #elif UNITY_IPHONE                    BuildPipeline.BuildAssetBundle(obj, null, targetPath,BuildAssetBundleOptions.CollectDependencies | BuildAssetBundleOptions.CompleteAssets, BuildTarget.iOS );        #elif UNITY_STANDALONE_WIN || UNITY_EDITOR                    BuildPipeline.BuildAssetBundle (obj, null, targetPath, BuildAssetBundleOptions.CollectDependencies)         #else                    string.Empty;          #endif                    if (dabao) {                        Debug.Log(obj.name +"资源打包成功");                    }                     else                     {                        Debug.Log(obj.name +"资源打包失败");                    }                }                //刷新编辑器                AssetDatabase.Refresh ();               }            }
0 0
原创粉丝点击