반응형
코드 작성
using UnityEngine;
using UnityEditor;
using System.IO;
public class AssetBundleBuilder : MonoBehaviour
{
[MenuItem("Tools/Build AssetBundles")]
static void BuildAllAssetBundles()
{
string assetBundleDirectory = "Assets/AssetBundles"; // Asset Bundle을 저장할 디렉토리
if (!Directory.Exists(assetBundleDirectory))
{
Directory.CreateDirectory(assetBundleDirectory);
}
// Asset Bundle 빌드
BuildPipeline.BuildAssetBundles(assetBundleDirectory, BuildAssetBundleOptions.None, EditorUserBuildSettings.activeBuildTarget);
Debug.Log("Asset Bundles are built and saved in: " + assetBundleDirectory);
}
}
빌드 후 파이어베이스 스토리지 자동 업로드
using UnityEngine;
using Firebase.Storage;
using System;
using System.IO;
public class FirebaseUploader : MonoBehaviour
{
public string buildFilePath = "Your/Build/File/Path";
public string firebaseStoragePath = "Path/In/Firebase/Storage";
void Start()
{
UploadBuildToFirebase();
}
void UploadBuildToFirebase()
{
FirebaseStorage storage = FirebaseStorage.DefaultInstance;
StorageReference storageRef = storage.GetReferenceFromUrl("Your Firebase Storage URL");
// Load the build file
byte[] fileBytes = File.ReadAllBytes(buildFilePath);
// Upload the build file to Firebase Storage
storageRef.Child(firebaseStoragePath).PutBytesAsync(fileBytes).ContinueWith(task =>
{
if (task.IsFaulted || task.IsCanceled)
{
Debug.LogError("Failed to upload build to Firebase Storage: " + task.Exception);
}
else
{
Debug.Log("Build uploaded successfully to Firebase Storage.");
}
});
}
}
반응형