公司项目的需求,需要动态的从本地导入FBX模型于是花了一天时间翻墙找到了一点可怜的资料。
1、这个可以动态加载OBJ模型,这个的话unity自带的有这个函数,当然OBJ模型是不带贴图的,对于一些场景是无法创建的。
http://download.csdn.net/detail/xiaomuzi0802/8316215
2、这个比较实用的,可以动态载入多种模型,特别是FBX模型,在创建场景时候很好用,不过这个是试用版本,贴图会有问题,如果要更好的还是推荐买正版
http://download.csdn.net/detail/xiaomuzi0802/8316229
3、我同时还想让它加载到场景之后自动做成prefabs,这样就节省了每次加载的时间,但是最终也没找到方法
因为总要用到using UnityEditor,这个编辑类只能在unity中使用,导出就报错,最终我也没找到解决办法
using UnityEngine; using System.Collections; #if UNITY_EDITOR using UnityEditor; #endif public class creatPrefabs : MonoBehaviour { //public GameObject kk; // Use this for initialization void Start () { GameObject kk = GameObject.Find ("Cube"); string localPath= "Assets/StreamingAssets/"+ kk.name + ".prefab"; Debug.Log (localPath); /*if (AssetDatabase.LoadAssetAtPath(localPath, GameObject) ){ if (PrefabUtility.DisplayDialog("Are you sure?", "The prefab already exists. Do you want to overwrite it?", "Yes", "No")) c/*ateNew(kk, localPath); } else {*/ createNew(kk, localPath); //} } static void createNew( GameObject obj,string localPath) { Object prefab = PrefabUtility.CreateEmptyPrefab(localPath); PrefabUtility.ReplacePrefab(obj, prefab); AssetDatabase.Refresh(); DestroyImmediate(obj); GameObject clone = PrefabUtility.InstantiatePrefab(prefab) as GameObject; } // Update is called once per frame void Update () { } }
希望有大神来指导
时间: 2024-10-12 20:34:43