Spaces:
Sleeping
Sleeping
Update UnityProject/Assets/Editor/TestBuilder.cs
Browse files1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071using UnityEngine;using UnityEditor;using System.IO;using UnityEditor.Formats.Fbx.Exporter;using Zepeto.Build;public class TestBuilder{static readonly string RAW_PATH = "Assets/InputRaw";static readonly string FBX_TEMP = "Assets/InputRaw/temp_model.fbx";static readonly string OUTPUT_DIR = "Output";// FASE 1: EXPORT (Membuka Prefab menjadi FBX)public static void ExportPrefabToFBX(){Debug.Log("[BRIDGE] Memulai Export Prefab ke FBX...");// Cari prefab apapun di folder InputRaw (misal DG_1.prefab)string[] guids = AssetDatabase.FindAssets("t:Prefab", new[] { RAW_PATH });if (guids.Length == 0) {Debug.LogError("[BRIDGE] Tidak ada prefab di InputRaw!");EditorApplication.Exit(1);return;}string prefabPath = AssetDatabase.GUIDToAssetPath(guids[0]);GameObject prefabAsset = AssetDatabase.LoadAssetAtPath<GameObject>(prefabPath);// Ekspor ke FBX agar bisa diproses BlenderModelExporter.ExportObject(FBX_TEMP, prefabAsset);Debug.Log($"[BRIDGE] Export Selesai: {FBX_TEMP}");EditorApplication.Exit(0);}// FASE 2: REPACK (Membungkus kembali ke .zepeto)public static void ManualConvert(){Debug.Log("[BRIDGE] Memulai Repack .zepeto...");// 1. Load FBX yang sudah dikecilkan BlenderGameObject optimizedMesh = AssetDatabase.LoadAssetAtPath<GameObject>(FBX_TEMP);if (optimizedMesh == null) {Debug.LogError("[BRIDGE] FBX hasil optimasi tidak ditemukan!");EditorApplication.Exit(1);return;}// 2. Buat Instance di SceneGameObject instance = (GameObject)PrefabUtility.InstantiatePrefab(optimizedMesh);instance.name = "Optimized_Item";// 3. Tentukan Path Outputif (!Directory.Exists(OUTPUT_DIR)) Directory.CreateDirectory(OUTPUT_DIR);string finalPath = Path.Combine(Directory.GetCurrentDirectory(), OUTPUT_DIR, "final_item.zepeto");// 4. Panggil Pipeline ZEPETO (Sesuaikan dengan versi SDK Anda)// Jika menggunakan ZEPETO Studio API:bool success = ZepetoBuildPipeline.BuildSinglePackage(instance, finalPath);// CleanupGameObject.DestroyImmediate(instance);if (success) {Debug.Log($"[BRIDGE] Repack Berhasil: {finalPath}");EditorApplication.Exit(0);} else {Debug.LogError("[BRIDGE] Repack Gagal di ZepetoBuildPipeline.");EditorApplication.Exit(1);}}1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374using UnityEngine;using UnityEditor;using System.IO;public class TestBuilder{// Path input dan outputstatic readonly string RAW_PATH = "Assets/InputRaw";static readonly string OUTPUT_DIR = "Assets/Output";// KITA GANTI NAMA FUNGSI JADI "ManualConvert" BIAR SAMA DENGAN YG DIPANGGIL PYTHONpublic static void ManualConvert(){Debug.Log("๐ [NATIVE] Memulai Build AssetBundle...");try{// 1. Refresh biar file prefab terbacaAssetDatabase.Refresh();// 2. Cari Prefab di folder InputRawstring[] guids = AssetDatabase.FindAssets("t:Prefab", new[] { RAW_PATH });if (guids.Length == 0){Debug.LogError("โ Error: Tidak ada Prefab di Assets/InputRaw!");EditorApplication.Exit(1);return;}// Ambil path file prefabnyastring prefabPath = AssetDatabase.GUIDToAssetPath(guids[0]);Debug.Log($"๐ Menggunakan Prefab: {prefabPath}");// 3. SET ASSETBUNDLE NAME// Ini triknya: Kita paksa Unity membungkus prefab ini jadi file bernama "repacked_item.zepeto"AssetImporter importer = AssetImporter.GetAtPath(prefabPath);if (importer == null){Debug.LogError("โ Gagal load AssetImporter.");EditorApplication.Exit(1);}// Ubah ekstensi jadi .zepeto biar server Zepeto mau terimaimporter.assetBundleName = "repacked_item.zepeto";// 4. SIAPKAN FOLDER OUTPUTif (!Directory.Exists(OUTPUT_DIR)) Directory.CreateDirectory(OUTPUT_DIR);// 5. BUILD (MURNI UNITY - TANPA ZEPETO SDK)// Kita pakai target Windows64 karena paling stabil di Docker LinuxBuildPipeline.BuildAssetBundles(OUTPUT_DIR,BuildAssetBundleOptions.ForceRebuildAssetBundle,BuildTarget.StandaloneWindows64);// 6. VERIFIKASIstring expectedFile = Path.Combine(OUTPUT_DIR, "repacked_item.zepeto");if (File.Exists(expectedFile)){Debug.Log($"โ SUKSES! File output: {expectedFile}");EditorApplication.Exit(0);}else{Debug.LogError("โ Gagal! File output tidak terbentuk.");EditorApplication.Exit(1);}}catch (System.Exception e){Debug.LogError($"โ CRITICAL ERROR: {e.Message}");EditorApplication.Exit(1);}}
UnityProject/Assets/Editor/TestBuilder.cs+55-52