Spaces:
Sleeping
Sleeping
Update UnityProject/Assets/Editor/TestBuilder.cs
Browse files7 unmodified lines891011121314151611 unmodified lines28293031323334353637383940414243444546474849506 unmodified lines57585960616263646566676869702 unmodified lines73747576777879802 unmodified lines8384858687888990919293949596971 unmodified line991001011021031041051068 unmodified lines1151161171181191201217 unmodified linespublic class TestBuilder{// Folder Utama (Akan dipack seluruh isinya)static readonly string MAIN_FOLDER = "Assets/InputRaw";// Sub-folder untuk binary OS (Berada di dalam Folder Utama)static readonly string ASSETBUNDLE_DIR = "Assets/InputRaw/assetbundles";public static void ManualConvert()11 unmodified lines{AssetDatabase.Refresh();// 1. BERSIHKAN SUB-FOLDER ASSETBUNDLES LAMA JIKA ADA (Agar binary OS fresh sesuai modul saat ini)if (Directory.Exists(ASSETBUNDLE_DIR)){Directory.Delete(ASSETBUNDLE_DIR, true);}Directory.CreateDirectory(ASSETBUNDLE_DIR);// 2. AMBIL SEMUA ASET DI FOLDER UTAMA (Kecuali folder assetbundles)string[] allAssets = Directory.GetFiles(MAIN_FOLDER, "*.*", SearchOption.AllDirectories).Where(s => !s.EndsWith(".meta") && !s.Contains("assetbundles")).ToArray();Debug.Log("⚙️ [UNITY] Memulai proses simplifikasi di folder utama...");// 3. PROSES SIMPLIFY PREFABforeach (string path in allAssets){// Rampingkan poligon 50% HANYA untuk file Prefab di folder utamaif (path.EndsWith(".prefab")){GameObject go = PrefabUtility.LoadPrefabContents(path);6 unmodified lines}}// 4. BUILD UNTUK SETIAP PLATFORM KE SUB-FOLDER ASSETBUNDLESforeach (BuildTarget t in targets){string platformName = t.ToString();foreach (string path in allAssets){// Beri label bundle sesuai nama platform (agar binary masuk ke assetbundles)AssetImporter importer = AssetImporter.GetAtPath(path);if (importer != null) importer.assetBundleName = platformName;}2 unmodified linestry{// Binary dilempar ke dalam sub-folder assetbundles/// Hanya akan berhasil dan muncul jika modul OS-nya tersedia di Unity EditorBuildPipeline.BuildAssetBundles(ASSETBUNDLE_DIR,BuildAssetBundleOptions.ForceRebuildAssetBundle,2 unmodified lines}catch (System.Exception ex){Debug.LogWarning($"⚠️ [UNITY] Gagal build untuk {platformName}. Modul mungkin tidak tersedia. Error: {ex.Message}");}}// 5. PROSES REPACKING FOLDER UTAMA MENJADI .ZEPETODebug.Log($"📦 [UNITY] Memulai proses repacking Folder Utama ({MAIN_FOLDER}) menjadi .zepeto...");string timestamp = DateTime.Now.ToString("yyyyMMdd_HHmmss");// File .zepeto disimpan di luar folder utama (di root folder Assets) agar tidak me-looping saat di-zipstring repackFile = $"Assets/Repacked_{timestamp}.zepeto";if (File.Exists(repackFile))1 unmodified lineFile.Delete(repackFile);}// YANG DI-PACK ADALAH FOLDER UTAMA// Di dalam .zepeto akan berisi: prefabs, png, meta, mesh baru, dan sub-folder assetbundles yang berisi binary sesuai OSZipFile.CreateFromDirectory(MAIN_FOLDER, repackFile);Debug.Log($"✅ [UNITY] Repacking selesai: {repackFile}");8 unmodified linesstatic void SimplifyMeshInGameObject(GameObject go){// Simpan mesh baru tetap di dalam MAIN_FOLDER agar terikat dan ikut ter-packstring meshDir = "Assets/InputRaw/SimplifiedMeshes";if (!Directory.Exists(meshDir)) Directory.CreateDirectory(meshDir);7 unmodified lines89101112131411 unmodified lines262728293031323334353637383940414243446 unmodified lines515253545556575859606162636465662 unmodified lines6970717273742 unmodified lines7778798081828384858687888990919293941 unmodified line969798991001018 unmodified lines1101111121131141157 unmodified linespublic class TestBuilder{static readonly string MAIN_FOLDER = "Assets/InputRaw";static readonly string ASSETBUNDLE_DIR = "Assets/InputRaw/assetbundles";public static void ManualConvert()11 unmodified lines{AssetDatabase.Refresh();if (Directory.Exists(ASSETBUNDLE_DIR)){Directory.Delete(ASSETBUNDLE_DIR, true);}Directory.CreateDirectory(ASSETBUNDLE_DIR);string[] allAssets = Directory.GetFiles(MAIN_FOLDER, "*.*", SearchOption.AllDirectories).Where(s => !s.EndsWith(".meta") && !s.Contains("assetbundles")).ToArray();Debug.Log("⚙️ [UNITY] Memulai proses simplifikasi di folder utama...");foreach (string path in allAssets){if (path.EndsWith(".prefab")){GameObject go = PrefabUtility.LoadPrefabContents(path);6 unmodified lines}}// Bersihkan RAM setelah proses simplifikasi selesaiEditorUtility.UnloadUnusedAssetsImmediate();GC.Collect();foreach (BuildTarget t in targets){string platformName = t.ToString();foreach (string path in allAssets){AssetImporter importer = AssetImporter.GetAtPath(path);if (importer != null) importer.assetBundleName = platformName;}2 unmodified linestry{BuildPipeline.BuildAssetBundles(ASSETBUNDLE_DIR,BuildAssetBundleOptions.ForceRebuildAssetBundle,2 unmodified lines}catch (System.Exception ex){Debug.LogWarning($"⚠️ [UNITY] Gagal build untuk {platformName}. Error: {ex.Message}");}// --- PEMBERSIHAN RAM SETIAP SELESAI SATU PLATFORM ---Debug.Log($"🧹 [UNITY] Membersihkan RAM setelah build {platformName}...");EditorUtility.UnloadUnusedAssetsImmediate();GC.Collect();}Debug.Log($"📦 [UNITY] Memulai proses repacking Folder Utama menjadi .zepeto...");string timestamp = DateTime.Now.ToString("yyyyMMdd_HHmmss");string repackFile = $"Assets/Repacked_{timestamp}.zepeto";if (File.Exists(repackFile))1 unmodified lineFile.Delete(repackFile);}ZipFile.CreateFromDirectory(MAIN_FOLDER, repackFile);Debug.Log($"✅ [UNITY] Repacking selesai: {repackFile}");8 unmodified linesstatic void SimplifyMeshInGameObject(GameObject go){string meshDir = "Assets/InputRaw/SimplifiedMeshes";if (!Directory.Exists(meshDir)) Directory.CreateDirectory(meshDir);
UnityProject/Assets/Editor/TestBuilder.cs+11-17