Spaces:
webzepetoku
/
Sleeping

webzepetoku commited on
Commit
fa0c7b6
·
verified ·
1 Parent(s): 590eef4

Update UnityProject/Assets/Editor/TestBuilder.cs

Browse files
UnityProject/Assets/Editor/TestBuilder.cs CHANGED
@@ -15,8 +15,9 @@ public class TestBuilder
15
  {
16
  try
17
  {
18
- Debug.Log("🛠️ [UNITY] Memulai Export Struktur Lengkap...");
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);
@@ -32,14 +33,12 @@ public class TestBuilder
32
  GameObject go = PrefabUtility.LoadPrefabContents(path);
33
  if (go != null)
34
  {
35
- // 1. EMBED MESH KE PREFAB (Agar m_DataSize kecil)
36
  ProcessAndEmbed(go, exportPath);
37
-
38
- // 2. SIMPAN PREFAB KE FINAL PACKAGE
39
  PrefabUtility.SaveAsPrefabAsset(go, exportPath);
40
  PrefabUtility.UnloadPrefabContents(go);
41
 
42
- // 3. SALIN PNG, SHADER, META (Universal)
43
  CopyRelatedFiles(Path.GetDirectoryName(path), FINAL_EXPORT_DIR);
44
  }
45
  }
@@ -47,15 +46,15 @@ public class TestBuilder
47
  AssetDatabase.SaveAssets();
48
  AssetDatabase.Refresh();
49
 
50
- // 4. BUILD SEMUA BINARY PLATFORM
51
- BuildPlatforms();
52
 
53
- Debug.Log("✅ [UNITY] Build Berhasil Selesai.");
54
  EditorApplication.Exit(0);
55
  }
56
  catch (Exception e)
57
  {
58
- Debug.LogError($"💀 [ERROR] {e.Message}");
59
  EditorApplication.Exit(1);
60
  }
61
  }
@@ -72,11 +71,9 @@ public class TestBuilder
72
  {
73
  var simplifier = new MeshSimplifier();
74
  simplifier.Initialize(sourceMesh);
75
- simplifier.SimplifyMesh(0.05f); // Agresif 5% poligon
76
  Mesh newMesh = simplifier.ToMesh();
77
  newMesh.name = sourceMesh.name + "_Internal";
78
-
79
- // Tanam Mesh langsung ke dalam file Prefab
80
  AssetDatabase.AddObjectToAsset(newMesh, exportPath);
81
 
82
  if (ren is MeshRenderer) ren.GetComponent<MeshFilter>().sharedMesh = newMesh;
@@ -95,22 +92,36 @@ public class TestBuilder
95
  }
96
  }
97
 
98
- static void BuildPlatforms()
99
  {
100
- BuildTarget[] targets = {
101
- BuildTarget.Android, BuildTarget.iOS, BuildTarget.WebGL,
102
- BuildTarget.StandaloneWindows64, BuildTarget.StandaloneOSX, BuildTarget.StandaloneLinux64
 
 
 
 
 
103
  };
104
 
105
- foreach (var t in targets)
106
  {
 
 
 
 
 
 
 
107
  AssetBundleBuild[] buildMap = new AssetBundleBuild[1];
108
- buildMap[0].assetBundleName = t.ToString();
109
  buildMap[0].assetNames = AssetDatabase.FindAssets("t:Prefab", new[] { FINAL_EXPORT_DIR })
110
  .Select(guid => AssetDatabase.GUIDToAssetPath(guid)).ToArray();
111
 
112
  BuildPipeline.BuildAssetBundles(BUNDLE_SUBDIR, buildMap,
113
- BuildAssetBundleOptions.ForceRebuildAssetBundle | BuildAssetBundleOptions.ChunkBasedCompression, t);
 
 
114
  }
115
  }
116
  }
 
15
  {
16
  try
17
  {
18
+ Debug.Log("🛠️ [UNITY] Memulai Export Struktur...");
19
 
20
+ // Bersihkan folder
21
  if (Directory.Exists(FINAL_EXPORT_DIR)) Directory.Delete(FINAL_EXPORT_DIR, true);
22
  Directory.CreateDirectory(FINAL_EXPORT_DIR);
23
  Directory.CreateDirectory(BUNDLE_SUBDIR);
 
33
  GameObject go = PrefabUtility.LoadPrefabContents(path);
34
  if (go != null)
35
  {
36
+ // Tetap tanam Mesh ke Prefab (Embedding)
37
  ProcessAndEmbed(go, exportPath);
 
 
38
  PrefabUtility.SaveAsPrefabAsset(go, exportPath);
39
  PrefabUtility.UnloadPrefabContents(go);
40
 
41
+ // Salin PNG, Shader, Meta (Universal)
42
  CopyRelatedFiles(Path.GetDirectoryName(path), FINAL_EXPORT_DIR);
43
  }
44
  }
 
46
  AssetDatabase.SaveAssets();
47
  AssetDatabase.Refresh();
48
 
49
+ // BUILD HANYA PLATFORM YANG TERSEDIA DI IMAGE INI
50
+ BuildAvailablePlatforms();
51
 
52
+ Debug.Log("✅ [UNITY] Selesai. Apa yang tersedia sudah dibuat.");
53
  EditorApplication.Exit(0);
54
  }
55
  catch (Exception e)
56
  {
57
+ Debug.LogError($"💀 [FATAL] {e.Message}");
58
  EditorApplication.Exit(1);
59
  }
60
  }
 
71
  {
72
  var simplifier = new MeshSimplifier();
73
  simplifier.Initialize(sourceMesh);
74
+ simplifier.SimplifyMesh(0.05f);
75
  Mesh newMesh = simplifier.ToMesh();
76
  newMesh.name = sourceMesh.name + "_Internal";
 
 
77
  AssetDatabase.AddObjectToAsset(newMesh, exportPath);
78
 
79
  if (ren is MeshRenderer) ren.GetComponent<MeshFilter>().sharedMesh = newMesh;
 
92
  }
93
  }
94
 
95
+ static void BuildAvailablePlatforms()
96
  {
97
+ // Daftar target yang diinginkan sesuai struktur 'sesudah'
98
+ var platforms = new Dictionary<BuildTarget, BuildTargetGroup> {
99
+ { BuildTarget.StandaloneLinux64, BuildTargetGroup.Standalone },
100
+ { BuildTarget.Android, BuildTargetGroup.Android },
101
+ { BuildTarget.iOS, BuildTargetGroup.iOS },
102
+ { BuildTarget.WebGL, BuildTargetGroup.WebGL },
103
+ { BuildTarget.StandaloneWindows64, BuildTargetGroup.Standalone },
104
+ { BuildTarget.StandaloneOSX, BuildTargetGroup.Standalone }
105
  };
106
 
107
+ foreach (var p in platforms)
108
  {
109
+ // CEK: Apakah modul ini tersedia di Unity Anda?
110
+ if (!BuildPipeline.IsBuildTargetSupported(p.Value, p.Key))
111
+ {
112
+ Debug.LogWarning($"⚠️ [SKIP] Platform {p.Key} tidak didukung oleh image Unity ini.");
113
+ continue;
114
+ }
115
+
116
  AssetBundleBuild[] buildMap = new AssetBundleBuild[1];
117
+ buildMap[0].assetBundleName = p.Key.ToString();
118
  buildMap[0].assetNames = AssetDatabase.FindAssets("t:Prefab", new[] { FINAL_EXPORT_DIR })
119
  .Select(guid => AssetDatabase.GUIDToAssetPath(guid)).ToArray();
120
 
121
  BuildPipeline.BuildAssetBundles(BUNDLE_SUBDIR, buildMap,
122
+ BuildAssetBundleOptions.ForceRebuildAssetBundle | BuildAssetBundleOptions.ChunkBasedCompression, p.Key);
123
+
124
+ Debug.Log($"📦 [SUCCESS] Binary untuk {p.Key} berhasil dibuat.");
125
  }
126
  }
127
  }