Spaces:
Sleeping
Sleeping
Update UnityProject/Assets/Editor/TestBuilder.cs
Browse files1234562 unmodified lines910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091using UnityEngine;using UnityEditor;using System.IO;public class TestBuilder{2 unmodified linespublic static void ManualConvert(){Debug.Log("==================================================");Debug.Log("🚀 [NATIVE] UNITY ASSET BUNDLE BUILDER STARTED");Debug.Log("==================================================");try{AssetDatabase.Refresh();// 1. CEK ISI FOLDER FISIK (DEBUGGING)// Biar kita tahu file apa yang sebenarnya masukstring sysPath = Path.Combine(Directory.GetCurrentDirectory(), RAW_PATH);if(Directory.Exists(sysPath)) {string[] files = Directory.GetFiles(sysPath);Debug.Log($"📂 [DEBUG] Isi Folder InputRaw ({files.Length} files):");foreach(var f in files) Debug.Log($" - {Path.GetFileName(f)}");} else {Debug.LogError($"⌠[FATAL] Folder fisik tidak ditemukan: {sysPath}");}// 2. CARI ASSET (PREFAB / MODEL)// Kita cari t:Prefab (Prefab Unity) DAN t:Model (FBX/OBJ)string[] guids = AssetDatabase.FindAssets("t:Prefab t:Model", new[] { RAW_PATH });if (guids.Length == 0){Debug.LogError("⌠[FATAL] Unity tidak mendeteksi Prefab atau Model apapun di InputRaw!");EditorApplication.Exit(1);return;}string assetPath = AssetDatabase.GUIDToAssetPath(guids[0]);Debug.Log($"✅ [INFO] Target Aset Ditemukan: {assetPath}");// 3. SET BUNDLE NAMEAssetImporter importer = AssetImporter.GetAtPath(assetPath);if (importer == null) {Debug.LogError($"⌠[FATAL] Importer null untuk: {assetPath}. File mungkin korup.");EditorApplication.Exit(1);}importer.assetBundleName = "repacked_item.zepeto";Debug.Log($"🔹 [INFO] AssetBundle Name diset ke: {importer.assetBundleName}");// 4. BUILDif (!Directory.Exists(OUTPUT_DIR)) Directory.CreateDirectory(OUTPUT_DIR);Debug.Log("🔨 [INFO] Memulai BuildPipeline (StandaloneWindows64)...");var manifest = BuildPipeline.BuildAssetBundles(OUTPUT_DIR,BuildAssetBundleOptions.ForceRebuildAssetBundle,BuildTarget.StandaloneWindows64);if (manifest == null) {Debug.LogError("⌠[FATAL] BuildPipeline mengembalikan NULL. Build Gagal!");EditorApplication.Exit(1);}// 5. CEK HASIL// Unity kadang memberi nama output sesuai nama folder parent kalau single bundlestring expectedFile = Path.Combine(OUTPUT_DIR, "repacked_item.zepeto");if (File.Exists(expectedFile)) {Debug.Log($"🎉 [SUKSES] File output terbentuk: {expectedFile}");EditorApplication.Exit(0);} else {Debug.LogError("⌠[GAGAL] Build sukses tapi file output tidak ditemukan di path yang diharapkan!");// List isi output folder buat debugstring[] outFiles = Directory.GetFiles(OUTPUT_DIR);Debug.LogError($"📂 Isi Output Folder: {string.Join(", ", outFiles)}");EditorApplication.Exit(1);}}catch (System.Exception e){Debug.LogError($"💀 [EXCEPTION] Error Kritis: {e.Message}\n{e.StackTrace}");EditorApplication.Exit(1);}}}123456782 unmodified lines1112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133using UnityEngine;using UnityEditor;using System.IO;using System.Linq;using UnityMeshSimplifier; // Pastikan library ini ada di Assets agar tidak errorpublic class TestBuilder{2 unmodified linespublic static void ManualConvert(){// 1. DAFTAR TARGET PLATFORM SESUAI KEBUTUHAN GITHUBBuildTarget[] targets = {BuildTarget.Android,BuildTarget.iOS,BuildTarget.StandaloneLinux64,BuildTarget.StandaloneOSX,BuildTarget.StandaloneWindows64,BuildTarget.WebGL};Debug.Log("==================================================");Debug.Log("🚀 [NATIVE] UNITY MULTI-PLATFORM BUILDER & SIMPLIFIER STARTED");Debug.Log("==================================================");try{AssetDatabase.Refresh();// 2. AMBIL SEMUA ASET DARI FOLDER INPUTstring[] assets = Directory.GetFiles(RAW_PATH, "*.*", SearchOption.AllDirectories).Where(s => !s.EndsWith(".meta")).ToArray();if (assets.Length == 0){Debug.LogError("❌ [FATAL] Tidak ada aset ditemukan di Assets/InputRaw!");EditorApplication.Exit(1);return;}Debug.Log($"📂 [DEBUG] Memproses {assets.Length} file untuk dibundle.");// 3. PROSES SETIAP ASET: SIMPLIFY & LABELINGforeach (string path in assets){// Proses perampingan poligon untuk Prefab dan FBXif (path.EndsWith(".prefab") || path.EndsWith(".fbx") || path.EndsWith(".obj")){GameObject go = AssetDatabase.LoadAssetAtPath<GameObject>(path);if (go != null){Debug.Log($"✂️ [NATIVE] Merampingkan poligon aset: {Path.GetFileName(path)}");SimplifyMeshInGameObject(go);}}// Beri label bundle yang sama agar semua file masuk dalam satu .zepetoAssetImporter importer = AssetImporter.GetAtPath(path);if (importer != null){importer.assetBundleName = "repacked_item.zepeto";}}// 4. LOOPING BUILD UNTUK SETIAP PLATFORMforeach (BuildTarget t in targets){// Buat sub-folder khusus tiap platform (Android, iOS, dsb)string platformPath = Path.Combine(OUTPUT_DIR, t.ToString());if (!Directory.Exists(platformPath)) Directory.CreateDirectory(platformPath);Debug.Log($"🔨 [INFO] Memulai Build Pipeline untuk Platform: {t}");var manifest = BuildPipeline.BuildAssetBundles(platformPath,BuildAssetBundleOptions.ForceRebuildAssetBundle,t);if (manifest == null){Debug.LogWarning($"⚠️ [WARNING] Build platform {t} gagal. Pastikan modul terinstall.");}else{Debug.Log($"✅ [SUCCESS] Build platform {t} selesai di: {platformPath}");}}Debug.Log("==================================================");Debug.Log("🎉 [DONE] SEMUA PROSES SELESAI");Debug.Log("==================================================");EditorApplication.Exit(0);}catch (System.Exception e){Debug.LogError($"💀 [EXCEPTION] Error Kritis: {e.Message}\n{e.StackTrace}");EditorApplication.Exit(1);}}// FUNGSI UNTUK MERAMPINGKAN MESH (POLYGON REDUCTION)static void SimplifyMeshInGameObject(GameObject go){// Proses MeshFilter (Model Biasa)var meshFilters = go.GetComponentsInChildren<MeshFilter>();foreach (var mf in meshFilters){if (mf.sharedMesh != null){var meshSimplifier = new UnityMeshSimplifier.MeshSimplifier();meshSimplifier.Initialize(mf.sharedMesh);meshSimplifier.SimplifyMesh(0.5f); // Mengurangi poligon sebesar 50%mf.sharedMesh = meshSimplifier.ToMesh();}}// Proses SkinnedMeshRenderer (Model dengan Bone/Tulang)var skinnedMeshes = go.GetComponentsInChildren<SkinnedMeshRenderer>();foreach (var smr in skinnedMeshes){if (smr.sharedMesh != null){var meshSimplifier = new UnityMeshSimplifier.MeshSimplifier();meshSimplifier.Initialize(smr.sharedMesh);meshSimplifier.SimplifyMesh(0.5f); // Mengurangi poligon sebesar 50%smr.sharedMesh = meshSimplifier.ToMesh();}}}}
UnityProject/Assets/Editor/TestBuilder.cs+98-56