[unity3d]加载模型资源
2013-10-29 23:47
260 查看
将模型资源加载到场景中显示
1.从本地加载
![](https://img-blog.csdn.net/20131029234458578?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvZGluZ3hpYW93ZWkyMDEz/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center)
2.从服务器端加载
这里我已经将资源模型加载到百度云盘上,然后获取一个url下载地址:(直接模型就是ok.unity3d格式的)
中间是搭建的sqlserver服务器和asp.net服务器:
同样的效果:
![](https://img-blog.csdn.net/20131030103420218?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvZGluZ3hpYW93ZWkyMDEz/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center)
直接从网上获取资源:
1.从本地加载
void OnGUI() { if (GUILayout.Button("click")) { StartCoroutine(getmodel()); } } IEnumerator getmodel() { WWW w = new WWW("file://"+Application.dataPath+"/ok.unity3d"); yield return w; Instantiate(w.assetBundle.mainAsset); }
2.从服务器端加载
这里我已经将资源模型加载到百度云盘上,然后获取一个url下载地址:(直接模型就是ok.unity3d格式的)
中间是搭建的sqlserver服务器和asp.net服务器:
using UnityEngine; using System.Collections; using System.Text; public class NewBehaviourScript : MonoBehaviour { string s; private GameObject obj; private WWW www; private string url = @"http://192.168.1.6/plusFile/Test.aspx"; private string url1 = @"http://114.92.247.6/xiaowei/ok.unity3d"; void Start() { } private bool isCompleted = false; void Update() { if (www == null) { return; } if (!isCompleted && www.isDone) { print("Download completed"); isCompleted = true; print("6"); obj = GameObject.Instantiate(www.assetBundle.mainAsset) as GameObject; obj.transform.position = new Vector3(0, 1, 20); print("7"); } } void OnGUI() { if (GUI.Button(new Rect(20, 20, 100, 40), "加载")) { StartCoroutine(getHtml(url)); print("2"); } } IEnumerator getHtml(string url) { print("3"); WWW web = new WWW(url); yield return web; print("1"); //Encoding e1 = new ASCIIEncoding(); //this.s = e1.GetString(web.bytes); //print("web" + e1.GetString(web.bytes)); this.s = web.text; StartCoroutine(getModel(s)); } IEnumerator getModel(string str) { print("s:" + str); this.www = new WWW(str); yield return www; print("5"); } }
同样的效果:
直接从网上获取资源:
using UnityEngine; using System.Collections; public class NewBehaviourScript : MonoBehaviour { string url1 = @"http://114.92.247.6/xiaowei/ok.unity3d"; GameObject obj; void Start () { } void Update () { } void OnGUI() { if (GUI.Button(new Rect(20, 20, 100, 40), "加载")) { StartCoroutine(getHtml(this.url1)); print("2"); } } IEnumerator getHtml(string url) { print("3"); WWW web = new WWW(url); yield return web; obj = Instantiate(web.assetBundle.mainAsset) as GameObject; obj.transform.position = new Vector3(0,1,20); print("1"); } }
相关文章推荐
- unity3d远程加载资源模型到本地并加载(一)打包资源
- unity3d远程加载资源模型到本地并加载(二)第一次加载资源后写到本地后从本地加载。
- [unity3d]加载模型资源
- Unity3D实现动态加载游戏资源(转)
- Unity3D Resources Load 资源加载测试
- [Unity3D]BuildPipeline.PushAssetDependencies 打包依赖包,优化UI Prefab的资源引用加载
- Unity3D-动态加载资源
- Unity3D中实现动态加载Resources目录外的资源
- Unity3d 动态加载fbx模型文件
- 在Unity3D的网络游戏中实现资源动态加载
- flare 3D之加载模型资源见解
- Unity3D AssetBundles 动态加载游戏资源
- 在Unity3D的网络游戏中实现资源动态加载
- Unity3D之AssetBundle资源加载封装
- Unity3d热更新全书-资源加载(一):从AssetBundle说起
- Unity3D基础学习之AssetBundle 资源包创建与加载
- Unity3D加载火炬之光资源
- Unity教程之-解析OBJ模型并将其加载到Unity3d场景中
- Unity3D技术之运行时加载资源浅析
- Unity3D动态加载外部资源