Unity3D动态加载FBX文件

来源:互联网 发布:vscode git插件 编辑:程序博客网 时间:2024/05/17 09:08

方法1:1.将模型拖动到场景中 ,调整好位置。(制作prefab需要)。

2.新建Resources(如果工程中有的话 就不用新建了,Resource.Load调用的就是该文件夹下的资源),在该文件夹下建一个prefab,将上面的模型拖动到这个prefab上。

3.删除场景中的该物体模型。

4.编写脚本,把它仍随便一个GameObject。

代码如下:

[csharp] view plaincopyprint?
  1. using UnityEngine;  
  2.   
  3. using System.Collections;  
  4.   
  5. public class LoadFBX : MonoBehaviour {  
  6.   
  7. // Use this for initialization  
  8.   
  9. void Start () {  
  10.   
  11. GameObject gFbx=(GameObject)Instantiate( Resources.Load("che"));  
  12.   
  13. }  
  14.   
  15. // Update is called once per frame  
  16.   
  17. void Update () {  
  18.   
  19. }  
  20.   
  21. }  


 

方法2:

1.按方法1 制作prefab 注意调整好位置。

2.然后使用AssetBundle导出包选项 create single AssetBundle(这之前需要在工程文件夹中新建一个叫做“Dynamic_Asset”的文件夹)。

3.这时可以看到导出的.AssetBundle文件了。

4.编写代码如下:

[csharp] view plaincopyprint?
  1. public string url;  
  2.   
  3. void Start () {  
  4.   
  5. string Scname = "scene1_part2.assetbundle";  
  6.   
  7. url = "file://F:/EZGUI/Dynamic_Asset/";  
  8.   
  9. StartCoroutine(DLAsset(url,Scname));  
  10.   
  11. }  
  12.   
  13. void Update () {  
  14.   
  15. }  
  16.   
  17. public IEnumerator DLAsset (string url,string Scname) {  
  18.   
  19. WWW www = new WWW(url+Scname);  
  20.   
  21. yield return www;  
  22.   
  23. GameObject GO = (GameObject)Instantiate;  
  24.   
  25. }  
0 0
原创粉丝点击