webzepetoku commited on
Commit
bbc7da8
·
verified ·
1 Parent(s): 3adf4d1

Update UnityProject/Assets/Editor/TestBuilder.cs

Browse files
UnityProject/Assets/Editor/TestBuilder.cs CHANGED
@@ -15,9 +15,8 @@ public class TestBuilder
15
  {
16
  try
17
  {
18
- Debug.Log("🛠️ [SYSTEM] Membuat Struktur Folder Paket Lengkap...");
19
-
20
- // Bersihkan dan buat folder struktur
21
  if (Directory.Exists(FINAL_EXPORT_DIR)) Directory.Delete(FINAL_EXPORT_DIR, true);
22
  Directory.CreateDirectory(FINAL_EXPORT_DIR);
23
  Directory.CreateDirectory(BUNDLE_SUBDIR);
@@ -26,29 +25,29 @@ public class TestBuilder
26
 
27
  foreach (string path in prefabPaths)
28
  {
29
- // 1. Optimasi & Embed Mesh
30
  GameObject go = PrefabUtility.LoadPrefabContents(path);
31
  if (go != null)
32
  {
 
33
  SimplifyAndEmbed(go, path);
34
 
35
- // 2. Simpan Prefab Baru ke Root Folder Ekspor
36
  string prefabName = Path.GetFileName(path);
37
  string exportPath = Path.Combine(FINAL_EXPORT_DIR, prefabName);
38
  PrefabUtility.SaveAsPrefabAsset(go, exportPath);
39
  PrefabUtility.UnloadPrefabContents(go);
40
 
41
- // 3. Salin File Pendukung (Shader, Texture, Meta)
42
  CopyDependencies(path);
43
  }
44
  }
45
 
46
  AssetDatabase.Refresh();
47
 
48
- // 4. Build AssetBundles untuk SEMUA PLATFORM
49
  BuildAllPlatforms();
50
 
51
- Debug.Log("🚀 [UNITY] Struktur folder selesai dibuat.");
52
  EditorApplication.Exit(0);
53
  }
54
  catch (Exception e)
@@ -69,7 +68,7 @@ public class TestBuilder
69
  {
70
  var simplifier = new MeshSimplifier();
71
  simplifier.Initialize(sourceMesh);
72
- simplifier.SimplifyMesh(0.1f); // Sesuaikan agresivitas
73
  Mesh newMesh = simplifier.ToMesh();
74
  newMesh.name = sourceMesh.name + "_Internal";
75
  AssetDatabase.AddObjectToAsset(newMesh, prefabPath);
@@ -81,23 +80,19 @@ public class TestBuilder
81
 
82
  static void CopyDependencies(string prefabPath)
83
  {
84
- // Ambil semua file di folder yang sama (PNG, Shader, Meta)
85
  string sourceDir = Path.GetDirectoryName(prefabPath);
86
  string[] files = Directory.GetFiles(sourceDir, "*.*");
87
-
88
  foreach (string file in files)
89
  {
90
  string fileName = Path.GetFileName(file);
91
- // Jangan salin ulang prefab asli, kita pakai yang sudah di-optimize
92
  if (fileName.EndsWith(".prefab") || fileName.EndsWith(".prefab.meta")) continue;
93
-
94
- string destPath = Path.Combine(FINAL_EXPORT_DIR, fileName);
95
- File.Copy(file, destPath, true);
96
  }
97
  }
98
 
99
  static void BuildAllPlatforms()
100
  {
 
101
  BuildTarget[] targets = {
102
  BuildTarget.Android,
103
  BuildTarget.iOS,
@@ -109,16 +104,13 @@ public class TestBuilder
109
 
110
  foreach (var t in targets)
111
  {
112
- // Buat sub-folder per platform (Android, iOS, dll)
113
- string platformPath = Path.Combine(BUNDLE_SUBDIR, t.ToString());
114
- Directory.CreateDirectory(platformPath);
115
-
116
  AssetBundleBuild[] buildMap = new AssetBundleBuild[1];
117
- buildMap[0].assetBundleName = t.ToString(); // Nama biner sesuai platform
118
  buildMap[0].assetNames = AssetDatabase.FindAssets("t:Prefab", new[] { FINAL_EXPORT_DIR })
119
  .Select(guid => AssetDatabase.GUIDToAssetPath(guid)).ToArray();
120
 
121
- BuildPipeline.BuildAssetBundles(platformPath, buildMap,
 
122
  BuildAssetBundleOptions.ForceRebuildAssetBundle | BuildAssetBundleOptions.ChunkBasedCompression,
123
  t);
124
  }
 
15
  {
16
  try
17
  {
18
+ Debug.Log("🛠️ [SYSTEM] Memulai Pembuatan Paket Terstruktur...");
19
+
 
20
  if (Directory.Exists(FINAL_EXPORT_DIR)) Directory.Delete(FINAL_EXPORT_DIR, true);
21
  Directory.CreateDirectory(FINAL_EXPORT_DIR);
22
  Directory.CreateDirectory(BUNDLE_SUBDIR);
 
25
 
26
  foreach (string path in prefabPaths)
27
  {
 
28
  GameObject go = PrefabUtility.LoadPrefabContents(path);
29
  if (go != null)
30
  {
31
+ // 1. Optimasi Mesh (Agar m_DataSize kecil)
32
  SimplifyAndEmbed(go, path);
33
 
34
+ // 2. Simpan Prefab ke Root FinalPackage
35
  string prefabName = Path.GetFileName(path);
36
  string exportPath = Path.Combine(FINAL_EXPORT_DIR, prefabName);
37
  PrefabUtility.SaveAsPrefabAsset(go, exportPath);
38
  PrefabUtility.UnloadPrefabContents(go);
39
 
40
+ // 3. Salin file pendukung (PNG, Shader, Meta)
41
  CopyDependencies(path);
42
  }
43
  }
44
 
45
  AssetDatabase.Refresh();
46
 
47
+ // 4. Build AssetBundles untuk Semua Platform
48
  BuildAllPlatforms();
49
 
50
+ Debug.Log("✅ [UNITY] Struktur folder FinalPackage selesai.");
51
  EditorApplication.Exit(0);
52
  }
53
  catch (Exception e)
 
68
  {
69
  var simplifier = new MeshSimplifier();
70
  simplifier.Initialize(sourceMesh);
71
+ simplifier.SimplifyMesh(0.1f);
72
  Mesh newMesh = simplifier.ToMesh();
73
  newMesh.name = sourceMesh.name + "_Internal";
74
  AssetDatabase.AddObjectToAsset(newMesh, prefabPath);
 
80
 
81
  static void CopyDependencies(string prefabPath)
82
  {
 
83
  string sourceDir = Path.GetDirectoryName(prefabPath);
84
  string[] files = Directory.GetFiles(sourceDir, "*.*");
 
85
  foreach (string file in files)
86
  {
87
  string fileName = Path.GetFileName(file);
 
88
  if (fileName.EndsWith(".prefab") || fileName.EndsWith(".prefab.meta")) continue;
89
+ File.Copy(file, Path.Combine(FINAL_EXPORT_DIR, fileName), true);
 
 
90
  }
91
  }
92
 
93
  static void BuildAllPlatforms()
94
  {
95
+ // Daftar platform sesuai struktur 'sesudah'
96
  BuildTarget[] targets = {
97
  BuildTarget.Android,
98
  BuildTarget.iOS,
 
104
 
105
  foreach (var t in targets)
106
  {
 
 
 
 
107
  AssetBundleBuild[] buildMap = new AssetBundleBuild[1];
108
+ buildMap[0].assetBundleName = t.ToString(); // Nama file biner (e.g. Android)
109
  buildMap[0].assetNames = AssetDatabase.FindAssets("t:Prefab", new[] { FINAL_EXPORT_DIR })
110
  .Select(guid => AssetDatabase.GUIDToAssetPath(guid)).ToArray();
111
 
112
+ // Build langsung ke dalam folder assetbundles/
113
+ BuildPipeline.BuildAssetBundles(BUNDLE_SUBDIR, buildMap,
114
  BuildAssetBundleOptions.ForceRebuildAssetBundle | BuildAssetBundleOptions.ChunkBasedCompression,
115
  t);
116
  }