Unity-AssetBundle

什么是AssetBundle

可理解为类似压缩包、 .UnityPackage、 文件夹、容器。

用来存放unity中的各种资源文件(模型,材质,组合屋,音频剪辑、好像非代码)

官方链接

https://docs.unity3d.com/Manual/AssetBundlesIntro.html

https://docs.unity3d.com/Manual/AssetBundles-Workflow.html

using System.IO;
using UnityEditor;
using UnityEngine;

public class BuildAssetBundlesEditor
{
public static string assetBundlesPath = Application.dataPath + "/AssetBundles";

[MenuItem("Tools/BuildAssetBundles")]
public static void BuildAssetBundlesMenu()
{

if (Directory.Exists(assetBundlesPath) == false)
{
Directory.CreateDirectory(assetBundlesPath);
}
BuildPipeline.BuildAssetBundles(assetBundlesPath, BuildAssetBundleOptions.None, BuildTarget.StandaloneWindows);

AssetDatabase.Refresh();

}
}

制作一些Prefab,并写上assetBundle标签。

本地加载AssetBundle

using System;
using UnityEngine;

public class LoadAssetBundles : MonoBehaviour
{
    void Start()
    {
        string path = Application.dataPath + "/AssetBundles/model.model";
        AssetBundle assetBundle = AssetBundle.LoadFromFile(path);
        if (assetBundle)
        {
            GameObject cubePrefab = assetBundle.LoadAsset<GameObject>("Cube");
            Instantiate<GameObject>(cubePrefab);

            GameObject spherePrefab = assetBundle.LoadAsset<GameObject>("Sphere");
            Instantiate<GameObject>(spherePrefab);

            Debug.Log("加载成功");
        }
        else
        {
            Debug.LogError("加载AssetBundle失败");
        }
    }
}

 

AssetBundleBrower

https://github.com/Unity-Technologies/AssetBundles-Browser

引用官方的一个Github包,可以在unity中查看AssetBundle文件。

点赞
  1. luvox generic说道:
    Google Chrome Windows 10

    I'm also commenting to let you be aware of of the cool discovery my child encountered checking your blog. She came to understand a wide variety of details, most notably how it is like to have a marvelous coaching heart to get folks easily fully grasp a variety of complicated matters. You actually did more than my desires. I appreciate you for delivering such good, dependable, edifying and also cool guidance on that topic to Evelyn.

  2. buy risnia说道:
    Google Chrome Windows 10

    I enjoy you because of all your efforts on this site. Ellie enjoys doing internet research and it's easy to see why. All of us hear all concerning the compelling means you deliver good information by means of the blog and as well cause contribution from other people about this concept plus my daughter is being taught a lot. Enjoy the remaining portion of the new year. You're the one carrying out a first class job.

  3. venlor说道:
    Google Chrome Windows 10

    A lot of thanks for all your efforts on this site. Gloria loves engaging in investigation and it's easy to understand why. Almost all know all concerning the dynamic means you deliver helpful items on the web blog and as well encourage contribution from other people on that concern plus our daughter is actually discovering a lot. Have fun with the remaining portion of the new year. You're the one conducting a good job.

  4. kova说道:
    Firefox Windows 7

    kovaci baba geldi

  5. dolandirici说道:
    Opera Windows XP

    dolandirici thank you.

  6. dolandirici说道:
    Internet Explorer Windows XP

    dolandirici thank you.

  7. dolandirici说道:
    Opera Windows XP

    dolandirici thank you.

  8. emre说道:
    Internet Explorer Windows 7

    emremisin nesin paramı geri ver

发表评论

昵称和uid可以选填一个,填邮箱必填(留言回复后将会发邮件给你)
tips:输入uid可以快速获得你的昵称和头像

此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据

Title - Artist
0:00