溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

[unity3d]加載模型資源

發布時間:2020-09-03 23:20:25 來源:網絡 閱讀:271 作者:蓬萊仙羽 欄目:游戲開發

將模型資源加載到場景中顯示

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);             }

[unity3d]加載模型資源

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");     } }


同樣的效果:[unity3d]加載模型資源



直接從網上獲取資源:

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");              } } 



向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

un %d
AI

亚洲午夜精品一区二区_中文无码日韩欧免_久久香蕉精品视频_欧美主播一区二区三区美女