方法1(已测试过)
1 将模型拖动到场景中 ,调整好位置。(制作prefab需要)
2 新建Resources(如果工程中有的话 就不用新建了,Resource.Load调用的就是该文件夹下的资源),在该文件夹下建一个prefab,将上面的模型拖动到这个prefab上
3 删除场景中的该物体模型
4 编写脚本,把它仍随便一个GameObject
1 将模型拖动到场景中 ,调整好位置。(制作prefab需要)
2 新建Resources(如果工程中有的话 就不用新建了,Resource.Load调用的就是该文件夹下的资源),在该文件夹下建一个prefab,将上面的模型拖动到这个prefab上
3 删除场景中的该物体模型
4 编写脚本,把它仍随便一个GameObject
主要代码如下:
using UnityEngine; using System.Collections; public class LoadFBX : MonoBehaviour { // Use this for initialization void Start () { GameObject gFbx=(GameObject)Instantiate( Resources.Load("che")); } // Update is called once per frame void Update () { } }
方法2:(没测试过,应该可以,因为之前能成功加载GameObject对象)
1 按方法1 制作prefab 注意调整好位置
2 然后使用AssetBundle导出包选项 create single AssetBundle(这之前需要在工程文件夹中新建一个叫做“Dynamic_Asset”的文件夹)
3 这时可以看到导出的.AssetBundle文件了
4 编写代码
如下:
public string url; void Start () { string Scname = "scene1_part2.assetbundle"; url = "file://F:/EZGUI/Dynamic_Asset/"; StartCoroutine(DLAsset(url,Scname)); } void Update () { } public IEnumerator DLAsset (string url,string Scname) { WWW www = new WWW(url+Scname); yield return www; GameObject GO = (GameObject)Instantiate(www.assetBundle.mainAsset); }
如何动态加载模型-0
如何动态加载模型 1,加载封装好的内部文件。 var aaa : Material;//空材质
var bbb : GameObject;//要绑定材质的模型
function Start() { aaa.mainTexture = Resources.Load("你的资源名,例如“pic1”不需要文件扩展名"); bbb.renderer.material = aaa; } 2,加载磁盘文件 var bbb : GameObject; function Start () { var www = new WWW ("file://D:\\pic1.jpg"这里也可以是网络图片地址); yield www; bbb.renderer.material.SetTexture("_MainTex", www.texture); }
转载于:https://blog.51cto.com/983836259/1565729