Spaces:
Sleeping
Sleeping
Update UnityProject/Assets/Editor/TestBuilder.cs
Browse files
UnityProject/Assets/Editor/TestBuilder.cs
CHANGED
|
@@ -15,26 +15,24 @@ public class TestBuilder
|
|
| 15 |
{
|
| 16 |
try
|
| 17 |
{
|
| 18 |
-
Debug.Log("🛠️ [UNITY] Memulai Export
|
| 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);
|
| 23 |
|
| 24 |
string[] prefabPaths = Directory.GetFiles("Assets/InputRaw", "*.prefab", SearchOption.AllDirectories);
|
| 25 |
-
|
|
|
|
| 26 |
foreach (string path in prefabPaths)
|
| 27 |
{
|
| 28 |
string exportPath = Path.Combine(FINAL_EXPORT_DIR, Path.GetFileName(path));
|
| 29 |
GameObject go = PrefabUtility.LoadPrefabContents(path);
|
| 30 |
if (go != null)
|
| 31 |
{
|
| 32 |
-
// Tetap tanam Mesh ke Prefab (Embedding)
|
| 33 |
ProcessAndEmbed(go, exportPath);
|
| 34 |
PrefabUtility.SaveAsPrefabAsset(go, exportPath);
|
| 35 |
PrefabUtility.UnloadPrefabContents(go);
|
| 36 |
-
|
| 37 |
-
// Salin file pendukung (PNG, Shader, Meta)
|
| 38 |
CopyRelatedFiles(Path.GetDirectoryName(path), FINAL_EXPORT_DIR);
|
| 39 |
}
|
| 40 |
}
|
|
@@ -42,10 +40,16 @@ public class TestBuilder
|
|
| 42 |
AssetDatabase.SaveAssets();
|
| 43 |
AssetDatabase.Refresh();
|
| 44 |
|
| 45 |
-
//
|
| 46 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 47 |
|
| 48 |
-
Debug.Log("✅ [UNITY] Build
|
| 49 |
EditorApplication.Exit(0);
|
| 50 |
}
|
| 51 |
catch (Exception e)
|
|
@@ -86,15 +90,28 @@ public class TestBuilder
|
|
| 86 |
}
|
| 87 |
}
|
| 88 |
|
| 89 |
-
static void
|
| 90 |
{
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 95 |
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
}
|
| 100 |
}
|
|
|
|
| 15 |
{
|
| 16 |
try
|
| 17 |
{
|
| 18 |
+
Debug.Log("🛠️ [UNITY] Memulai Export Struktur...");
|
| 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);
|
| 23 |
|
| 24 |
string[] prefabPaths = Directory.GetFiles("Assets/InputRaw", "*.prefab", SearchOption.AllDirectories);
|
| 25 |
+
if (prefabPaths.Length == 0) throw new Exception("Folder Assets/InputRaw kosong!");
|
| 26 |
+
|
| 27 |
foreach (string path in prefabPaths)
|
| 28 |
{
|
| 29 |
string exportPath = Path.Combine(FINAL_EXPORT_DIR, Path.GetFileName(path));
|
| 30 |
GameObject go = PrefabUtility.LoadPrefabContents(path);
|
| 31 |
if (go != null)
|
| 32 |
{
|
|
|
|
| 33 |
ProcessAndEmbed(go, exportPath);
|
| 34 |
PrefabUtility.SaveAsPrefabAsset(go, exportPath);
|
| 35 |
PrefabUtility.UnloadPrefabContents(go);
|
|
|
|
|
|
|
| 36 |
CopyRelatedFiles(Path.GetDirectoryName(path), FINAL_EXPORT_DIR);
|
| 37 |
}
|
| 38 |
}
|
|
|
|
| 40 |
AssetDatabase.SaveAssets();
|
| 41 |
AssetDatabase.Refresh();
|
| 42 |
|
| 43 |
+
// Build platform yang tersedia
|
| 44 |
+
BuildAvailablePlatforms();
|
| 45 |
+
|
| 46 |
+
// --- PEMBERSIHAN MASTER MANIFEST (PENTING) ---
|
| 47 |
+
// Unity otomatis buat file biner bernama sama dengan folder ('assetbundles')
|
| 48 |
+
string masterBundlePath = Path.Combine(BUNDLE_SUBDIR, "assetbundles");
|
| 49 |
+
if (File.Exists(masterBundlePath)) File.Delete(masterBundlePath);
|
| 50 |
+
if (File.Exists(masterBundlePath + ".manifest")) File.Delete(masterBundlePath + ".manifest");
|
| 51 |
|
| 52 |
+
Debug.Log("✅ [UNITY] Build Selesai & Master Manifest dihapus.");
|
| 53 |
EditorApplication.Exit(0);
|
| 54 |
}
|
| 55 |
catch (Exception e)
|
|
|
|
| 90 |
}
|
| 91 |
}
|
| 92 |
|
| 93 |
+
static void BuildAvailablePlatforms()
|
| 94 |
{
|
| 95 |
+
var platforms = new Dictionary<BuildTarget, BuildTargetGroup> {
|
| 96 |
+
{ BuildTarget.StandaloneLinux64, BuildTargetGroup.Standalone },
|
| 97 |
+
{ BuildTarget.Android, BuildTargetGroup.Android },
|
| 98 |
+
{ BuildTarget.iOS, BuildTargetGroup.iOS },
|
| 99 |
+
{ BuildTarget.WebGL, BuildTargetGroup.WebGL },
|
| 100 |
+
{ BuildTarget.StandaloneWindows64, BuildTargetGroup.Standalone },
|
| 101 |
+
{ BuildTarget.StandaloneOSX, BuildTargetGroup.Standalone }
|
| 102 |
+
};
|
| 103 |
+
|
| 104 |
+
foreach (var p in platforms)
|
| 105 |
+
{
|
| 106 |
+
if (!BuildPipeline.IsBuildTargetSupported(p.Value, p.Key)) continue;
|
| 107 |
+
|
| 108 |
+
AssetBundleBuild[] buildMap = new AssetBundleBuild[1];
|
| 109 |
+
buildMap[0].assetBundleName = p.Key.ToString();
|
| 110 |
+
buildMap[0].assetNames = AssetDatabase.FindAssets("t:Prefab", new[] { FINAL_EXPORT_DIR })
|
| 111 |
+
.Select(guid => AssetDatabase.GUIDToAssetPath(guid)).ToArray();
|
| 112 |
|
| 113 |
+
BuildPipeline.BuildAssetBundles(BUNDLE_SUBDIR, buildMap,
|
| 114 |
+
BuildAssetBundleOptions.ForceRebuildAssetBundle | BuildAssetBundleOptions.ChunkBasedCompression, p.Key);
|
| 115 |
+
}
|
| 116 |
}
|
| 117 |
}
|