1. 程式人生 > >unity3d遠端載入資源模型到本地並載入(一)打包資源

unity3d遠端載入資源模型到本地並載入(一)打包資源

由於模型放在遠端伺服器,fbx格式是不能載入的所以可以做成預設或是AssetBundle格式進行遠端載入。首先打包AssetBundle資源!在unity資原始檔夾下新建一下一個Editor資料夾 下方一個指令碼程式碼如下!(程式碼可複製!!!)
using UnityEngine;
using System.Collections;
using UnityEditor;

public class ExportAssetBundles : MonoBehaviour {
//在Unity編輯器中新增選單
[MenuItem(“AssetBundle/打包選中的檔案”)]
static void Export()
{
// 開啟儲存面板,獲得使用者選擇的路徑
string path = EditorUtility.SaveFilePanel(“儲存檔案”, “”, “模型”, “assetbundle”);

    if (path.Length != 0)
    {
        // 選擇的要儲存的物件  
        Object[] selection = Selection.GetFiltered(typeof(Object), SelectionMode.DeepAssets);            
        //打包 成AssetBundle
    BuildPipeline.BuildAssetBundle(Selection.activeObject, selection, path, BuildAssetBundleOptions.CollectDependencies | BuildAssetBundleOptions.CompleteAssets, BuildTarget.StandaloneWindows);
    }
}  

}
這裡寫圖片描述

這裡寫圖片描述

這裡寫圖片描述