Spaces:
Sleeping
Sleeping
Update UnityProject/Assets/Editor/TestBuilder.cs
Browse files7 unmodified lines89101112131411 unmodified lines26272829303132333435363738394041428 unmodified lines515253545556575859606162636465662 unmodified lines6970717273745 unmodified lines80818283848586878889909192932 unmodified lines969798991001011021031041057 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"))8 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,5 unmodified linesDebug.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";2 unmodified linesFile.Delete(repackFile);}ZipFile.CreateFromDirectory(MAIN_FOLDER, repackFile);Debug.Log($"✅ [UNITY] Repacking selesai: {repackFile}");Debug.Log("✅ [UNITY] Build binary selesai.");EditorApplication.Exit(0);}catch (System.Exception e) {7 unmodified lines891011121314151611 unmodified lines28293031323334353637383940414243444546478 unmodified lines5657585960616263646566676869707172732 unmodified lines767778798081825 unmodified lines8889909192939495969798991001011022 unmodified lines1051061071081091101111121131141157 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 ADAif (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){if (path.EndsWith(".prefab"))8 unmodified lines}}// --- PEMBERSIHAN RAM AWAL ---EditorUtility.UnloadUnusedAssetsImmediate();GC.Collect();// 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/BuildPipeline.BuildAssetBundles(ASSETBUNDLE_DIR,BuildAssetBundleOptions.ForceRebuildAssetBundle,5 unmodified linesDebug.LogWarning($"⚠️ [UNITY] Gagal build untuk {platformName}. Error: {ex.Message}");}// --- PEMBERSIHAN RAM SETIAP SELESAI SATU PLATFORM (Mencegah Exit Code 137) ---EditorUtility.UnloadUnusedAssetsImmediate();GC.Collect();}// 5. PROSES REPACKING FOLDER UTAMA MENJADI .ZEPETO DENGAN TIMESTAMP UNIKDebug.Log($"📦 [UNITY] Memulai proses repacking Folder Utama ({MAIN_FOLDER}) menjadi .zepeto...");// PEMBUATAN NAMA FILE UNIK DENGAN TIMESTAMPstring timestamp = DateTime.Now.ToString("yyyyMMdd_HHmmss");string repackFile = $"Assets/Repacked_{timestamp}.zepeto";2 unmodified linesFile.Delete(repackFile);}// Yang di-pack adalah folder utama (isinya: prefab, assetbundles, dsb)ZipFile.CreateFromDirectory(MAIN_FOLDER, repackFile);Debug.Log($"✅ [UNITY] Repacking selesai: {repackFile}");Debug.Log("✅ [UNITY] Seluruh rangkaian build dan repacking selesai.");EditorApplication.Exit(0);}catch (System.Exception e) {
UnityProject/Assets/Editor/TestBuilder.cs+15-5