using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
#if UNITY_EDITOR
public class AssetBundleBuilder
{
[MenuItem("Tools/Build AssetBundle")]
public static void Build()
{
string outputPath = "Assets/Bundles";
BuildPipeline.BuildAssetBundles(outputPath, BuildAssetBundleOptions.None, BuildTarget.StandaloneWindows);
}
}
#endif
1. 빌드용 코드 작성
public class AssetBundleLoader : MonoBehaviour
{
AssetBundle bundle = null;
void Start()
{
StartCoroutine(GetAssetBundle(() =>
{
Debug.Log(bundle);
var obj = bundle.LoadAsset("Button") as GameObject;
Instantiate(obj);
}));
}
IEnumerator GetAssetBundle(Action callback)
{
var path = System.IO.Path.Combine(Application.dataPath, "Bundles/button");
UnityWebRequest www = UnityWebRequestAssetBundle.GetAssetBundle(path);
yield return www.SendWebRequest();
if (www.result != UnityWebRequest.Result.Success)
{
Debug.Log(www.error);
}
else
{
bundle = DownloadHandlerAssetBundle.GetContent(www);
}
callback?.Invoke();
}
}
5. 로드용 코드 작성
'Unity' 카테고리의 다른 글
[유니티] sRGB, Linear, Gamma (0) | 2022.07.20 |
---|---|
[Unity] 병목 프로파일링 (그래픽스 최적화 스타트업) (0) | 2022.07.17 |
[Unity] Platform Effector 2D (0) | 2022.07.12 |
[Unity] 유니티의 뷰 프러스텀, 오클루전 컬링 (0) | 2022.06.21 |
[Unity] 포스트 프로세싱? (0) | 2022.06.11 |