• 您的位置:首頁 > 新聞動態 > Unity3D

    Unity3d 動態加(jiā)載模型文件的方法

    2019/1/22      點擊:
    方法1(已測試過)
    1 將模(mó)型拖動(dòng)到場景中 ,調整好位置。(製作prefab需要(yào))
    2 新建Resources(如果工程中有的話 就不用新建了,Resource.Load調用的就是(shì)該文件夾下的資源),在該文件夾下建一個prefab,將上麵的模型拖動到這個prefab上
    3 刪除場景(jǐng)中的該物體模型

    4 編寫腳本,把它仍隨便一(yī)個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 () {  }
    }
    
    方法(fǎ)2:(沒測試過,應該可以,因為之前能(néng)成功加載GameObject對象)
    1 按方法(fǎ)1 製作prefab 注意調整好(hǎo)位(wèi)置
    2 然後使用(yòng)AssetBundle導(dǎo)出包選項(xiàng) create single AssetBundle(這之前需(xū)要在工程文件夾中新建一個叫(jiào)做“Dynamic_Asset”的文件夾)
    3 這時可(kě)以看到導出的.AssetBundle文(wén)件了
    4 編寫代碼
    public string url;
        void Start () {
            string Scname = "scene1_part2.assetbundle";
            url = "file://F://asd//Dynamic//";
            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);
        }
    网站地图 正能量网-传播正能量弘扬主旋律-免费正能量网站www正能量-免费正能量网站www正能量下载在线观看官网