Spaces:
Sleeping
Sleeping
Update UnityProject/Assets/Editor/TestBuilder.cs
Browse files14 unmodified lines15161718192018192021222 unmodified lines2526272928293031323335343536373839414041424344454648474849515051525314 unmodified lines68697072717273745 unmodified lines808182848384878586879188939495899091929394959697985 unmodified lines10410510611211311411510711710810911011111212111311411511614 unmodified lines { try { Debug.Log("🛠️ [SYSTEM] Membuat Struktur Folder Paket Lengkap..."); // Bersihkan dan buat folder struktur Debug.Log("🛠️ [SYSTEM] Memulai Pembuatan Paket Terstruktur...");
if (Directory.Exists(FINAL_EXPORT_DIR)) Directory.Delete(FINAL_EXPORT_DIR, true); Directory.CreateDirectory(FINAL_EXPORT_DIR); Directory.CreateDirectory(BUNDLE_SUBDIR);2 unmodified lines
foreach (string path in prefabPaths) { // 1. Optimasi & Embed Mesh GameObject go = PrefabUtility.LoadPrefabContents(path); if (go != null) { // 1. Optimasi Mesh (Agar m_DataSize kecil) SimplifyAndEmbed(go, path); // 2. Simpan Prefab Baru ke Root Folder Ekspor // 2. Simpan Prefab ke Root FinalPackage string prefabName = Path.GetFileName(path); string exportPath = Path.Combine(FINAL_EXPORT_DIR, prefabName); PrefabUtility.SaveAsPrefabAsset(go, exportPath); PrefabUtility.UnloadPrefabContents(go);
// 3. Salin File Pendukung (Shader, Texture, Meta) // 3. Salin file pendukung (PNG, Shader, Meta) CopyDependencies(path); } }
AssetDatabase.Refresh();
// 4. Build AssetBundles untuk SEMUA PLATFORM // 4. Build AssetBundles untuk Semua Platform BuildAllPlatforms();
Debug.Log("🚀 [UNITY] Struktur folder selesai dibuat."); Debug.Log("✅ [UNITY] Struktur folder FinalPackage selesai."); EditorApplication.Exit(0); } catch (Exception e)14 unmodified lines { var simplifier = new MeshSimplifier(); simplifier.Initialize(sourceMesh); simplifier.SimplifyMesh(0.1f); // Sesuaikan agresivitas simplifier.SimplifyMesh(0.1f); Mesh newMesh = simplifier.ToMesh(); newMesh.name = sourceMesh.name + "_Internal"; AssetDatabase.AddObjectToAsset(newMesh, prefabPath);5 unmodified lines
static void CopyDependencies(string prefabPath) { // Ambil semua file di folder yang sama (PNG, Shader, Meta) string sourceDir = Path.GetDirectoryName(prefabPath); string[] files = Directory.GetFiles(sourceDir, "*.*");
foreach (string file in files) { string fileName = Path.GetFileName(file); // Jangan salin ulang prefab asli, kita pakai yang sudah di-optimize if (fileName.EndsWith(".prefab") || fileName.EndsWith(".prefab.meta")) continue; string destPath = Path.Combine(FINAL_EXPORT_DIR, fileName); File.Copy(file, destPath, true); File.Copy(file, Path.Combine(FINAL_EXPORT_DIR, fileName), true); } }
static void BuildAllPlatforms() { // Daftar platform sesuai struktur 'sesudah' BuildTarget[] targets = { BuildTarget.Android, BuildTarget.iOS, 5 unmodified lines
foreach (var t in targets) { // Buat sub-folder per platform (Android, iOS, dll) string platformPath = Path.Combine(BUNDLE_SUBDIR, t.ToString()); Directory.CreateDirectory(platformPath);
AssetBundleBuild[] buildMap = new AssetBundleBuild[1]; buildMap[0].assetBundleName = t.ToString(); // Nama biner sesuai platform buildMap[0].assetBundleName = t.ToString(); // Nama file biner (e.g. Android) buildMap[0].assetNames = AssetDatabase.FindAssets("t:Prefab", new[] { FINAL_EXPORT_DIR }) .Select(guid => AssetDatabase.GUIDToAssetPath(guid)).ToArray();
// Build langsung ke dalam folder assetbundles/ BuildPipeline.BuildAssetBundles(platformPath, buildMap, BuildPipeline.BuildAssetBundles(BUNDLE_SUBDIR, buildMap, BuildAssetBundleOptions.ForceRebuildAssetBundle | BuildAssetBundleOptions.ChunkBasedCompression, t); }UnityProject/Assets/Editor/TestBuilder.cs+13-21