เริ่มกันเลย
1. ให้ทำการสร้าง Project ขึ้นมาใหม่จากนั้นทำการ Import Models ที่เราต้องการทำ Asset Bundle
2. จากนั้นทำการสร้าง C# Script (AssetBundleCreator.cs)
3. ทำการสร้าง Folder Editor จากนั้นนำ AssetBundleCreator.cs ใส่เข้าไปครับ และทำการเพิ่ม Script
using System.IO;
using UnityEngine;
using UnityEditor;
public class AssetBundleCreator : MonoBehaviour
{
[MenuItem("Assets/Create Asset Bundle")]
private static void BuildAllAssetBundles()
{
string assetBundleDirectory = "Assets/AssetBundles";
if (!Directory.Exists(assetBundleDirectory))
{
Directory.CreateDirectory(assetBundleDirectory);
}
BuildPipeline.BuildAssetBundles(assetBundleDirectory, BuildAssetBundleOptions.None,
BuildTarget.StandaloneWindows);
}
}
7. จากนั้นทำการสร้าง C# Script (AssetBundleManager.cs) จากนั้นทำการเพิ่ม Code
using System.Collections;
using UnityEngine;
public class AssetBundleManager : MonoBehaviour
{
public string url;
private AssetBundle bundle;
private GameObject model;
// Load Asset Bundle From Server
IEnumerator Start()
{
WWW www = new WWW(url);
yield return www;
if (!string.IsNullOrEmpty(www.error))
{
Debug.LogError(www.error);
}
bundle = www.assetBundle;
Debug.Log("Load Success");
}
// Load Model
public void LoadAsset(string assetName)
{
if (!string.IsNullOrEmpty(assetName))
{
if (model != null)
{
Destroy(model.gameObject);
}
model = Instantiate(bundle.LoadAsset(assetName)) as GameObject;
}
}
}
NO GAME NO DREAM !!!