1. 程式人生 > 實用技巧 >U3d:assetsBounld 打包解包

U3d:assetsBounld 打包解包

//打包 
static void AssetsBuild()
    {
        Object[] selection = Selection.GetFiltered(typeof(Object), SelectionMode.DeepAssets);
        if (selection.Length <= 0)
            return;
        string path = EditorUtility.SaveFilePanel("另存為", Application.streamingAssetsPath + "/data", selection[0].name, "
dat"); if (path.Length != 0) { BuildPipeline.BuildAssetBundle(Selection.activeObject, selection, path, BuildAssetBundleOptions.CollectDependencies | BuildAssetBundleOptions.CompleteAssets, BuildTarget.StandaloneWindows); AssetDatabase.Refresh(); } }
//解包 public static IEnumerator LoadAssetsbounld(string path, string name) { string locoPath = path + "/"+name + ".dat"; AssetBundleCreateRequest request = AssetBundle.LoadFromMemoryAsync(File.ReadAllBytes(locoPath)); //非同步的方式 yield return request; //等載入完成之後在進行 AssetBundle ab = request.assetBundle;
//使用資源 GameObject gameObj = ab.LoadAsset<GameObject>(name); GameObject GO_MainType = Instantiate(gameObj); request.assetBundle.Unload(false); yield return null; }